Changeset 13806 for branches/HeuristicLab.VariableInteractionNetworks
- Timestamp:
- 04/27/16 17:17:00 (9 years ago)
- Location:
- branches/HeuristicLab.VariableInteractionNetworks
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/DirectedGraphChart.cs
r13789 r13806 90 90 get { return graph; } 91 91 set { 92 if (value == null || graph == value ) return;92 if (value == null || graph == value || !value.Vertices.Any()) return; 93 93 graph = value; 94 94 Draw(); -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.cs
r13789 r13806 269 269 } 270 270 271 private static VariableInteractionNetwork ApplyThreshold(VariableInteractionNetwork originalNetwork, double threshold) { 272 var arcs = originalNetwork.Arcs.Where(x => x.Weight >= threshold).ToList(); 273 if (!arcs.Any()) return originalNetwork; 274 var filteredNetwork = new VariableInteractionNetwork(); 275 var cloner = new Cloner(); 276 var vertices = arcs.SelectMany(x => new[] { x.Source, x.Target }).Select(cloner.Clone).Distinct(); // arcs are not cloned 277 filteredNetwork.AddVertices(vertices); 278 filteredNetwork.AddArcs(arcs.Select(x => (IArc)x.Clone(cloner))); 279 280 var unusedJunctions = filteredNetwork.Vertices.Where(x => x.InDegree == 0 && x is JunctionNetworkNode).ToList(); 281 filteredNetwork.RemoveVertices(unusedJunctions); 282 var orphanedNodes = filteredNetwork.Vertices.Where(x => x.Degree == 0).ToList(); 283 filteredNetwork.RemoveVertices(orphanedNodes); 284 return filteredNetwork.Vertices.Any() ? filteredNetwork : originalNetwork; 285 } 286 271 287 private static double CalculateAverageQuality(RunCollection runs) { 272 288 var pd = (IRegressionProblemData)runs.First().Parameters["ProblemData"]; … … 374 390 var tb = (TextBox)sender; 375 391 errorProvider.SetError(tb, string.Empty); 376 var network = ApplyThreshold(variableInteractionNetwork, double.Parse(tb.Text)); 392 double impact; 393 if (!double.TryParse(tb.Text, out impact)) 394 impact = 0.1; 395 var network = ApplyThreshold(variableInteractionNetwork, impact); 377 396 graphChart.Graph = network; 378 }379 380 private static VariableInteractionNetwork ApplyThreshold(VariableInteractionNetwork originalNetwork, double threshold) {381 var arcs = originalNetwork.Arcs.Where(x => x.Weight >= threshold).ToList();382 if (!arcs.Any()) return originalNetwork;383 var filteredNetwork = new VariableInteractionNetwork();384 var cloner = new Cloner();385 var vertices = arcs.SelectMany(x => new[] { x.Source, x.Target }).Select(cloner.Clone).Distinct(); // arcs are not cloned386 filteredNetwork.AddVertices(vertices);387 filteredNetwork.AddArcs(arcs.Select(x => (IArc)x.Clone(cloner)));388 389 var unusedJunctions = filteredNetwork.Vertices.Where(x => x.InDegree == 0 && x is JunctionNetworkNode).ToList();390 filteredNetwork.RemoveVertices(unusedJunctions);391 var orphanedNodes = filteredNetwork.Vertices.Where(x => x.Degree == 0).ToList();392 filteredNetwork.RemoveVertices(orphanedNodes);393 return filteredNetwork;394 397 } 395 398 -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperiment.cs
r13728 r13806 26 26 using HeuristicLab.Optimization; 27 27 using HeuristicLab.Optimizer; 28 using HeuristicLab.Problems.DataAnalysis; 28 29 29 30 namespace HeuristicLab.VariableInteractionNetworks { … … 47 48 protected override void OnActiveViewChanged(object sender, EventArgs e) { 48 49 IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView; 49 ToolStripItem.Enabled = (activeView != null) && (activeView.Content != null) && (activeView.Content is IOptimizer) && !activeView.Locked; 50 bool enabled = false; 51 if (activeView != null && !activeView.Locked && activeView.Content != null) { 52 var algorithm = activeView.Content as IAlgorithm; 53 if (algorithm != null) { 54 var problem = algorithm.Problem; 55 // make sure the problem data specifies a target variable 56 enabled = problem is IRegressionProblem || problem is IClassificationProblem; 57 } 58 } 59 ToolStripItem.Enabled = enabled; 50 60 } 51 61 -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/CreateTargetVariationExperimentDialog.Designer.cs
r13788 r13806 33 33 this.cancelButton = new System.Windows.Forms.Button(); 34 34 this.okButton = new System.Windows.Forms.Button(); 35 this. binomialCoeffNumericUpDown = new System.Windows.Forms.NumericUpDown();35 this.combinationGroupSizeNumericUpDown = new System.Windows.Forms.NumericUpDown(); 36 36 this.label1 = new System.Windows.Forms.Label(); 37 this. label2= new System.Windows.Forms.Label();37 this.warningLabel = new System.Windows.Forms.Label(); 38 38 ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).BeginInit(); 39 ((System.ComponentModel.ISupportInitialize)(this. binomialCoeffNumericUpDown)).BeginInit();39 ((System.ComponentModel.ISupportInitialize)(this.combinationGroupSizeNumericUpDown)).BeginInit(); 40 40 this.SuspendLayout(); 41 41 // … … 98 98 this.okButton.Click += new System.EventHandler(this.okButton_Click); 99 99 // 100 // binomialCoeffNumericUpDown100 // combinationGroupSizeNumericUpDown 101 101 // 102 this. binomialCoeffNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)102 this.combinationGroupSizeNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 103 103 | System.Windows.Forms.AnchorStyles.Right))); 104 this. binomialCoeffNumericUpDown.Location = new System.Drawing.Point(128, 38);105 this. binomialCoeffNumericUpDown.Maximum = new decimal(new int[] {104 this.combinationGroupSizeNumericUpDown.Location = new System.Drawing.Point(128, 38); 105 this.combinationGroupSizeNumericUpDown.Maximum = new decimal(new int[] { 106 106 1000000, 107 107 0, 108 108 0, 109 109 0}); 110 this. binomialCoeffNumericUpDown.Minimum = new decimal(new int[] {110 this.combinationGroupSizeNumericUpDown.Minimum = new decimal(new int[] { 111 111 1, 112 112 0, 113 113 0, 114 114 0}); 115 this. binomialCoeffNumericUpDown.Name = "binomialCoeffNumericUpDown";116 this. binomialCoeffNumericUpDown.Size = new System.Drawing.Size(185, 20);117 this. binomialCoeffNumericUpDown.TabIndex = 4;118 this. binomialCoeffNumericUpDown.ThousandsSeparator = true;119 this. binomialCoeffNumericUpDown.Value = new decimal(new int[] {115 this.combinationGroupSizeNumericUpDown.Name = "combinationGroupSizeNumericUpDown"; 116 this.combinationGroupSizeNumericUpDown.Size = new System.Drawing.Size(185, 20); 117 this.combinationGroupSizeNumericUpDown.TabIndex = 4; 118 this.combinationGroupSizeNumericUpDown.ThousandsSeparator = true; 119 this.combinationGroupSizeNumericUpDown.Value = new decimal(new int[] { 120 120 10, 121 121 0, 122 122 0, 123 123 0}); 124 this.binomialCoeffNumericUpDown.Validated += new System.EventHandler(this.binomialCoefficientNumericUpDown_Validated); 124 this.combinationGroupSizeNumericUpDown.ValueChanged += new System.EventHandler(this.combinationGroupSizeNumericUpDown_Validated); 125 this.combinationGroupSizeNumericUpDown.Validating += new System.ComponentModel.CancelEventHandler(this.combinationGroupSizeNumericUpDown_Validating); 126 this.combinationGroupSizeNumericUpDown.Validated += new System.EventHandler(this.combinationGroupSizeNumericUpDown_Validated); 125 127 // 126 128 // label1 … … 129 131 this.label1.Location = new System.Drawing.Point(26, 40); 130 132 this.label1.Name = "label1"; 131 this.label1.Size = new System.Drawing.Size( 79, 13);133 this.label1.Size = new System.Drawing.Size(60, 13); 132 134 this.label1.TabIndex = 5; 133 this.label1.Text = "& Binomial coeff.:";135 this.label1.Text = "&Group size:"; 134 136 // 135 // label2137 // warningLabel 136 138 // 137 this.label2.ForeColor = System.Drawing.Color.Red; 138 this.label2.Location = new System.Drawing.Point(26, 67); 139 this.label2.Name = "label2"; 140 this.label2.Size = new System.Drawing.Size(287, 50); 141 this.label2.TabIndex = 5; 142 this.label2.Text = "Warning: depending on the binomial coefficient and the number of variables, this " + 143 "can create very large experiments. "; 139 this.warningLabel.ForeColor = System.Drawing.Color.Red; 140 this.warningLabel.Location = new System.Drawing.Point(26, 67); 141 this.warningLabel.Name = "warningLabel"; 142 this.warningLabel.Size = new System.Drawing.Size(287, 50); 143 this.warningLabel.TabIndex = 5; 144 this.warningLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter; 144 145 // 145 146 // CreateTargetVariationExperimentDialog … … 152 153 this.Controls.Add(this.okButton); 153 154 this.Controls.Add(this.cancelButton); 154 this.Controls.Add(this. label2);155 this.Controls.Add(this.warningLabel); 155 156 this.Controls.Add(this.label1); 156 157 this.Controls.Add(this.repetitionsLabel); 157 this.Controls.Add(this. binomialCoeffNumericUpDown);158 this.Controls.Add(this.combinationGroupSizeNumericUpDown); 158 159 this.Controls.Add(this.repetitionsNumericUpDown); 159 160 this.Name = "CreateTargetVariationExperimentDialog"; 160 161 this.Text = "Create Target Variation Experiment"; 161 162 ((System.ComponentModel.ISupportInitialize)(this.repetitionsNumericUpDown)).EndInit(); 162 ((System.ComponentModel.ISupportInitialize)(this. binomialCoeffNumericUpDown)).EndInit();163 ((System.ComponentModel.ISupportInitialize)(this.combinationGroupSizeNumericUpDown)).EndInit(); 163 164 this.ResumeLayout(false); 164 165 this.PerformLayout(); … … 172 173 private System.Windows.Forms.Button cancelButton; 173 174 private System.Windows.Forms.Button okButton; 174 private System.Windows.Forms.NumericUpDown binomialCoeffNumericUpDown;175 private System.Windows.Forms.NumericUpDown combinationGroupSizeNumericUpDown; 175 176 private System.Windows.Forms.Label label1; 176 private System.Windows.Forms.Label label2;177 private System.Windows.Forms.Label warningLabel; 177 178 } 178 179 } -
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 } -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/HeuristicLab.VariableInteractionNetworks-3.3.csproj
r13789 r13806 166 166 <Compile Include="Properties\AssemblyInfo.cs" /> 167 167 <Compile Include="SymbolicDataAnalysisVariableImpactsAnalyzer.cs" /> 168 <Compile Include="TinySet.cs" />169 168 <Compile Include="VariableInteractionNetwork.cs" /> 170 169 </ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.