Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/20/15 18:20:59 (10 years ago)
Author:
bburlacu
Message:

#1772: Changed the way node highlighting is performed (taking into account sampling count relative to current generation). Made NodeWeight field storable in the SymbolicExpressionTreeNode. Updated the statistics counting in the TraceCalculator.

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

    r12210 r12231  
    2020#endregion
    2121
    22 using System;
    2322using System.Linq;
    24 using HeuristicLab.Analysis;
    2523using HeuristicLab.Common;
    2624using HeuristicLab.Core;
     
    2826using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2927using HeuristicLab.EvolutionTracking;
    30 using HeuristicLab.Optimization;
    3128using HeuristicLab.Parameters;
    3229using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3330
    3431namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Tracking.Analyzers {
    35   [Item("SymbolicDataAnalysisTraceOverlapAnalyzer", "An analyzer for trace graph overlap.")]
     32  [Item("SymbolicDataAnalysisSubtreeSampleCountAnalyzer", "An analyzer for trace graph overlap.")]
    3633  [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 };
    3937
    4038    #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]; }
    4341    }
    4442    #endregion
    4543
    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)));
    4955    }
    5056
    51     private SymbolicDataAnalysisTraceOverlapAnalyzer(SymbolicDataAnalysisTraceOverlapAnalyzer original, Cloner cloner)
     57    private SymbolicDataAnalysisSubtreeSampleCountAnalyzer(SymbolicDataAnalysisSubtreeSampleCountAnalyzer original, Cloner cloner)
    5258      : base(original, cloner) {
    5359    }
    5460
    5561    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();
    5772    }
    5873
    5974    [StorableConstructor]
    60     private SymbolicDataAnalysisTraceOverlapAnalyzer(bool deserializing) : base(deserializing) { }
     75    private SymbolicDataAnalysisSubtreeSampleCountAnalyzer(bool deserializing) : base(deserializing) { }
    6176
    6277    public override IOperation Apply() {
     
    7994        return base.Apply();
    8095
    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
    84101
    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        }
    100106      }
    101107      return base.Apply();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/TraceCalculator.cs

    r12225 r12231  
    160160              if (UpdateSubtreeWeights) {
    161161                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
    162164                for (int i = 0; i < arcs.Count; ++i) {
    163165                  var td = (TraceData)((IArc<IDeepCloneable>)arcs[i]).Data;
    164166                  var p = (IGenealogyGraphNode<ISymbolicExpressionTree>)arcs[i].Source;
    165                   // TODO: the first part of the check below represents a necessary but not sufficient condition
    166                   // TODO: therefore, a Difference check is also performed, it would be nice to make this code more ellegant
    167                   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
    169171                    break;
    170172                  }
Note: See TracChangeset for help on using the changeset viewer.