1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Globalization;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Text;
|
---|
7 | using System.Threading;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.Core;
|
---|
10 | using HeuristicLab.Data;
|
---|
11 | using HeuristicLab.MainForm.WindowsForms;
|
---|
12 | using HeuristicLab.Optimization;
|
---|
13 | using HeuristicLab.Parameters;
|
---|
14 | using HeuristicLab.Problems.Instances;
|
---|
15 | using HeuristicLab.Problems.DataAnalysis;
|
---|
16 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
17 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
18 | using HeuristicLab.Optimizer;
|
---|
19 | using HeuristicLab.MainForm;
|
---|
20 |
|
---|
21 | namespace HeuristicLab.VariableInteractionNetworks
|
---|
22 | {
|
---|
23 | public partial class CreateTargetVariationExperimentDialog : Form
|
---|
24 | {
|
---|
25 | public Experiment Experiment { get; private set; }
|
---|
26 | private int repetitions;
|
---|
27 |
|
---|
28 |
|
---|
29 | public CreateTargetVariationExperimentDialog() : this(null) { }
|
---|
30 | public CreateTargetVariationExperimentDialog(IAlgorithm alg)
|
---|
31 | {
|
---|
32 | InitializeComponent();
|
---|
33 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
34 |
|
---|
35 | Experiment = null;
|
---|
36 | okButton.Enabled = alg != null;
|
---|
37 | }
|
---|
38 |
|
---|
39 | private void repetitionsNumericUpDown_Validated(object sender, EventArgs e)
|
---|
40 | {
|
---|
41 | if (repetitionsNumericUpDown.Text == string.Empty)
|
---|
42 | repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
|
---|
43 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public Experiment CreateVariableCombinations(IAlgorithm algorithm)
|
---|
47 | {
|
---|
48 | var experiment = new Experiment("Target Variation Experiment");
|
---|
49 |
|
---|
50 | if (algorithm == null)
|
---|
51 | throw new InvalidOperationException("Null algorithm!");
|
---|
52 |
|
---|
53 | var problem = algorithm.Problem;
|
---|
54 | var regressionProblem = problem as IRegressionProblem;
|
---|
55 | if (regressionProblem == null)
|
---|
56 | throw new Exception();
|
---|
57 |
|
---|
58 | var problemData = regressionProblem.ProblemData;
|
---|
59 | var variables = problemData.InputVariables.ToList();
|
---|
60 |
|
---|
61 | for (int i = 0; i < variables.Count; i++)
|
---|
62 | {
|
---|
63 | var alg = (IAlgorithm)algorithm.Clone();
|
---|
64 | var pd = ((IRegressionProblem)alg.Problem).ProblemData;
|
---|
65 |
|
---|
66 | // set target to false
|
---|
67 | pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
|
---|
68 |
|
---|
69 | pd.TargetVariable = pd.InputVariables[i].Value;
|
---|
70 | alg.Name += "{Target variable=" + pd.TargetVariable + "}";
|
---|
71 |
|
---|
72 | var batchrun = new BatchRun("Batchrun" + i)
|
---|
73 | {
|
---|
74 | Repetitions = repetitions,
|
---|
75 | Optimizer = alg
|
---|
76 | };
|
---|
77 |
|
---|
78 | experiment.Optimizers.Add(batchrun);
|
---|
79 | }
|
---|
80 | return experiment;
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void okButton_Click(object sender, EventArgs e)
|
---|
84 | {
|
---|
85 | IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
|
---|
86 | if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked)
|
---|
87 | {
|
---|
88 | Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content);
|
---|
89 | DialogResult = System.Windows.Forms.DialogResult.OK;
|
---|
90 | Close();
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 | } |
---|