Changeset 13664
- Timestamp:
- 03/08/16 11:24:33 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.cs
r12321 r13664 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Globalization; 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; 5 23 using System.Linq; 6 using System.Text;7 using System.Threading;8 24 using System.Windows.Forms; 9 using HeuristicLab.Core; 10 using HeuristicLab.Data; 11 using HeuristicLab.MainForm.WindowsForms; 25 using HeuristicLab.MainForm; 12 26 using HeuristicLab.Optimization; 13 using HeuristicLab.Parameters;14 using HeuristicLab.Problems.Instances;15 27 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 28 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; 29 namespace HeuristicLab.VariableInteractionNetworks { 30 public partial class CreateTargetVariationExperimentDialog : Form { 31 public Experiment Experiment { get; private set; } 32 private int repetitions; 33 33 34 Experiment = null; 35 okButton.Enabled = alg != null; 36 } 34 public CreateTargetVariationExperimentDialog() : this(null) { } 35 public CreateTargetVariationExperimentDialog(IAlgorithm alg) { 36 InitializeComponent(); 37 repetitions = (int)repetitionsNumericUpDown.Value; 37 38 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 } 39 Experiment = null; 40 okButton.Enabled = alg != null; 41 } 44 42 45 public Experiment CreateVariableCombinations(IAlgorithm algorithm) 46 { 47 var experiment = new Experiment("Target Variation Experiment"); 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 48 49 if (algorithm == null)50 throw new InvalidOperationException("Null algorithm!");49 public Experiment CreateVariableCombinations(IAlgorithm algorithm) { 50 var experiment = new Experiment("Target Variation Experiment"); 51 51 52 var regressionProblem = algorithm.Problem as IRegressionProblem; 53 if (regressionProblem == null) 54 throw new InvalidOperationException("Null regression problem!!"); 52 if (algorithm == null) 53 throw new ArgumentNullException("The algorithm parameter must be a valid IAlgorithm instance."); 55 54 56 var problemData = regressionProblem.ProblemData;57 var variables = problemData.InputVariables.ToList();58 int checksNo = 0;55 var regressionProblem = algorithm.Problem as IRegressionProblem; 56 if (regressionProblem == null) 57 throw new ArgumentNullException("The algorithm does not contain a valid problem instance."); 59 58 60 for (int i = 0; i < variables.Count; i++) 61 { 62 if (!problemData.InputVariables.ItemChecked(problemData.InputVariables[i])) 63 continue; 59 var problemData = regressionProblem.ProblemData; 60 var variables = problemData.Dataset.DoubleVariables.ToList(); 64 61 65 var alg = (IAlgorithm)algorithm.Clone();66 var pd = ((IRegressionProblem)alg.Problem).ProblemData;67 checksNo++;62 for (int i = 0; i < variables.Count; i++) { 63 var alg = (IAlgorithm)algorithm.Clone(); 64 var pd = ((IRegressionProblem)alg.Problem).ProblemData; 68 65 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 + "}"; 66 for (int j = 0; j < variables.Count; ++j) 67 pd.InputVariables.SetItemCheckedState(pd.InputVariables[j], true); 75 68 76 var batchrun = new BatchRun("Batchrun" + checksNo) 77 { 78 Repetitions = repetitions, 79 Optimizer = alg 80 }; 69 pd.InputVariables.SetItemCheckedState(pd.InputVariables[i], false); 70 pd.TargetVariable = pd.InputVariables[i].Value; 81 71 82 experiment.Optimizers.Add(batchrun); 83 } 84 return experiment; 85 } 72 alg.Name += "{Target = " + pd.TargetVariable + "}"; 86 73 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 } 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; 97 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 } 98 93 }
Note: See TracChangeset
for help on using the changeset viewer.