Changeset 13806 for branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.cs
- Timestamp:
- 04/27/16 17:17:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.cs
r13788 r13806 24 24 using System.Linq; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.MainForm; 27 28 using HeuristicLab.Optimization; … … 32 33 public Experiment Experiment { get; private set; } 33 34 private int repetitions; 34 private int binomialCoefficient;35 private int combinationGroupSize; 35 36 36 37 public CreateTargetVariationExperimentDialog() : this(null) { } … … 38 39 InitializeComponent(); 39 40 repetitions = (int)repetitionsNumericUpDown.Value; 41 combinationGroupSize = (int)combinationGroupSizeNumericUpDown.Value; 42 43 var problem = alg.Problem as IDataAnalysisProblem; 44 var inputCount = problem.ProblemData.AllowedInputVariables.Count(); 45 if (combinationGroupSize > inputCount) 46 combinationGroupSize = inputCount; 47 warningLabel.Text = string.Format("Warning: this will create {0} combinations.", EnumerableExtensions.BinomialCoefficient(inputCount, combinationGroupSize)); 40 48 41 49 Experiment = null; 42 50 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 51 } 56 52 … … 61 57 throw new ArgumentNullException("The algorithm parameter must be a valid IAlgorithm instance."); 62 58 63 var regressionProblem = algorithm.Problem as IRegressionProblem; 64 if (regressionProblem == null) 65 throw new ArgumentNullException("The algorithm does not contain a valid problem instance."); 59 var problem = (IDataAnalysisProblem)algorithm.Problem; 60 var problemData = problem.ProblemData; 66 61 67 var problemData = regressionProblem.ProblemData; 68 var variables = problemData.Dataset.DoubleVariables.ToList(); 62 var variables = problemData.AllowedInputVariables.ToList(); 69 63 70 64 for (int i = 0; i < variables.Count; i++) { 71 65 var target = variables[i]; 72 66 var inputs = variables.Where(x => x != target).ToList(); 73 var combinations = Util.Combinations(inputs, binomialCoefficient); 67 if (combinationGroupSize > inputs.Count) 68 combinationGroupSize = inputs.Count; 69 70 var combinations = inputs.Combinations(combinationGroupSize); 74 71 75 72 foreach (var combination in combinations) { 76 73 var h = new HashSet<string>(combination); 77 74 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)); 75 alg.Name += " {Target = " + target + ", Inputs = (" + combination.Aggregate((a, b) => a + "," + b) + ")}"; 76 problem = (IDataAnalysisProblem)alg.Problem; 77 problemData = problem.ProblemData; 78 foreach (var item in problemData.InputVariables) { 79 problemData.InputVariables.SetItemCheckedState(item, h.Contains(item.Value)); 84 80 } 81 SetTargetName(problemData, target); 85 82 86 83 var batchrun = new BatchRun(string.Format("Batchrun {0}", i + 1)) { … … 95 92 } 96 93 94 private static string GetTargetName(IDataAnalysisProblemData problemData) { 95 var regressionProblemData = problemData as IRegressionProblemData; 96 if (regressionProblemData != null) 97 return regressionProblemData.TargetVariable; 98 var classificationProblemData = problemData as IClassificationProblemData; 99 if (classificationProblemData != null) 100 return classificationProblemData.TargetVariable; 101 throw new ArgumentException("The provided argument must be either a regression or classification problem data."); 102 } 103 104 private static void SetTargetName(IDataAnalysisProblemData problemData, string targetName) { 105 var regressionProblemData = problemData as IRegressionProblemData; 106 if (regressionProblemData != null) { 107 regressionProblemData.TargetVariable = targetName; 108 return; 109 } 110 var classificationProblemData = problemData as IClassificationProblemData; 111 if (classificationProblemData != null) { 112 classificationProblemData.TargetVariable = targetName; 113 return; 114 } 115 throw new ArgumentException("The provided argument must be either a regression or classification problem data."); 116 } 117 118 #region events 97 119 private void okButton_Click(object sender, EventArgs e) { 98 120 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 99 if ((activeView != null) && (activeView.Content != null) && (activeView.Content is I Optimizer) && !activeView.Locked) {121 if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IAlgorithm) && !activeView.Locked) { 100 122 Experiment = CreateVariableCombinations((IAlgorithm)activeView.Content); 101 123 DialogResult = DialogResult.OK; … … 103 125 } 104 126 } 127 128 private void combinationGroupSizeNumericUpDown_Validating(object sender, System.ComponentModel.CancelEventArgs e) { 129 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 130 if (activeView == null) return; 131 var algorithm = (IAlgorithm)activeView.Content; 132 var problem = algorithm.Problem as IDataAnalysisProblem; 133 if (problem == null) return; 134 var inputCount = problem.ProblemData.AllowedInputVariables.Count(); 135 if (combinationGroupSizeNumericUpDown.Value > inputCount) 136 combinationGroupSizeNumericUpDown.Value = inputCount; 137 } 138 139 private void repetitionsNumericUpDown_Validated(object sender, EventArgs e) { 140 if (repetitionsNumericUpDown.Text == string.Empty) 141 repetitionsNumericUpDown.Text = repetitionsNumericUpDown.Value.ToString(); 142 repetitions = (int)repetitionsNumericUpDown.Value; 143 } 144 145 private void combinationGroupSizeNumericUpDown_Validated(object sender, EventArgs e) { 146 if (combinationGroupSizeNumericUpDown.Text == string.Empty) 147 combinationGroupSizeNumericUpDown.Text = combinationGroupSizeNumericUpDown.Value.ToString(); 148 combinationGroupSize = (int)combinationGroupSizeNumericUpDown.Value; 149 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 150 if (activeView == null) return; 151 var algorithm = (IAlgorithm)activeView.Content; 152 var problem = (IDataAnalysisProblem)algorithm.Problem; 153 var inputCount = problem.ProblemData.AllowedInputVariables.Count(); 154 warningLabel.Text = string.Format("Warning: this will create {0} combinations.", EnumerableExtensions.BinomialCoefficient(inputCount, combinationGroupSize)); 155 } 156 #endregion 105 157 } 106 158 }
Note: See TracChangeset
for help on using the changeset viewer.