[13664] | 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;
|
---|
[12320] | 23 | using System.Linq;
|
---|
| 24 | using System.Windows.Forms;
|
---|
[13664] | 25 | using HeuristicLab.MainForm;
|
---|
[12320] | 26 | using HeuristicLab.Optimization;
|
---|
| 27 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 28 |
|
---|
[13664] | 29 | namespace HeuristicLab.VariableInteractionNetworks {
|
---|
| 30 | public partial class CreateTargetVariationExperimentDialog : Form {
|
---|
| 31 | public Experiment Experiment { get; private set; }
|
---|
| 32 | private int repetitions;
|
---|
[12320] | 33 |
|
---|
[13664] | 34 | public CreateTargetVariationExperimentDialog() : this(null) { }
|
---|
| 35 | public CreateTargetVariationExperimentDialog(IAlgorithm alg) {
|
---|
| 36 | InitializeComponent();
|
---|
| 37 | repetitions = (int)repetitionsNumericUpDown.Value;
|
---|
[12320] | 38 |
|
---|
[13664] | 39 | Experiment = null;
|
---|
| 40 | okButton.Enabled = alg != null;
|
---|
| 41 | }
|
---|
[12320] | 42 |
|
---|
[13664] | 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 | }
|
---|
[12320] | 48 |
|
---|
[13664] | 49 | public Experiment CreateVariableCombinations(IAlgorithm algorithm) {
|
---|
| 50 | var experiment = new Experiment("Target Variation Experiment");
|
---|
[12320] | 51 |
|
---|
[13664] | 52 | if (algorithm == null)
|
---|
| 53 | throw new ArgumentNullException("The algorithm parameter must be a valid IAlgorithm instance.");
|
---|
[12320] | 54 |
|
---|
[13664] | 55 | var regressionProblem = algorithm.Problem as IRegressionProblem;
|
---|
| 56 | if (regressionProblem == null)
|
---|
| 57 | throw new ArgumentNullException("The algorithm does not contain a valid problem instance.");
|
---|
[12320] | 58 |
|
---|
[13664] | 59 | var problemData = regressionProblem.ProblemData;
|
---|
| 60 | var variables = problemData.Dataset.DoubleVariables.ToList();
|
---|
[12321] | 61 |
|
---|
[13664] | 62 | for (int i = 0; i < variables.Count; i++) {
|
---|
| 63 | var alg = (IAlgorithm)algorithm.Clone();
|
---|
| 64 | var pd = ((IRegressionProblem)alg.Problem).ProblemData;
|
---|
[12320] | 65 |
|
---|
[13664] | 66 | for (int j = 0; j < variables.Count; ++j)
|
---|
| 67 | pd.InputVariables.SetItemCheckedState(pd.InputVariables[j], true);
|
---|
[12320] | 68 |
|
---|
[13664] | 69 | pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false);
|
---|
| 70 | pd.TargetVariable = pd.InputVariables[i].Value;
|
---|
[12320] | 71 |
|
---|
[13664] | 72 | alg.Name += "{Target = " + pd.TargetVariable + "}";
|
---|
[12320] | 73 |
|
---|
[13664] | 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;
|
---|
[12320] | 82 | }
|
---|
[13664] | 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 | }
|
---|