Changeset 12231 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers
- Timestamp:
- 03/20/15 18:20:59 (9 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
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();
Note: See TracChangeset
for help on using the changeset viewer.