Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7227


Ignore:
Timestamp:
12/22/11 00:12:46 (13 years ago)
Author:
mkommend
Message:

#1661: Corrected AfterDeserialization in SymbolicExpressionTreeLengthAnalyzer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs

    r7223 r7227  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Analysis;
     
    2930using HeuristicLab.Parameters;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using System;
    3232
    3333namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    3737  [Item("SymbolicExpressionTreeLengthAnalyzer", "An operator that tracks tree lengths of Symbolic Expression Trees")]
    3838  [StorableClass]
    39   public sealed class SymbolicExpressionTreeLengthAnalyzer : SingleSuccessorOperator, ISymbolicExpressionTreeAnalyzer {
     39  public sealed class SymbolicExpressionTreeLengthAnalyzer : SingleSuccessorOperator, ISymbolicExpressionTreeAnalyzer, IStatefulItem {
    4040    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4141    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     
    9191    private SymbolicExpressionTreeLengthAnalyzer(SymbolicExpressionTreeLengthAnalyzer original, Cloner cloner)
    9292      : base(original, cloner) {
    93       AfterDeserialization();
    9493    }
    9594    public override IDeepCloneable Clone(Cloner cloner) {
     
    107106      Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
    108107
    109       AfterDeserialization();
     108      SymbolicExpressionTreeLengthsParameter.Hidden = true;
     109      SymbolicExpressionTreeLengthsHistoryParameter.Hidden = true;
     110      ResultsParameter.Hidden = true;
     111      UpdateCounterParameter.Hidden = true;
    110112    }
    111113
     
    119121        Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    120122      }
    121       if (Parameters.ContainsKey(UpdateCounterParameterName))
    122         Parameters.Remove(UpdateCounterParameterName);
    123       Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
    124 
    125       SymbolicExpressionTreeLengthsParameter.Hidden = true;
    126       SymbolicExpressionTreeLengthsHistoryParameter.Hidden = true;
    127       ResultsParameter.Hidden = true;
    128       UpdateCounterParameter.Hidden = true;
    129     }
     123      if (!Parameters.ContainsKey(UpdateCounterParameterName)) {
     124        Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
     125        UpdateCounterParameter.Hidden = true;
     126      }
     127    }
     128
     129    #region IStatefulItem members
     130    public void InitializeState() {
     131      UpdateCounter.Value = 0;
     132    }
     133    public void ClearState() {
     134      UpdateCounter.Value = 0;
     135    }
     136    #endregion
    130137
    131138    public override IOperation Apply() {
     
    222229
    223230        if (storeHistory) {
    224           // store tree lengths for each generation
    225           var historyDataRow = new DataRow("Tree lengths", "", treeLengthsTableRow.Values);
    226           historyDataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    227           historyDataRow.VisualProperties.ExactBins = false;
    228           historyDataRow.VisualProperties.Bins = range;
    229           historyDataRow.VisualProperties.ScaleFactor = treeLengthsTableRow.VisualProperties.ScaleFactor;
    230           historyDataRow.VisualProperties.IsVisibleInLegend = false;
    231           var historyTable = new DataTable("Tree lengths");
    232           historyTable.Rows.Add(historyDataRow);
    233           // visual properties for the X-axis
    234           historyTable.VisualProperties.XAxisMinimumAuto = false;
    235           historyTable.VisualProperties.XAxisMaximumAuto = false;
    236           historyTable.VisualProperties.XAxisMinimumFixedValue = 0.0;
    237           if (maxLength > maximumAllowedTreeLength + 1)
    238             historyTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed
    239           else
    240             historyTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1;
    241           historyTable.VisualProperties.XAxisTitle = xAxisTitle;
    242           // visual properties for the Y-axis
    243           historyTable.VisualProperties.YAxisMinimumAuto = false;
    244           historyTable.VisualProperties.YAxisMaximumAuto = false;
    245           historyTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
    246           historyTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue;
    247           historyTable.VisualProperties.YAxisTitle = yAxisTitle;
    248 
    249231          var treeLengthsHistory = SymbolicExpressionTreeLengthsHistoryParameter.ActualValue;
    250232          if (treeLengthsHistory == null) {
     
    252234            SymbolicExpressionTreeLengthsHistoryParameter.ActualValue = treeLengthsHistory;
    253235          }
    254 
    255           treeLengthsHistory.Add(historyTable);
     236          treeLengthsHistory.Add((DataTable)treeLengthsTable.Clone());
    256237
    257238          if (!results.ContainsKey(treeLengthHistoryTableName)) {
Note: See TracChangeset for help on using the changeset viewer.