Changeset 16303 for branches/2956_apriori_knowledge/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
- Timestamp:
- 11/16/18 11:55:13 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2956_apriori_knowledge/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r15583 r16303 26 26 using System.Threading.Tasks; 27 27 using System.Windows.Forms; 28 using HeuristicLab.Algorithms.DataAnalysis.KnowledgeIntegration.Interpreter; 29 using HeuristicLab.Algorithms.DataAnalysis.KnowledgeIntegration.IntervalArithmetic; 30 using HeuristicLab.Algorithms.DataAnalysis.KnowledgeIntegration.Util; 28 31 using HeuristicLab.Common; 29 32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 36 39 private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> foldedNodes; 37 40 private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes; 41 //private Dictionary<ISymbolicExpressionTreeNode, Interval> intervals; 42 private Dictionary<ISymbolicExpressionTreeNode, Interval> intervals; 38 43 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 39 44 … … 50 55 changedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); 51 56 nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 57 //intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); 52 58 this.Caption = "Interactive Solution Simplifier"; 53 59 this.impactCalculator = impactCalculator; … … 185 191 progress.Start("Calculate Impact and Replacement Values ..."); 186 192 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 193 var interpreter = new SymbolicDataAnalysisIntervalArithmeticInterpreter(); 194 195 //var intervalParam = ((IRegressionProblemData)Content.ProblemData).IntervalVariable; 196 var customIntervals = new Dictionary<String, Interval>(); 197 var parser = new FormulationParser(); 198 //foreach (var ci in intervalParam) { 199 //var inter = parser.Parse(ci.Formulation.GetValue()); 200 //customIntervals.Add(ci.Variable.GetValue(), new Interval(0, 1)); 201 //} 202 var resultInterval = interpreter.GetSymbolicExressionTreeIntervals(tree, Content.ProblemData.Dataset, Content.ProblemData.TrainingIndices, out intervals); 187 203 await Task.Delay(500); // wait for progressbar to finish animation 188 204 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); … … 190 206 foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value); 191 207 } 208 //Instruction currentInstr = instructions.NextInstruction(); 209 //while (instructions.HasNextInstruction()) { 210 // //intervals[currentInstr.dynamicNode] = (Interval)currentInstr.data; 211 // intervals.Add(Tuple.Create(currentInstr.dynamicNode, (Interval)currentInstr.data)); 212 // currentInstr = instructions.NextInstruction(); 213 //} 214 215 216 217 //intervals.Add(Tuple.Create(currentInstr.dynamicNode, (Interval)currentInstr.data)); 192 218 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 193 219 progress.Finish(); 194 PaintNodeImpacts(); 220 PaintIntervals(); 221 //PaintNodeImpacts(); 195 222 } 196 223 … … 253 280 } 254 281 282 private void PaintIntervals() { 283 int node = 0; 284 var impacts = nodeImpacts.Values; 285 double max = impacts.Max(); 286 double min = impacts.Min(); 287 288 foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPrefix()) { 289 VisualTreeNode<ISymbolicExpressionTreeNode> visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode); 290 291 if (visualTree != null) { 292 visualTree.ToolTip = visualTree.Content.ToString(); 293 //visualTree.ToolTip += String.Format($"{Environment.NewLine}Intervals: [{intervals[node].Item2.LowerBound:E4} ... {intervals[node].Item2.UpperBound:E4}]{Environment.NewLine}"); 294 visualTree.ToolTip += String.Format($"{Environment.NewLine}Intervals: [{intervals[treeNode].LowerBound:E4} ... {intervals[treeNode].UpperBound:E4}]{Environment.NewLine}]"); 295 node++; 296 297 if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) { 298 double impact = nodeImpacts[treeNode]; 299 300 // impact = 0 if no change 301 // impact < 0 if new solution is better 302 // impact > 0 if new solution is worse 303 if (impact < 0.0) { 304 visualTree.FillColor = Color.FromArgb((int)(impact / min * 255), Color.Red); 305 } else if (impact.IsAlmost(0.0)) { 306 visualTree.FillColor = Color.White; 307 } else { 308 // max is guaranteed to be > 0 309 visualTree.FillColor = Color.FromArgb((int)(impact / max * 255), Color.Green); 310 } 311 visualTree.ToolTip += String.Format($"{Environment.NewLine} Node impact: {impact:E4}"); 312 var constantReplacementNode = foldedNodes[treeNode] as ConstantTreeNode; 313 if (constantReplacementNode != null) { 314 visualTree.ToolTip += String.Format($"{Environment.NewLine} Replacement value: {constantReplacementNode.Value:E4}"); 315 } 316 } 317 if (changedNodes.ContainsKey(treeNode)) { 318 visualTree.LineColor = Color.DodgerBlue; 319 } else if (treeNode is ConstantTreeNode && foldedNodes.ContainsKey(treeNode)) { 320 visualTree.LineColor = Color.DarkOrange; 321 } 322 } 323 } 324 treeChart.RepaintNodes(); 325 } 326 255 327 private void PaintNodeImpacts() { 256 328 var impacts = nodeImpacts.Values;
Note: See TracChangeset
for help on using the changeset viewer.