1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Windows.Forms;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Problems.DataAnalysis;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.VariableInteractionNetworks {
|
---|
31 | public partial class CreateTargetVariationExperimentDialog : Form {
|
---|
32 | public Experiment Experiment { get; private set; }
|
---|
33 | private int repetitions;
|
---|
34 | private int binomialCoefficient;
|
---|
35 |
|
---|
36 | public CreateTargetVariationExperimentDialog() : this(null) { }
|
---|
37 | public CreateTargetVariationExperimentDialog(IAlgorithm alg) {
|
---|
38 | InitializeComponent();
|
---|
39 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
40 |
|
---|
41 | Experiment = null;
|
---|
42 | okButton.Enabled = alg != null;
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
|
---|
46 | if (repetitionsNumericUpDown.Text == string.Empty)
|
---|
47 | repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
|
---|
48 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
49 | }
|
---|
50 |
|
---|
51 | private void binomialCoefficientNumericUpDown_Validated(object sender, EventArgs e) {
|
---|
52 | if (binomialCoeffNumericUpDown.Text == string.Empty)
|
---|
53 | binomialCoeffNumericUpDown.Text = binomialCoeffNumericUpDown.Value.ToString();
|
---|
54 | binomialCoefficient = (int)binomialCoeffNumericUpDown.Value;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public Experiment CreateVariableCombinations(IAlgorithm algorithm) {
|
---|
58 | var experiment = new Experiment("Target Variation Experiment");
|
---|
59 |
|
---|
60 | if (algorithm == null)
|
---|
61 | throw new ArgumentNullException("The algorithm parameter must be a valid IAlgorithm instance.");
|
---|
62 |
|
---|
63 | var regressionProblem = algorithm.Problem as IRegressionProblem;
|
---|
64 | if (regressionProblem == null)
|
---|
65 | throw new ArgumentNullException("The algorithm does not contain a valid problem instance.");
|
---|
66 |
|
---|
67 | var problemData = regressionProblem.ProblemData;
|
---|
68 | var variables = problemData.Dataset.DoubleVariables.ToList();
|
---|
69 |
|
---|
70 | for (int i = 0; i < variables.Count; i++) {
|
---|
71 | var target = variables[i];
|
---|
72 | var inputs = variables.Where(x => x != target).ToList();
|
---|
73 | var combinations = Util.Combinations(inputs, binomialCoefficient);
|
---|
74 |
|
---|
75 | foreach (var combination in combinations) {
|
---|
76 | var h = new HashSet<string>(combination);
|
---|
77 | var alg = (IAlgorithm)algorithm.Clone();
|
---|
78 | var pd = ((IRegressionProblem)alg.Problem).ProblemData;
|
---|
79 | pd.TargetVariable = target;
|
---|
80 | alg.Name += "{Target = " + target + ", Inputs = (" + combination.Aggregate((a, b) => a + "," + b) + ")}";
|
---|
81 |
|
---|
82 | foreach (var item in pd.InputVariables) {
|
---|
83 | pd.InputVariables.SetItemCheckedState(item, h.Contains(item.Value));
|
---|
84 | }
|
---|
85 |
|
---|
86 | var batchrun = new BatchRun(string.Format("Batchrun {0}", i + 1)) {
|
---|
87 | Repetitions = repetitions,
|
---|
88 | Optimizer = alg
|
---|
89 | };
|
---|
90 |
|
---|
91 | experiment.Optimizers.Add(batchrun);
|
---|
92 | }
|
---|
93 | }
|
---|
94 | return experiment;
|
---|
95 | }
|
---|
96 |
|
---|
97 | private void okButton_Click(object sender, EventArgs e) {
|
---|
98 | IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
|
---|
99 | if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) {
|
---|
100 | Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content);
|
---|
101 | DialogResult = DialogResult.OK;
|
---|
102 | Close();
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 | }
|
---|