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 | public CreateTargetVariationExperimentDialog() : this(null) { }
|
---|
29 | public CreateTargetVariationExperimentDialog(IAlgorithm alg)
|
---|
30 | {
|
---|
31 | InitializeComponent();
|
---|
32 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
33 |
|
---|
34 | Experiment = null;
|
---|
35 | okButton.Enabled = alg != null;
|
---|
36 | }
|
---|
37 |
|
---|
38 | private void repetitionsNumericUpDown_Validated(object sender, EventArgs e)
|
---|
39 | {
|
---|
40 | if (repetitionsNumericUpDown.Text == string.Empty)
|
---|
41 | repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
|
---|
42 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public Experiment CreateVariableCombinations(IAlgorithm algorithm)
|
---|
46 | {
|
---|
47 | var experiment = new Experiment("Target Variation Experiment");
|
---|
48 |
|
---|
49 | if (algorithm == null)
|
---|
50 | throw new InvalidOperationException("Null algorithm!");
|
---|
51 |
|
---|
52 | var regressionProblem = algorithm.Problem as IRegressionProblem;
|
---|
53 | if (regressionProblem == null)
|
---|
54 | throw new InvalidOperationException("Null regression problem!!");
|
---|
55 |
|
---|
56 | var problemData = regressionProblem.ProblemData;
|
---|
57 | var variables = problemData.InputVariables.ToList();
|
---|
58 | int checksNo = 0;
|
---|
59 |
|
---|
60 | for (int i = 0; i < variables.Count; i++)
|
---|
61 | {
|
---|
62 | if (!problemData.InputVariables.ItemChecked(problemData.InputVariables[i]))
|
---|
63 | continue;
|
---|
64 |
|
---|
65 | var alg = (IAlgorithm)algorithm.Clone();
|
---|
66 | var pd = ((IRegressionProblem)alg.Problem).ProblemData;
|
---|
67 | checksNo++;
|
---|
68 |
|
---|
69 | // set target to false
|
---|
70 | pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
|
---|
71 |
|
---|
72 | pd.TargetVariable = pd.InputVariables[i].Value;
|
---|
73 |
|
---|
74 | alg.Name += "{Target variable=" + pd.TargetVariable + "}";
|
---|
75 |
|
---|
76 | var batchrun = new BatchRun("Batchrun" + checksNo)
|
---|
77 | {
|
---|
78 | Repetitions = repetitions,
|
---|
79 | Optimizer = alg
|
---|
80 | };
|
---|
81 |
|
---|
82 | experiment.Optimizers.Add(batchrun);
|
---|
83 | }
|
---|
84 | return experiment;
|
---|
85 | }
|
---|
86 |
|
---|
87 | private void okButton_Click(object sender, EventArgs e)
|
---|
88 | {
|
---|
89 | IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
|
---|
90 | if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked)
|
---|
91 | {
|
---|
92 | Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content);
|
---|
93 | DialogResult = System.Windows.Forms.DialogResult.OK;
|
---|
94 | Close();
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | } |
---|