Changeset 12231
- Timestamp:
- 03/20/15 18:20:59 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 1 deleted
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs
r12155 r12231 34 34 int GetBranchLevel(ISymbolicExpressionTreeNode child); 35 35 36 double NodeWeight { get; set; } 37 36 38 IEnumerable<ISymbolicExpressionTreeNode> IterateNodesBreadth(); 37 39 IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r12155 r12231 50 50 } 51 51 52 [Storable] 53 public double NodeWeight { get; set; } 54 52 55 [StorableConstructor] 53 56 protected SymbolicExpressionTreeNode(bool deserializing) { } … … 57 60 length = original.length; 58 61 depth = original.depth; 62 NodeWeight = original.NodeWeight; 59 63 if (original.subtrees != null) { 60 64 subtrees = new List<ISymbolicExpressionTreeNode>(original.subtrees.Count); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Tracking/SymbolicDataAnalysisGenealogyGraphView.cs
r12225 r12231 100 100 var fragment = data as IFragment<ISymbolicExpressionTreeNode>; 101 101 var td = data as TraceData; 102 // double max = Content.Vertices.SelectMany(x => x.Data.IterateNodesPrefix()).Max(x => x.NodeWeight); 103 102 // double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Max(y => y.NodeWeight)); 103 104 // calculate max only in the current generation 105 double max = Content.GetByRank(graphNode.Rank).Max(x => ((IGenealogyGraphNode<ISymbolicExpressionTree>)x).Data.IterateNodesPrefix().Max(y => y.NodeWeight)); 106 if (max.IsAlmost(0)) max = 1; 107 int c = ColorGradient.Colors.Count - 1; 108 const int alpha = 100; 104 109 if (fragment != null) { 105 // treeChart_HighlightSubtree(graphNode.Data.NodeAt(fragment.Index1)); 110 // highlight the fragment with a blue line color 111 foreach (var n in graphNode.Data.NodeAt(fragment.Index1).IterateNodesPrefix()) { 112 treeChart_HighlightSubtree(n, Color.CornflowerBlue); 113 } 114 // highlight all the nodes according to their sample count 106 115 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 107 int c = ColorGradient.Colors.Count - 1; 116 foreach (var n in nodes.Skip(1)) { 117 var i = (int)Math.Round(n.NodeWeight / max * c); 118 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 119 treeChart_HighlightSubtree(n, null, fillColor); 120 } 121 } else if (td != null) { 122 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 108 123 foreach (var n in nodes.Skip(1)) { // skip program root symbol 109 // var i = (int)Math.Round(n.NodeWeight / max * c); 110 // const int alpha = 50; 111 // var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 112 113 // treeChart_HighlightSubtree(n, null, fillColor); 114 } 115 } else if (td != null) { 116 117 var nodes = graphNode.Data.IterateNodesPrefix().ToList(); 118 int c = ColorGradient.Colors.Count - 1; 119 foreach (var n in nodes.Skip(1)) { // skip program root symbol 120 // var i = (int)Math.Round(n.NodeWeight / max * c); 121 // const int alpha = 50; 122 // var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 123 124 // treeChart_HighlightSubtree(n, null, fillColor); 125 } 126 124 var i = (int)Math.Round(n.NodeWeight / max * c); 125 var fillColor = Color.FromArgb(alpha, ColorGradient.Colors[i]); 126 treeChart_HighlightSubtree(n, null, fillColor); 127 } 127 128 treeChart_HighlightSubtree(nodes[td.LastSubtreeIndex], Color.Orange); 128 129 treeChart_HighlightSubtree(nodes[td.LastFragmentIndex], Color.CornflowerBlue); … … 141 142 142 143 switch (args.Button) { 143 case MouseButtons.Left: 144 SelectedSubtree = subtree; 145 if (trace) { 146 // perform fragment tracing 147 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; 148 var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(subtree); 149 var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: true, updateSubtreeWeights: true, cacheTraceNodes: true); 150 if (traceGraph.Vertices.Any()) { 151 genealogyGraphChart.UpdateEnabled = false; 152 genealogyGraphChart.ClearPrimitives(); 153 var traceVertices = traceGraph.Vertices.ToList(); 154 var genealogyNodes = traceVertices.Select(v => Content.GetByContent(v.Data)).ToList(); 155 // color graph vertices according to their weight 156 double max = traceGraph.Vertices.Max(x => x.Data.IterateNodesPrefix().Max(n => x.Weight)); 157 for (int i = 0; i < genealogyNodes.Count; ++i) { 158 var g = genealogyNodes[i]; 159 g.Weight = traceVertices[i].Weight; 160 var v = genealogyGraphChart.GetMappedNode(g); 161 if (v != null) { 162 v.Brush = new SolidBrush(ColorGradient.Colors[(int)Math.Round(g.Weight * (ColorGradient.Colors.Count - 1) / max)]); 144 case MouseButtons.Left: { 145 SelectedSubtree = subtree; 146 if (trace) { 147 // TODO: maybe highlight based on per generation maximum 148 double max = Content.Vertices.Max(x => x.Data.IterateNodesPrefix().Average(y => y.NodeWeight)); 149 // perform fragment tracing 150 var graphNode = (IGenealogyGraphNode<ISymbolicExpressionTree>)genealogyGraphChart.SelectedGraphNode; 151 var subtreeIndex = graphNode.Data.IterateNodesPrefix().ToList().IndexOf(subtree); 152 var traceGraph = TraceCalculator.TraceSubtree(graphNode, subtreeIndex, updateVertexWeights: false, updateSubtreeWeights: false, cacheTraceNodes: true); 153 if (traceGraph.Vertices.Any()) { 154 var vertices = traceGraph.Vertices.Select(x => Content.GetByContent(x.Data)); 155 genealogyGraphChart.UpdateEnabled = false; 156 genealogyGraphChart.ClearPrimitives(); 157 foreach (var v in vertices) { 158 var vNode = genealogyGraphChart.GetMappedNode(v); 159 var wSum = v.Data.IterateNodesPrefix().Average(x => x.NodeWeight); 160 // use a grayscal gradient 161 var color = ColorGradient.GrayscaledColors[(int)Math.Round(wSum / max * (ColorGradient.GrayscaledColors.Count - 1))]; 162 vNode.Brush = new SolidBrush(color); 163 } 164 genealogyGraphChart.UpdateEnabled = true; 165 genealogyGraphChart.EnforceUpdate(); 166 167 if (openNew_CheckBox.Checked) { 168 MainFormManager.MainForm.ShowContent(traceGraph); // display the fragment graph on the screen 163 169 } 164 170 } 165 166 genealogyGraphChart.UpdateEnabled = true; 167 genealogyGraphChart.EnforceUpdate(); 168 169 if (openNew_CheckBox.Checked) 170 MainFormManager.MainForm.ShowContent(traceGraph); // display the fragment graph on the screen 171 } else { 172 // perform matching like it was done before 173 // currently there is no possibility to specify the subtree matching criteria 174 var trees = Content.Vertices.Select(x => x.Data); 175 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer)); 176 177 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)); 178 graphChart_HighlightMatchingVertices(matchingVertices); 171 179 } 172 } else { 173 // perform matching like it was done before 174 // currently there is no possibility to specify the subtree matching criteria 175 var trees = Content.Vertices.Select(x => x.Data); 176 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(subtree, comparer)); 177 178 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)); 179 graphChart_HighlightMatchingVertices(matchingVertices); 180 } 181 break; 182 case MouseButtons.Middle: 183 var index = SelectedSubtree.IterateNodesPrefix().ToList().IndexOf(subtree); 184 if (index > 0) { 185 var s = ClonedSubtree.NodeAt(index); 186 s.Parent.RemoveSubtree(s.Parent.IndexOfSubtree(s)); 187 188 var trees = Content.Vertices.Select(x => x.Data); 189 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(ClonedSubtree, comparer)); 190 191 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)); 192 treeChart_HighlightSubtree(subtree, Color.Black, Color.White); 193 graphChart_HighlightMatchingVertices(matchingVertices); 194 } 195 break; 180 break; 181 } 182 case MouseButtons.Middle: { 183 var index = SelectedSubtree.IterateNodesPrefix().ToList().IndexOf(subtree); 184 if (index > 0) { 185 var s = ClonedSubtree.NodeAt(index); 186 s.Parent.RemoveSubtree(s.Parent.IndexOfSubtree(s)); 187 188 var trees = Content.Vertices.Select(x => x.Data); 189 var matchingTrees = trees.Where(x => x.Root.ContainsSubtree(ClonedSubtree, comparer)); 190 191 var matchingVertices = matchingTrees.Select(x => Content.GetByContent(x)); 192 treeChart_HighlightSubtree(subtree, Color.Black, Color.White); 193 graphChart_HighlightMatchingVertices(matchingVertices); 194 } 195 break; 196 } 196 197 } 197 198 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs
r12210 r12231 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 using HeuristicLab.Analysis;25 23 using HeuristicLab.Common; 26 24 using HeuristicLab.Core; … … 28 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 27 using HeuristicLab.EvolutionTracking; 30 using HeuristicLab.Optimization;31 28 using HeuristicLab.Parameters; 32 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 30 34 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Tracking.Analyzers { 35 [Item("SymbolicDataAnalysis TraceOverlapAnalyzer", "An analyzer for trace graph overlap.")]32 [Item("SymbolicDataAnalysisSubtreeSampleCountAnalyzer", "An analyzer for trace graph overlap.")] 36 33 [StorableClass] 37 public class SymbolicDataAnalysisTraceOverlapAnalyzer : EvolutionTrackingAnalyzer<ISymbolicExpressionTree> { 38 private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions"; 34 public class SymbolicDataAnalysisSubtreeSampleCountAnalyzer : EvolutionTrackingAnalyzer<ISymbolicExpressionTree> { 35 private const string CacheTraceNodesParameterName = "CacheTraceNodes"; 36 private readonly TraceCalculator traceCalculator = new TraceCalculator { UpdateVertexWeights = true, UpdateSubtreeWeights = true, CacheTraceNodes = true }; 39 37 40 38 #region parameters 41 public IFixedValueParameter< DoubleValue> PercentageOfBestSolutionsParameter {42 get { return (IFixedValueParameter< DoubleValue>)Parameters[PercentageOfBestSolutionsParameterName]; }39 public IFixedValueParameter<BoolValue> CacheTraceNodesParameter { 40 get { return (IFixedValueParameter<BoolValue>)Parameters[CacheTraceNodesParameterName]; } 43 41 } 44 42 #endregion 45 43 46 public SymbolicDataAnalysisTraceOverlapAnalyzer() { 47 UpdateCounterParameter.ActualName = "TraceOverlapAnalyzerUpdateCounter"; 48 Parameters.Add(new FixedValueParameter<DoubleValue>(PercentageOfBestSolutionsParameterName, new DoubleValue(1.0))); 44 #region parameter properties 45 public bool CacheTraceNodes { 46 get { return CacheTraceNodesParameter.Value.Value; } 47 set { CacheTraceNodesParameter.Value.Value = value; } 48 } 49 #endregion 50 51 public SymbolicDataAnalysisSubtreeSampleCountAnalyzer() { 52 UpdateCounterParameter.ActualName = "SubtreeSampleCountAnalyzerUpdateCounter"; 53 54 Parameters.Add(new FixedValueParameter<BoolValue>(CacheTraceNodesParameterName, new BoolValue(true))); 49 55 } 50 56 51 private SymbolicDataAnalysis TraceOverlapAnalyzer(SymbolicDataAnalysisTraceOverlapAnalyzer original, Cloner cloner)57 private SymbolicDataAnalysisSubtreeSampleCountAnalyzer(SymbolicDataAnalysisSubtreeSampleCountAnalyzer original, Cloner cloner) 52 58 : base(original, cloner) { 53 59 } 54 60 55 61 public override IDeepCloneable Clone(Cloner cloner) { 56 return new SymbolicDataAnalysisTraceOverlapAnalyzer(this, cloner); 62 return new SymbolicDataAnalysisSubtreeSampleCountAnalyzer(this, cloner); 63 } 64 65 public override void ClearState() { 66 base.ClearState(); 67 traceCalculator.ResetState(); 68 } 69 70 public override void InitializeState() { 71 traceCalculator.ResetState(); 57 72 } 58 73 59 74 [StorableConstructor] 60 private SymbolicDataAnalysis TraceOverlapAnalyzer(bool deserializing) : base(deserializing) { }75 private SymbolicDataAnalysisSubtreeSampleCountAnalyzer(bool deserializing) : base(deserializing) { } 61 76 62 77 public override IOperation Apply() { … … 79 94 return base.Apply(); 80 95 81 var bestSolutionsPercentage = PercentageOfBestSolutionsParameter.Value.Value; 82 int n = (int)Math.Round(bestSolutionsPercentage * PopulationSize.Value); 83 double avgTraceOverlap = 0; 96 traceCalculator.CacheTraceNodes = CacheTraceNodes; 97 if (Generation.Value > 0) { 98 var rank = PopulationGraph.GetByRank(Generation.Value).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>().ToList(); 99 foreach (var n in rank) 100 traceCalculator.Trace(n, 2, false); // during this call weights will be updated 84 101 85 if (Generation.Value > 0) { 86 var nodes = PopulationGraph.GetByRank(Generation.Value).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>().OrderByDescending(x => x.Quality).Take(n); 87 avgTraceOverlap = nodes.Average(x => TraceCalculator.TraceSubtree(x, 2).Vertices.Count()); 88 } 89 90 DataTable table; 91 if (!Results.ContainsKey("AverageTraceOverlap")) { 92 table = new DataTable("Average trace overlap"); 93 var row = new DataRow("Average trace overlap") { VisualProperties = { StartIndexZero = true } }; 94 row.Values.Add(avgTraceOverlap); 95 table.Rows.Add(row); 96 Results.Add(new Result("AverageTraceOverlap", table)); 97 } else { 98 table = (DataTable)Results["AverageTraceOverlap"].Value; 99 table.Rows["Average trace overlap"].Values.Add(avgTraceOverlap); 102 foreach (var v in traceCalculator.TraceGraph.Vertices) { 103 var g = PopulationGraph.GetByContent(v.Data); 104 g.Weight = v.Weight; 105 } 100 106 } 101 107 return base.Apply(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r12225 r12231 160 160 if (UpdateSubtreeWeights) { 161 161 var arcs = (List<IArc>)((IVertex)n).InArcs; // at this moment n will have been added as a child to the next trace node 162 163 // TODO: try to simplify the code below 162 164 for (int i = 0; i < arcs.Count; ++i) { 163 165 var td = (TraceData)((IArc<IDeepCloneable>)arcs[i]).Data; 164 166 var p = (IGenealogyGraphNode<ISymbolicExpressionTree>)arcs[i].Source; 165 // TODO: the first part of the check below represents a necessary but not sufficient condition166 // TODO: therefore, a Difference check is also performed, it would be nice to make this code more ellegant167 if (td.LastFragmentIndex == td.SubtreeIndex && fragment.Root.Difference(NodeAt(p.Data, td.SubtreeIndex)) == null) {168 arcs[i].Weight++; 167 var s = NodeAt(p.Data, td.SubtreeIndex); 168 if (td.LastFragmentIndex == td.SubtreeIndex && fragment.Root.Difference(s) == null) { 169 foreach (var ss in s.IterateNodesPrefix()) ss.NodeWeight++; // the node weight will represent the total sample count for a given node 170 arcs[i].Weight++; // the arc weights (since there are multiple arcs) will sum up to the same count but give more detail 169 171 break; 170 172 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.TravelingSalesman
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.TravelingSalesman.Views
- Property svn:mergeinfo changed (with no actual effect on merging)
Note: See TracChangeset
for help on using the changeset viewer.