Changeset 12265 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Timestamp:
- 03/29/15 23:40:57 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs
r12225 r12265 1 #region License Information1 #region License information 2 2 /* HeuristicLab 3 3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using HeuristicLab.EvolutionTracking; 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 … … 32 33 [StorableClass] 33 34 public class SymbolicDataAnalysisSubtreeSampleCountAnalyzer : EvolutionTrackingAnalyzer<ISymbolicExpressionTree> { 35 private const string CacheTraceNodesParameterName = "CacheTraceNodes"; 34 36 private readonly TraceCalculator traceCalculator = new TraceCalculator { UpdateVertexWeights = true, UpdateSubtreeWeights = true, CacheTraceNodes = true }; 35 37 38 #region parameters 39 public IFixedValueParameter<BoolValue> CacheTraceNodesParameter { 40 get { return (IFixedValueParameter<BoolValue>)Parameters[CacheTraceNodesParameterName]; } 41 } 42 #endregion 43 44 #region parameter properties 45 public bool CacheTraceNodes { 46 get { return CacheTraceNodesParameter.Value.Value; } 47 set { CacheTraceNodesParameter.Value.Value = value; } 48 } 49 #endregion 50 36 51 public SymbolicDataAnalysisSubtreeSampleCountAnalyzer() { 37 UpdateCounterParameter.ActualName = "TraceOverlapAnalyzerUpdateCounter"; 52 UpdateCounterParameter.ActualName = "SubtreeSampleCountAnalyzerUpdateCounter"; 53 54 Parameters.Add(new FixedValueParameter<BoolValue>(CacheTraceNodesParameterName, new BoolValue(true))); 38 55 } 39 56 … … 77 94 return base.Apply(); 78 95 79 double avgTraceOverlap = 0; 80 96 traceCalculator.CacheTraceNodes = CacheTraceNodes; 81 97 if (Generation.Value > 0) { 82 98 var rank = PopulationGraph.GetByRank(Generation.Value).Cast<IGenealogyGraphNode<ISymbolicExpressionTree>>().ToList(); 83 foreach (var n in rank) { 84 // during the trace the SymbolicExpressionTreeNode weights will be updated behind the scenes 85 // the weights represent the sample count of each subtree 86 var trace = traceCalculator.Trace(n, 2, false); 87 foreach (var v in trace.Vertices) { 88 var g = PopulationGraph.GetByContent(v.Data); 89 g.Weight = v.Weight; 90 } 99 foreach (var n in rank) 100 traceCalculator.Trace(n, 2, false); // during this call weights will be updated 101 102 foreach (var v in traceCalculator.TraceGraph.Vertices) { 103 var g = PopulationGraph.GetByContent(v.Data); 104 g.Weight = v.Weight; 91 105 } 92 106 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs
r12231 r12265 155 155 traceCache.Add(t1); 156 156 } 157 // gather statistics about sampled individuals and sampled subtrees158 if (UpdateVertexWeights)159 n.Weight++;160 if (UpdateSubtreeWeights) {161 var arcs = (List<IArc>)((IVertex)n).InArcs; // at this moment n will have been added as a child to the next trace node162 163 // TODO: try to simplify the code below164 for (int i = 0; i < arcs.Count; ++i) {165 var td = (TraceData)((IArc<IDeepCloneable>)arcs[i]).Data;166 var p = (IGenealogyGraphNode<ISymbolicExpressionTree>)arcs[i].Source;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 node170 arcs[i].Weight++; // the arc weights (since there are multiple arcs) will sum up to the same count but give more detail171 break;172 }173 }174 }175 157 break; 176 158 } else { … … 197 179 traceCache.Add(t); 198 180 } 199 if (UpdateVertexWeights)200 n.Weight++;201 181 break; 202 182 } else { … … 257 237 /// <param name="si">The index of the traced subtree</param> 258 238 /// <param name="fi">The index of the fragment</param> 259 private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current, 260 IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) { 239 private void ConnectLast(IGenealogyGraphNode<ISymbolicExpressionTree> current, IGenealogyGraphNode<ISymbolicExpressionTree> last, int si, int fi) { 261 240 var lastTraceData = traceMap[last]; 262 241 int lastSi = lastTraceData.SubtreeIndex; // last subtree index (index of the traced subtree in the previous trace node) 263 242 int lastFi = lastTraceData.FragmentIndex; // last fragment index (index of the fragment in the previous trace node) 264 243 var td = new TraceData(si, fi, lastSi, lastFi); // trace data 265 // using the inArcs seems to be slightly more efficient than using the outArcs 244 266 245 // TODO: more testing 267 var inArcs = (List<IArc>)((IVertex)last).InArcs; 246 var inArcs = (List<IArc>)((IVertex)last).InArcs; // using the InArcs seems to be slightly more efficient than using the OutArcs 268 247 var arc = inArcs.FirstOrDefault(a => a.Source == current && ((IArc<IDeepCloneable>)a).Data.Equals(td)); 269 248 if (arc == null) { 270 249 arc = new GenealogyGraphArc(current, last) { Data = td }; 271 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 } 272 261 } 273 262 }
Note: See TracChangeset
for help on using the changeset viewer.