Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RegressionBenchmarks/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/MinAverageMaxSymbolicExpressionTreeLengthAnalyzer.cs @ 7255

Last change on this file since 7255 was 7255, checked in by sforsten, 12 years ago

#1708: merged r7209 from trunk

  • adjusted GUI
  • added toggle for the different series
  • X Axis labels are rounded to useful values
  • added ToolTip
File size: 6.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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;
23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
32  /// <summary>
33  /// An operator that tracks the min average and max length of symbolic expression trees.
34  /// </summary>
35  [Item("MinAverageMaxSymbolicExpressionTreeLengthAnalyzer", "An operator that tracks the min avgerage and max length of symbolic expression trees.")]
36  [StorableClass]
37  public sealed class MinAverageMaxSymbolicExpressionTreeLengthAnalyzer : AlgorithmOperator, ISymbolicExpressionTreeAnalyzer {
38    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
39    private const string SymbolicExpressionTreeLengthParameterName = "SymbolicExpressionTreeLength";
40    private const string SymbolicExpressionTreeLengthsParameterName = "Symbolic expression tree length";
41    private const string MinTreeLengthParameterName = "Minimal symbolic expression tree length";
42    private const string AverageTreeLengthParameterName = "Average symbolic expression tree length";
43    private const string MaxTreeLengthParameterName = "Maximal symbolic expression tree length";
44    private const string ResultsParameterName = "Results";
45
46    public bool EnabledByDefault {
47      get { return true; }
48    }
49
50    #region parameter properties
51    public IScopeTreeLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
52      get { return (IScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
53    }
54    public ScopeTreeLookupParameter<DoubleValue> SymbolicExpressionTreeLengthParameter {
55      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[SymbolicExpressionTreeLengthParameterName]; }
56    }
57    public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter {
58      get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; }
59    }
60    public ValueLookupParameter<VariableCollection> ResultsParameter {
61      get { return (ValueLookupParameter<VariableCollection>)Parameters[ResultsParameterName]; }
62    }
63
64    [Storable]
65    private MinAverageMaxValueAnalyzer valueAnalyzer;
66    [Storable]
67    private UniformSubScopesProcessor subScopesProcessor;
68
69    #endregion
70
71    [StorableConstructor]
72    private MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(bool deserializing) : base() { }
73    private MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(MinAverageMaxSymbolicExpressionTreeLengthAnalyzer original, Cloner cloner)
74      : base(original, cloner) {
75      AfterDeserialization();
76    }
77    public MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()
78      : base() {
79      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree whose length should be calculated."));
80      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(SymbolicExpressionTreeLengthParameterName, "The length of the symbolic expression tree."));
81      Parameters.Add(new ValueLookupParameter<DataTable>(SymbolicExpressionTreeLengthsParameterName, "The data table to store the symbolic expression tree lengths."));
82      Parameters.Add(new ValueLookupParameter<VariableCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
83
84      subScopesProcessor = new UniformSubScopesProcessor();
85      SymbolicExpressionTreeLengthCalculator lengthCalculator = new SymbolicExpressionTreeLengthCalculator();
86      valueAnalyzer = new MinAverageMaxValueAnalyzer();
87
88      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
89      lengthCalculator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
90      lengthCalculator.SymbolicExpressionTreeLengthParameter.ActualName = SymbolicExpressionTreeLengthParameter.Name;
91      valueAnalyzer.ValueParameter.ActualName = lengthCalculator.SymbolicExpressionTreeLengthParameter.Name;
92      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeLengthParameter.Depth;
93      valueAnalyzer.AverageValueParameter.ActualName = AverageTreeLengthParameterName;
94      valueAnalyzer.CollectAverageValueInResultsParameter.Value = new BoolValue(false);
95      valueAnalyzer.MaxValueParameter.ActualName = MaxTreeLengthParameterName;
96      valueAnalyzer.CollectMaxValueInResultsParameter.Value = new BoolValue(false);
97      valueAnalyzer.MinValueParameter.ActualName = MinTreeLengthParameterName;
98      valueAnalyzer.CollectMinValueInResultsParameter.Value = new BoolValue(false);
99      valueAnalyzer.ValuesParameter.ActualName = SymbolicExpressionTreeLengthsParameter.Name;
100
101      OperatorGraph.InitialOperator = subScopesProcessor;
102      subScopesProcessor.Operator = lengthCalculator;
103      lengthCalculator.Successor = null;
104      subScopesProcessor.Successor = valueAnalyzer;
105      valueAnalyzer.Successor = null;
106
107      AfterDeserialization();
108    }
109
110
111    [StorableHook(HookType.AfterDeserialization)]
112    private void AfterDeserialization() {
113      SymbolicExpressionTreeParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeParameter_DepthChanged);
114      SymbolicExpressionTreeLengthParameter.DepthChanged += new EventHandler(SymbolicExpressionTreeLengthParameter_DepthChanged);
115    }
116
117    public override IDeepCloneable Clone(Cloner cloner) {
118      return new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer(this, cloner);
119    }
120
121    private void SymbolicExpressionTreeParameter_DepthChanged(object sender, EventArgs e) {
122      OnDepthParameterChanged();
123    }
124
125    private void SymbolicExpressionTreeLengthParameter_DepthChanged(object sender, EventArgs e) {
126      OnDepthParameterChanged();
127    }
128
129    private void OnDepthParameterChanged() {
130      valueAnalyzer.ValueParameter.Depth = SymbolicExpressionTreeParameter.Depth;
131      subScopesProcessor.Depth.Value = SymbolicExpressionTreeParameter.Depth;
132    }
133  }
134}
Note: See TracBrowser for help on using the repository browser.