Changeset 16295
- Timestamp:
- 11/13/18 15:22:18 (6 years ago)
- Location:
- branches/2288_HeuristicLab.VariableInteractionNetworks
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.Designer.cs
r14275 r16295 26 26 this.components = new System.ComponentModel.Container(); 27 27 this.settingsGroupBox = new System.Windows.Forms.GroupBox(); 28 this.impactThresholdLabel = new System.Windows.Forms.Label(); 28 29 this.impactThresholdTrackBar = new System.Windows.Forms.TrackBar(); 29 30 this.exportImpactsMatrixButton = new System.Windows.Forms.Button(); … … 38 39 this.label1 = new System.Windows.Forms.Label(); 39 40 this.layoutOptionsGroupBox = new System.Windows.Forms.GroupBox(); 41 this.relayoutGraphButton = new System.Windows.Forms.Button(); 40 42 this.idealEdgeLengthTextBox = new System.Windows.Forms.TextBox(); 41 43 this.edgeRoutingComboBox = new System.Windows.Forms.ComboBox(); … … 43 45 this.label3 = new System.Windows.Forms.Label(); 44 46 this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); 45 this.impactThresholdLabel = new System.Windows.Forms.Label();46 this.relayoutGraphButton = new System.Windows.Forms.Button();47 47 this.graphChart = new HeuristicLab.VariableInteractionNetworks.Views.DirectedGraphChart(); 48 48 this.settingsGroupBox.SuspendLayout(); … … 54 54 // settingsGroupBox 55 55 // 56 this.settingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 56 this.settingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 57 57 | System.Windows.Forms.AnchorStyles.Left))); 58 58 this.settingsGroupBox.Controls.Add(this.impactThresholdLabel); … … 75 75 this.settingsGroupBox.Text = "Network Configuration"; 76 76 // 77 // impactThresholdLabel 78 // 79 this.impactThresholdLabel.Location = new System.Drawing.Point(118, 92); 80 this.impactThresholdLabel.Name = "impactThresholdLabel"; 81 this.impactThresholdLabel.Size = new System.Drawing.Size(204, 23); 82 this.impactThresholdLabel.TabIndex = 8; 83 this.impactThresholdLabel.Text = "0"; 84 this.impactThresholdLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 85 // 77 86 // impactThresholdTrackBar 78 87 // … … 186 195 // layoutOptionsGroupBox 187 196 // 188 this.layoutOptionsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 189 | System.Windows.Forms.AnchorStyles.Left))); 197 this.layoutOptionsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 190 198 this.layoutOptionsGroupBox.Controls.Add(this.relayoutGraphButton); 191 199 this.layoutOptionsGroupBox.Controls.Add(this.idealEdgeLengthTextBox); … … 193 201 this.layoutOptionsGroupBox.Controls.Add(this.label4); 194 202 this.layoutOptionsGroupBox.Controls.Add(this.label3); 195 this.layoutOptionsGroupBox.Location = new System.Drawing.Point(4, 245);203 this.layoutOptionsGroupBox.Location = new System.Drawing.Point(4, 360); 196 204 this.layoutOptionsGroupBox.Name = "layoutOptionsGroupBox"; 197 this.layoutOptionsGroupBox.Size = new System.Drawing.Size(331, 217);205 this.layoutOptionsGroupBox.Size = new System.Drawing.Size(331, 102); 198 206 this.layoutOptionsGroupBox.TabIndex = 2; 199 207 this.layoutOptionsGroupBox.TabStop = false; 200 208 this.layoutOptionsGroupBox.Text = "Layout Options"; 209 // 210 // relayoutGraphButton 211 // 212 this.relayoutGraphButton.Location = new System.Drawing.Point(10, 69); 213 this.relayoutGraphButton.Name = "relayoutGraphButton"; 214 this.relayoutGraphButton.Size = new System.Drawing.Size(149, 23); 215 this.relayoutGraphButton.TabIndex = 4; 216 this.relayoutGraphButton.Text = "Recalculate Layout"; 217 this.relayoutGraphButton.UseVisualStyleBackColor = true; 218 this.relayoutGraphButton.Click += new System.EventHandler(this.relayoutGraphButton_Click); 201 219 // 202 220 // idealEdgeLengthTextBox … … 246 264 this.errorProvider.ContainerControl = this; 247 265 // 248 // impactThresholdLabel249 //250 this.impactThresholdLabel.Location = new System.Drawing.Point(118, 92);251 this.impactThresholdLabel.Name = "impactThresholdLabel";252 this.impactThresholdLabel.Size = new System.Drawing.Size(204, 23);253 this.impactThresholdLabel.TabIndex = 8;254 this.impactThresholdLabel.Text = "0";255 this.impactThresholdLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;256 //257 // relayoutGraphButton258 //259 this.relayoutGraphButton.Location = new System.Drawing.Point(10, 69);260 this.relayoutGraphButton.Name = "relayoutGraphButton";261 this.relayoutGraphButton.Size = new System.Drawing.Size(149, 23);262 this.relayoutGraphButton.TabIndex = 4;263 this.relayoutGraphButton.Text = "Recalculate Layout";264 this.relayoutGraphButton.UseVisualStyleBackColor = true;265 this.relayoutGraphButton.Click += new System.EventHandler(this.relayoutGraphButton_Click);266 //267 266 // graphChart 268 267 // 269 this.graphChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 270 | System.Windows.Forms.AnchorStyles.Left) 268 this.graphChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 269 | System.Windows.Forms.AnchorStyles.Left) 271 270 | System.Windows.Forms.AnchorStyles.Right))); 272 271 this.graphChart.BackColor = System.Drawing.SystemColors.Control; 272 this.graphChart.DefaultEdgeLength = 50D; 273 273 this.graphChart.Graph = null; 274 this.graphChart.DefaultEdgeLength = 50D;275 274 this.graphChart.Location = new System.Drawing.Point(341, 4); 276 275 this.graphChart.Mode = null; -
branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.cs
r15421 r16295 111 111 var targetImpacts = new Dictionary<string, Tuple<IEnumerable<IRun>, Dictionary<string, double>>>(); 112 112 113 var groups = runs.GroupBy(run => { 114 var sol = (IRegressionSolution)run.Results.Values.Single(x => x is IRegressionSolution); 115 return Concatenate(sol.ProblemData.AllowedInputVariables) + sol.ProblemData.TargetVariable; 116 }); 117 113 118 if (useBest) { 114 119 // build network using only the best run for each target 120 foreach (var group in groups) { 121 var solutions = group.Select(run => Tuple.Create(run, (IRegressionSolution)run.Results.Values.Single(sol => sol is IRegressionSolution))); 122 var best = solutions.OrderBy(x => x.Item2.TrainingRSquared).Last(); 123 var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(best.Item2, RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.All, RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum.Shuffle).ToDictionary(x => x.Item1, x => x.Item2); 124 125 targetImpacts[best.Item2.ProblemData.TargetVariable] = Tuple.Create(new[] { best.Item1 }.AsEnumerable(), impacts); 126 } 115 127 } else { 116 var groups = runs.GroupBy(run => {117 var sol = (IRegressionSolution)run.Results.Values.Single(x => x is IRegressionSolution);118 return Concatenate(sol.ProblemData.AllowedInputVariables) + sol.ProblemData.TargetVariable;119 });120 121 128 foreach (var group in groups) { 122 129 // calculate average impacts … … 131 138 } 132 139 var md = dataset.ToModifiable(); 133 var impacts = CalculateImpacts(sol, md, originalValues, medians, estimationLimits); 134 foreach (var pair in impacts) { 135 if (averageImpacts.ContainsKey(pair.Key)) 136 averageImpacts[pair.Key] += pair.Value; 140 141 var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(sol, RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.All, RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum.Shuffle); 142 foreach (var t in impacts) { 143 if (averageImpacts.ContainsKey(t.Item1)) 144 averageImpacts[t.Item1] += t.Item2; 137 145 else { 138 averageImpacts[ pair.Key] = pair.Value;146 averageImpacts[t.Item1] = t.Item2; 139 147 } 140 148 } 141 149 } 150 142 151 var count = group.Count(); 143 var keys = averageImpacts.Keys.ToList(); 144 foreach (var v in keys) { 152 foreach (var v in averageImpacts.Keys) { 145 153 averageImpacts[v] /= count; 146 154 } 147 155 148 targetImpacts[solution.ProblemData.TargetVariable] = new Tuple<IEnumerable<IRun>, Dictionary<string, double>>(group, averageImpacts);156 targetImpacts[solution.ProblemData.TargetVariable] = Tuple.Create(group.AsEnumerable(), averageImpacts); 149 157 } 150 158 } 151 159 return targetImpacts; 152 }153 154 private static Dictionary<string, double> CalculateImpacts(IRegressionSolution solution, ModifiableDataset dataset,155 Dictionary<string, List<double>> originalValues, Dictionary<string, List<double>> medianValues, DoubleLimit estimationLimits = null) {156 var impacts = new Dictionary<string, double>();157 158 var model = solution.Model;159 var pd = solution.ProblemData;160 161 var rows = pd.TrainingIndices.ToList();162 var targetValues = pd.Dataset.GetDoubleValues(pd.TargetVariable, rows).ToList();163 164 165 foreach (var v in pd.AllowedInputVariables) {166 dataset.ReplaceVariable(v, medianValues[v]);167 168 var estimatedValues = model.GetEstimatedValues(dataset, rows);169 if (estimationLimits != null)170 estimatedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper);171 172 OnlineCalculatorError error;173 var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out error);174 var newQuality = error == OnlineCalculatorError.None ? r * r : double.NaN;175 var originalQuality = solution.TrainingRSquared;176 impacts[v] = originalQuality - newQuality;177 178 dataset.ReplaceVariable(v, originalValues[v]);179 }180 return impacts;181 160 } 182 161 183 162 public static Dictionary<string, Tuple<IEnumerable<IRun>, Dictionary<string, double>>> CalculateVariableImpactsFromRunResults(RunCollection runs, 184 163 string qualityResultName, bool maximization, string impactsResultName, bool useBestRunsPerTarget = false) { 185 var targets = runs.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList(); 164 165 Func<IRun, double> getQuality = run => ((DoubleValue)run.Results[qualityResultName]).Value; 166 var targetGroups = runs.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList(); 186 167 var targetImpacts = new Dictionary<string, Tuple<IEnumerable<IRun>, Dictionary<string, double>>>(); 187 168 188 Func<IRun, double> getQualityValue = run => ((DoubleValue)run.Results[qualityResultName]).Value;189 190 169 if (useBestRunsPerTarget) { 191 var bestRunsPerTarget = maximization 192 ? targets.Select(x => x.OrderBy(getQualityValue).Last()) 193 : targets.Select(x => x.OrderBy(getQualityValue).First()); 194 195 foreach (var run in bestRunsPerTarget) { 196 var pd = (IRegressionProblemData)run.Parameters["ProblemData"]; 197 var target = pd.TargetVariable; 198 var impacts = (DoubleMatrix)run.Results[impactsResultName]; 199 targetImpacts[target] = new Tuple<IEnumerable<IRun>, Dictionary<string, double>>(new[] { run }, impacts.RowNames.Select((x, i) => new { Name = x, Index = i }).ToDictionary(x => x.Name, x => impacts[x.Index, 0])); 170 foreach (var group in targetGroups) { 171 var ordered = group.OrderBy(getQuality); 172 var best = maximization ? ordered.Last() : ordered.First(); 173 var pd = (IRegressionProblemData)best.Parameters["ProblemData"]; 174 var target = group.Key; 175 var impacts = (DoubleMatrix)best.Results[impactsResultName]; 176 targetImpacts[target] = Tuple.Create((IEnumerable<IRun>)new[] { best }, impacts.RowNames.Select((x, i) => new { x, i }).ToDictionary(x => x.x, x => impacts[x.i, 0])); 200 177 } 201 178 } else { 202 foreach (var target in target s) {179 foreach (var target in targetGroups) { 203 180 var averageImpacts = CalculateAverageImpacts(new RunCollection(target), impactsResultName); 204 181 targetImpacts[target.Key] = new Tuple<IEnumerable<IRun>, Dictionary<string, double>>(target, averageImpacts); … … 460 437 worker.DoWork += (o, e) => { 461 438 ControlsEnable(false); 462 var impacts = CalculateVariableImpactsOnline(Content, false);439 var impacts = CalculateVariableImpactsOnline(Content, impactAggregationComboBox.SelectedIndex == 0); 463 440 variableInteractionNetwork = CreateNetwork(impacts); 464 441 var threshold = impactThresholdTrackBar.Minimum + (double)impactThresholdTrackBar.Value / impactThresholdTrackBar.Maximum; -
branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/HeuristicLab.VariableInteractionNetworks-3.3.csproj
r15929 r16295 111 111 <SpecificVersion>False</SpecificVersion> 112 112 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath> 113 <Private>False</Private>114 </Reference>115 <Reference Include="HeuristicLab.MainForm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">116 <SpecificVersion>False</SpecificVersion>117 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.MainForm-3.3.dll</HintPath>118 <Private>False</Private>119 </Reference>120 <Reference Include="HeuristicLab.MainForm.WindowsForms-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">121 <SpecificVersion>False</SpecificVersion>122 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath>123 113 <Private>False</Private> 124 114 </Reference>
Note: See TracChangeset
for help on using the changeset viewer.