Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisSubtreeSampleCountAnalyzer.cs @ 12283

Last change on this file since 12283 was 12283, checked in by bburlacu, 9 years ago

#1772: Updated genealogy graph view and worked on subtree sample count.

File size: 4.6 KB
Line 
1#region License information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.EvolutionTracking;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Tracking.Analyzers {
32  [Item("SymbolicDataAnalysisSubtreeSampleCountAnalyzer", "An analyzer for trace graph overlap.")]
33  [StorableClass]
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 };
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
51    public SymbolicDataAnalysisSubtreeSampleCountAnalyzer() {
52      UpdateCounterParameter.ActualName = "SubtreeSampleCountAnalyzerUpdateCounter";
53
54      Parameters.Add(new FixedValueParameter<BoolValue>(CacheTraceNodesParameterName, new BoolValue(true)));
55    }
56
57    private SymbolicDataAnalysisSubtreeSampleCountAnalyzer(SymbolicDataAnalysisSubtreeSampleCountAnalyzer original, Cloner cloner)
58      : base(original, cloner) {
59    }
60
61    public override IDeepCloneable Clone(Cloner 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();
72    }
73
74    [StorableConstructor]
75    private SymbolicDataAnalysisSubtreeSampleCountAnalyzer(bool deserializing) : base(deserializing) { }
76
77    public override IOperation Apply() {
78      int updateInterval = UpdateIntervalParameter.Value.Value;
79      IntValue updateCounter = UpdateCounterParameter.ActualValue;
80      // if counter does not yet exist then initialize it with update interval
81      // to make sure the solutions are analyzed on the first application of this operator
82      if (updateCounter == null) {
83        updateCounter = new IntValue(updateInterval);
84        UpdateCounterParameter.ActualValue = updateCounter;
85      }
86      //analyze solutions only every 'updateInterval' times
87      if (updateCounter.Value != updateInterval) {
88        updateCounter.Value++;
89        return base.Apply();
90      }
91      updateCounter.Value = 1;
92
93      if (PopulationGraph == null)
94        return base.Apply();
95
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
101
102        foreach (var v in traceCalculator.TraceGraph.Vertices) {
103          var g = PopulationGraph.GetByContent(v.Data);
104          g.Weight = v.Weight;
105        }
106
107        // analyze subtree frequencies
108        foreach (var v in PopulationGraph.GetByRank(Generation.Value)) {
109          var g = (IGenealogyGraphNode<ISymbolicExpressionTree>)v;
110          var t = g.Data;
111
112
113        }
114      }
115
116      return base.Apply();
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.