Changeset 12283
- Timestamp:
- 04/02/15 16:35:59 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs
r12265 r12283 84 84 nodeWeightLabel.Text = String.Format("{0:0.00}", graphNode.Weight); 85 85 86 int colorCount = ColorGradient.Colors.Count - 1; 87 const int alpha = 100; 88 // calculate max only in the current generation 89 var nodes = graphNode.Data.IterateNodesPrefix().Skip(1).ToList(); 90 var max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(n => n.NodeWeight)); 91 if (max.IsAlmost(0)) max = 1; 92 foreach (var n in nodes) { 93 var visualSymbolicExpressionTreeNode = SymbolicExpressionTreeChart.GetVisualSymbolicExpressionTreeNode(n); 94 visualSymbolicExpressionTreeNode.ToolTip += Environment.NewLine + String.Format("Weight: {0:0}", n.NodeWeight); 95 var i = (int)Math.Round(n.NodeWeight / max * colorCount); 96 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 97 treeChart_HighlightSubtree(n, null, fillColor); 98 } 99 86 100 if (!graphNode.InArcs.Any()) return; 87 101 … … 101 115 var fragment = data as IFragment<ISymbolicExpressionTreeNode>; 102 116 var td = data as TraceData; 103 // calculate max only in the current generation 104 var max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(y => y.NodeWeight)); 105 // var max = Content.GetByRank(graphNode.Rank).Max(x => x.Weight); 106 107 if (max.IsAlmost(0)) 108 max = 1; 109 110 int colorCount = ColorGradient.Colors.Count - 1; 111 const int alpha = 100; 117 112 118 if (fragment != null) { 113 119 // highlight the fragment with a blue line color … … 115 121 treeChart_HighlightSubtree(n, Color.CornflowerBlue); 116 122 } 117 // highlight all the nodes according to their sample count118 var nodes = graphNode.Data.IterateNodesPrefix().ToList();119 foreach (var n in nodes.Skip(1)) {120 var i = (int)Math.Round(n.NodeWeight / max * colorCount);121 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]);122 treeChart_HighlightSubtree(n, null, fillColor);123 }124 123 } else if (td != null) { 125 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 126 foreach (var n in nodes.Skip(1)) { // skip program root symbol 127 var i = (int)Math.Round(n.NodeWeight / max * colorCount); 128 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 129 treeChart_HighlightSubtree(n, null, fillColor); 130 } 124 // highlight traced subtree and fragment 131 125 treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange); 132 126 treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue); … … 141 135 // check whether we are in 'trace' or 'match' mode 142 136 if (trace) { 143 // TODO: maybe highlight based on per generation maximum144 // double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Average(y => y.NodeWeight));145 137 // perform fragment tracing 146 138 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; 147 var max = Content.GetByRank(graphNode.Rank).Max(x => x.Weight);148 139 var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(node); 149 140 var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: false, updateSubtreeWeights: false, cacheTraceNodes: true); 141 genealogyGraphChart.UpdateEnabled = false; 142 genealogyGraphChart.ClearPrimitives(); // clear everything 143 var rankMaximums = new Dictionary<double, double>(); 144 // fill each vertex in the graph with a grayscale color according to average subtree weight 145 foreach (var r in Content.Ranks) { 146 var vertices = r.Value.Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>().ToList(); 147 var averages = vertices.Select(x => x.Data.IterateNodesPrefix().Average(n => n.NodeWeight)).ToList(); 148 var max = averages.Max(); 149 rankMaximums.Add(r.Key, max); 150 if (max.IsAlmost(0.0)) continue; 151 int colorCount = ColorGradient.GrayscaledColors.Count - 1; 152 for (int i = 0; i < vertices.Count; ++i) { 153 var color = ColorGradient.GrayscaledColors[(int)Math.Round(averages[i] / max * colorCount)]; 154 var vNode = genealogyGraphChart.GetMappedNode(vertices[i]); 155 vNode.Brush = new SolidBrush(color); 156 } 157 } 158 // fill vertices that are part of the trace with a rgb color according to average subtree weight 150 159 if (traceGraph.Vertices.Any()) { 151 var vertices = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data)); 152 genealogyGraphChart.UpdateEnabled = false; 153 genealogyGraphChart.ClearPrimitives(); 154 foreach (var v in vertices) { 155 var vNode = genealogyGraphChart.GetMappedNode(v); 156 var wSum = v.Data.IterateNodesPrefix().Average(x => x.NodeWeight); 157 // use a grayscale gradient 158 var color = ColorGradient.GrayscaledColors[(int)Math.Round(wSum / max * (ColorGradient.GrayscaledColors.Count - 1))]; 159 vNode.Brush = new SolidBrush(color); 160 } 161 genealogyGraphChart.UpdateEnabled = true; 162 genealogyGraphChart.EnforceUpdate(); 160 var ranks = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data)).GroupBy(x => x.Rank); 161 int colorCount = ColorGradient.Colors.Count - 1; 162 foreach (var g in ranks) { 163 var vertices = g.ToList(); 164 var averages = vertices.Select(x => x.Data.IterateNodesPrefix().Average(n => n.NodeWeight)).ToList(); 165 double max = rankMaximums[g.Key]; 166 if (max.IsAlmost(0.0)) continue; 167 for (int i = 0; i < vertices.Count; ++i) { 168 var vNode = genealogyGraphChart.GetMappedNode(vertices[i]); 169 // use a grayscale gradient 170 var color = ColorGradient.Colors[(int)Math.Round(averages[i] / max * colorCount)]; 171 vNode.Brush = new SolidBrush(color); 172 } 173 } 163 174 164 175 if (openNew_CheckBox.Checked) { … … 166 177 } 167 178 } 179 genealogyGraphChart.UpdateEnabled = true; 180 genealogyGraphChart.EnforceUpdate(); 168 181 } else { 169 182 // perform matching like it was done before -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/BuildingBlockAnalyzers/SymbolicDataAnalysisPoly10Analyzer.cs
r11493 r12283 45 45 private const string BuildingBlocksFrequenciesTableName = "Building blocks frequencies"; 46 46 47 48 47 // store evaluations of building blocks for phenotypic matching 49 48 private readonly Dictionary<string, List<double>> evaluationMap = new Dictionary<string, List<double>>(); … … 141 140 var dataset = ProblemDataParameter.ActualValue.Dataset; 142 141 var rows = ProblemDataParameter.ActualValue.TrainingIndices.ToList(); 143 OnlineCalculatorError error; 144 Dictionary<string, int> bbFrequencies = evaluationMap.Keys.ToDictionary(x => x, x => 0); 142 var bbFrequencies = evaluationMap.Keys.ToDictionary(x => x, x => 0); 145 143 146 144 foreach (var key in evaluationMap.Keys) { … … 154 152 var s = nodes[i]; 155 153 var values = interpreter.GetValues(s, dataset, rows); 154 OnlineCalculatorError error; 156 155 var r2 = OnlinePearsonsRSquaredCalculator.Calculate(values, evaluationMap[key], out error); 157 156 if (error == OnlineCalculatorError.None && r2 >= PhenotypicSimilarityThreshold) { … … 163 162 } 164 163 var table = (DataTable)results[BuildingBlocksFrequenciesTableName].Value; 164 double max = bbFrequencies.Max(x => x.Value); 165 165 foreach (var pair in bbFrequencies) { 166 var formatter = new SymbolicExpressionTreeStringFormatter(); 167 // var label = formatter.Format(fragmentMap[pair.Key]) + "(" + prettyLabels[pair.Key] + ")"; 166 168 var label = prettyLabels[pair.Key]; 167 table.Rows[label].Values.Add(pair.Value); 169 if (table.Rows.ContainsKey(label)) { 170 var row = table.Rows[label]; 171 // scale previous values according to the new max 172 // if (row.Values.Count > 0) { 173 // var values = new List<double>(row.Values); 174 // var m = values.Max(); 175 // row.Values.Replace(values.Select(x => x * m / max)); 176 // } 177 row.Values.Add(max > 0 ? pair.Value / max : 0); 178 } 168 179 } 169 180 … … 227 238 table.Rows.Clear(); 228 239 foreach (var key in evaluationMap.Keys) { 229 table.Rows.Add(new DataRow(prettyLabels[key]) );240 table.Rows.Add(new DataRow(prettyLabels[key]) { VisualProperties = { StartIndexZero = true } }); 230 241 } 231 242 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs
r12265 r12283 104 104 g.Weight = v.Weight; 105 105 } 106 107 // analyze subtree frequencies 108 foreach (var v in PopulationGraph.GetByRank(Generation.Value)) { 109 var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)v; 110 var t = g.Data; 111 112 113 } 106 114 } 115 107 116 return base.Apply(); 108 117 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r12265 r12283 249 249 arc = new GenealogyGraphArc(current, last) { Data = td }; 250 250 TraceGraph.AddArc(arc); 251 } else { 252 if (UpdateVertexWeights) { 253 arc.Weight++; 254 current.Weight++; 255 } 256 if (UpdateSubtreeWeights) { 257 var subtree = NodeAt(current.Data, td.SubtreeIndex); 258 foreach (var s in subtree.IterateNodesPrefix()) 259 s.NodeWeight++; 260 } 251 } 252 if (UpdateVertexWeights) { 253 arc.Weight++; 254 current.Weight++; 255 } 256 if (UpdateSubtreeWeights) { 257 var subtree = NodeAt(current.Data, td.SubtreeIndex); 258 foreach (var s in subtree.IterateNodesPrefix()) 259 s.NodeWeight++; 261 260 } 262 261 }
Note: See TracChangeset
for help on using the changeset viewer.