Changeset 12265 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs
- Timestamp:
- 03/29/15 23:40:57 (10 years ago)
- File:
-
- 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 }
Note: See TracChangeset
for help on using the changeset viewer.