Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.cs @ 13728

Last change on this file since 13728 was 13664, checked in by bburlacu, 8 years ago

#2288: Change the CreateTargetVariationExperimentDialog so that it creates combinations of all variables in the dataset.

File size: 3.6 KB
Line 
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
22using System;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.Optimization;
27using HeuristicLab.Problems.DataAnalysis;
28
29namespace HeuristicLab.VariableInteractionNetworks {
30  public partial class CreateTargetVariationExperimentDialog : Form {
31    public Experiment Experiment { get; private set; }
32    private int repetitions;
33
34    public CreateTargetVariationExperimentDialog() : this(null) { }
35    public CreateTargetVariationExperimentDialog(IAlgorithm alg) {
36      InitializeComponent();
37      repetitions = (int)repetitionsNumericUpDown.Value;
38
39      Experiment = null;
40      okButton.Enabled = alg != null;
41    }
42
43    private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) {
44      if (repetitionsNumericUpDown.Text == string.Empty)
45        repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString();
46      repetitions = (int)repetitionsNumericUpDown.Value;
47    }
48
49    public Experiment CreateVariableCombinations(IAlgorithm algorithm) {
50      var experiment = new Experiment("Target Variation Experiment");
51
52      if (algorithm == null)
53        throw new ArgumentNullException("The algorithm parameter must be a valid IAlgorithm instance.");
54
55      var regressionProblem = algorithm.Problem as IRegressionProblem;
56      if (regressionProblem == null)
57        throw new ArgumentNullException("The algorithm does not contain a valid problem instance.");
58
59      var problemData = regressionProblem.ProblemData;
60      var variables = problemData.Dataset.DoubleVariables.ToList();
61
62      for (int i = 0; i < variables.Count; i++) {
63        var alg = (IAlgorithm)algorithm.Clone();
64        var pd = ((IRegressionProblem)alg.Problem).ProblemData;
65
66        for (int j = 0; j < variables.Count; ++j)
67          pd.InputVariables.SetItemCheckedState(pd.InputVariables[j], true);
68
69        pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
70        pd.TargetVariable = pd.InputVariables[i].Value;
71
72        alg.Name += "{Target = " + pd.TargetVariable + "}";
73
74        var batchrun = new BatchRun(string.Format("Batchrun {0}", i + 1)) {
75          Repetitions = repetitions,
76          Optimizer = alg
77        };
78
79        experiment.Optimizers.Add(batchrun);
80      }
81      return experiment;
82    }
83
84    private void okButton_Click(object sender, EventArgs e) {
85      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
86      if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked) {
87        Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content);
88        DialogResult = DialogResult.OK;
89        Close();
90      }
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.