Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7143


Ignore:
Timestamp:
12/06/11 19:41:26 (13 years ago)
Author:
bburlacu
Message:

#1661: Refactored some bits in the SymbolicExpressionTreeLengthAnalyzer. It now works with GA and it mostly works with OSGA, short of an interesting bug that I couldn't yet track down.

The bug occurs in the following situation:

  • Using OSGA with the SymbolicExpressionTreeLengthAnalyzer turned on
  • Everything works until the user wants to see the graphical histogram
  • During the update of the bar chart/histogram, at some point the chart throws an overflow exception (possible overflow by zero or related). The exception is followed by a long stack trace involving WinForms and the Graphics system.
  • The user can click continue and run again (if the histogram is not displayed then everything is fine)
File:
1 edited

Legend:

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

    r7124 r7143  
    4646    private const string UpdateIntervalParameterName = "UpdateInterval";
    4747    private const string UpdateCounterParameterName = "UpdateCounter";
     48    private const string GenerationCounterParameterName = "GenerationCounter";
    4849
    4950    #region Parameter properties
     
    6768      get { return (ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; }
    6869    }
    69     public LookupParameter<IntValue> UpdateCounterParameter {
    70       get { return (LookupParameter<IntValue>)Parameters[UpdateCounterParameterName]; }
    71     }
     70    public ValueParameter<IntValue> UpdateCounterParameter {
     71      get { return (ValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; }
     72    }
     73    public ValueParameter<IntValue> GenerationCounterParameter {
     74      get { return (ValueParameter<IntValue>)Parameters[GenerationCounterParameterName]; }
     75    }
     76    #endregion
     77
     78    #region Properties
     79    public IntValue UpdateInterval {
     80      get { return UpdateIntervalParameter.Value; }
     81    }
     82    public IntValue UpdateCounter {
     83      get { return UpdateCounterParameter.Value; }
     84    }
     85    public BoolValue StoreHistory {
     86      get { return StoreHistoryParameter.Value; }
     87    }
     88    public IntValue GenerationCounter {
     89      get { return GenerationCounterParameter.Value; }
     90    }
     91
    7292    #endregion
    7393
     
    90110      Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false)));
    91111      Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    92       Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter"));
     112      Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
     113      Parameters.Add(new ValueParameter<IntValue>(GenerationCounterParameterName, "The value of the total number of generations this operator has been applied.", new IntValue(0)));
    93114
    94115      UpdateCounterParameter.Hidden = true;
     
    107128      }
    108129      if (!Parameters.ContainsKey(UpdateCounterParameterName)) {
    109         Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter"));
     130        Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update"));
     131      }
     132      if (!Parameters.ContainsKey(GenerationCounterParameterName)) {
     133        Parameters.Add(new ValueParameter<IntValue>(GenerationCounterParameterName, "The value of the total number of generations this operator has been applied.", new IntValue(1)));
    110134      }
    111135    }
    112136
    113137    public override IOperation Apply() {
    114       int updateInterval = UpdateIntervalParameter.Value.Value;
    115       IntValue updateCounter = UpdateCounterParameter.ActualValue;
     138      //IntValue updateCounter = UpdateCounterParameter.Value;
    116139      // if the counter doesn't exist yet, we initialize it here with the current update interval
    117       if (updateCounter == null) {
    118         updateCounter = new IntValue(updateInterval);
    119         UpdateCounterParameter.ActualValue = updateCounter;
    120       } else updateCounter.Value++;
     140      GenerationCounter.Value++;
     141      UpdateCounter.Value++;
    121142
    122143      // the analyzer runs periodically, every 'updateInterval' times
    123       if (updateCounter.Value == updateInterval) {
    124         updateCounter.Value = 0; // reset counter
     144      if (UpdateCounter.Value == UpdateInterval.Value) {
     145        UpdateCounter.Value = 0; // reset counter
    125146
    126147        // compute all tree lengths and store them in the lengthsTable
     
    202223        const string treeLengthHistoryTableName = "Tree lengths history";
    203224        const string treeLengthHistoryRowPrefix = "Tree lengths ";
    204         int currentGeneration = ((IntValue)results["Generations"].Value).Value;
    205225
    206226        if (storeHistory) {
    207227          // store tree lengths for each generation
    208           var historyDataRow = new DataRow(treeLengthHistoryRowPrefix + currentGeneration, "Symbolic expression tree lengths at generation " + currentGeneration, treeLengthsTableRow.Values);
     228          var historyDataRow = new DataRow(treeLengthHistoryRowPrefix + GenerationCounter.Value, "Symbolic expression tree lengths at generation " + GenerationCounter.Value, treeLengthsTableRow.Values);
    209229          historyDataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    210230          historyDataRow.VisualProperties.ExactBins = false;
Note: See TracChangeset for help on using the changeset viewer.