Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/02/12 11:40:31 (12 years ago)
Author:
sforsten
Message:

#1708: merged r7209 from trunk

  • adjusted GUI
  • added toggle for the different series
  • X Axis labels are rounded to useful values
  • added ToolTip
Location:
branches/RegressionBenchmarks
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/RegressionBenchmarks

  • branches/RegressionBenchmarks/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionTreeLengthAnalyzer.cs

    r7085 r7255  
    2020#endregion
    2121
    22 using System;
    2322using System.Linq;
    2423using HeuristicLab.Analysis;
     
    5251    }
    5352    public ValueLookupParameter<DataTable> SymbolicExpressionTreeLengthsParameter {
    54       get {
    55         return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName];
    56       }
     53      get { return (ValueLookupParameter<DataTable>)Parameters[SymbolicExpressionTreeLengthsParameterName]; }
    5754    }
    5855    public ValueLookupParameter<DataTableHistory> SymbolicExpressionTreeLengthsHistoryParameter {
    59       get {
    60         return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName];
    61       }
     56      get { return (ValueLookupParameter<DataTableHistory>)Parameters[SymbolicExpressionTreeLengthsHistoryParameterName]; }
    6257    }
    6358    public ValueLookupParameter<ResultCollection> ResultsParameter {
     
    7166      get { return (ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; }
    7267    }
    73     public LookupParameter<IntValue> UpdateCounterParameter {
    74       get { return (LookupParameter<IntValue>)Parameters[UpdateCounterParameterName]; }
     68    public ValueParameter<IntValue> UpdateCounterParameter {
     69      get { return (ValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; }
    7570    }
    7671    #endregion
     72
     73    #region Properties
     74    public bool EnabledByDefault {
     75      get { return true; }
     76    }
     77    public IntValue UpdateInterval {
     78      get { return UpdateIntervalParameter.Value; }
     79    }
     80    public IntValue UpdateCounter {
     81      get { return UpdateCounterParameter.Value; }
     82    }
     83    public BoolValue StoreHistory {
     84      get { return StoreHistoryParameter.Value; }
     85    }
     86    #endregion
     87
    7788    [StorableConstructor]
    7889    private SymbolicExpressionTreeLengthAnalyzer(bool deserializing) : base() { }
     
    91102      Parameters.Add(new ValueLookupParameter<DataTableHistory>(SymbolicExpressionTreeLengthsHistoryParameterName, "The data table to store the symbolic expression tree lengths history."));
    92103      Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
    93 
    94       #region Add parameters for history
    95104      Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false)));
    96105      Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    97       Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter"));
    98       #endregion
    99 
    100       UpdateCounterParameter.Hidden = true;
     106      Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
    101107
    102108      AfterDeserialization();
     
    112118        Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    113119      }
    114       if (!Parameters.ContainsKey(UpdateCounterParameterName)) {
    115         Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", "MinMaxAverageSymbolicExpressionTreeLengthAnalyzerUpdateCounter"));
    116       }
     120      if (Parameters.ContainsKey(UpdateCounterParameterName))
     121        Parameters.Remove(UpdateCounterParameterName);
     122      Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
     123
     124      SymbolicExpressionTreeLengthsParameter.Hidden = true;
     125      SymbolicExpressionTreeLengthsHistoryParameter.Hidden = true;
     126      ResultsParameter.Hidden = true;
     127      UpdateCounterParameter.Hidden = true;
    117128    }
    118129
    119130    public override IOperation Apply() {
    120       int updateInterval = UpdateIntervalParameter.Value.Value;
    121       IntValue updateCounter = UpdateCounterParameter.ActualValue;
    122       // if the counter doesn't exist yet, we initialize it here with the current update interval
    123       if (updateCounter == null) {
    124         updateCounter = new IntValue(updateInterval);
    125         UpdateCounterParameter.ActualValue = updateCounter;
    126       } else updateCounter.Value++;
    127 
     131      UpdateCounter.Value++;
    128132      // the analyzer runs periodically, every 'updateInterval' times
    129       if (updateCounter.Value == updateInterval) {
    130         updateCounter.Value = 0; // reset counter
     133      if (UpdateCounter.Value == UpdateInterval.Value) {
     134        UpdateCounter.Value = 0; // reset counter
    131135
    132136        // compute all tree lengths and store them in the lengthsTable
     
    136140        // if the table was not created yet, we create it here
    137141        if (treeLengthsTable == null) {
    138           treeLengthsTable = new DataTable("Tree Length Values");
     142          treeLengthsTable = new DataTable("Histogram");
    139143          SymbolicExpressionTreeLengthsParameter.ActualValue = treeLengthsTable;
    140144        }
    141145
    142146        // data table which stores tree length values
    143         DataRow dataRow;
    144 
    145         var treeLengths = solutions.Select(s => (double)s.Length);
    146 
    147         if (!treeLengthsTable.Rows.ContainsKey("Tree Lengths")) {
    148           dataRow = new DataRow("Tree Lengths", "", treeLengths);
    149           treeLengthsTable.Rows.Add(dataRow);
     147        DataRow treeLengthsTableRow;
     148
     149        const string treeLengthsTableRowName = "Symbolic expression tree lengths";
     150        const string treeLengthsTableRowDesc = "The distribution of symbolic expression tree lengths";
     151        const string xAxisTitle = "Symbolic expression tree lengths";
     152        const string yAxisTitle = "Frequency / Number of tree individuals";
     153
     154        var treeLengths = solutions.Select(s => (int)s.Length).ToList();
     155
     156        int maxLength = treeLengths.Max(t => t);
     157        int minLength = treeLengths.Min(t => t);
     158
     159        if (!treeLengthsTable.Rows.ContainsKey(treeLengthsTableRowName)) {
     160          treeLengthsTableRow = new DataRow(treeLengthsTableRowName, treeLengthsTableRowDesc, treeLengths.Select(x => (double)x));
     161          treeLengthsTable.Rows.Add(treeLengthsTableRow);
    150162        } else {
    151           dataRow = treeLengthsTable.Rows["Tree Lengths"];
    152           dataRow.Values.Replace(treeLengths);
     163          treeLengthsTableRow = treeLengthsTable.Rows[treeLengthsTableRowName];
     164          treeLengthsTableRow.Values.Replace(treeLengths.Select(x => (double)x));
    153165        }
    154166
    155167        double maximumAllowedTreeLength = ((LookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]).ActualValue.Value;
    156168
    157         dataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    158         dataRow.VisualProperties.ExactBins = false;
    159 
    160         // the following trick should result in an intervalWidth of 1,2,4,... (an int value)
    161         dataRow.VisualProperties.Bins = solutions.Max(s => s.Length) - solutions.Min(s => s.Length);
    162 
    163         int maxLength = solutions.Max(s => s.Length);
    164         if (maxLength <= 25)      // [0,25]
    165           dataRow.VisualProperties.ScaleFactor = 1.0;
    166         else if (maxLength <= 100) // [26,100])
    167           dataRow.VisualProperties.ScaleFactor = 1.0 / 2.0;
    168         else if (maxLength <= 250) // [100,250]
    169           dataRow.VisualProperties.ScaleFactor = 1.0 / 5.0;
     169        treeLengthsTableRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
     170        treeLengthsTableRow.VisualProperties.ExactBins = false;
     171
     172        int range = maxLength - minLength;
     173        if (range == 0) range = 1;
     174        // the following trick should result in an integer intervalWidth of 1,2,4,...
     175        treeLengthsTableRow.VisualProperties.Bins = range;
     176
     177        if (maxLength <= 25) // [0,25]
     178          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0;
     179        else if (maxLength <= 100) // [26,100]
     180          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 2.0;
     181        else if (maxLength <= 250) // [101,250]
     182          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 5.0;
    170183        else if (maxLength <= 500) // [251,500]
    171           dataRow.VisualProperties.ScaleFactor = 1.0 / 10.0;
     184          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 10.0;
    172185        else
    173           dataRow.VisualProperties.ScaleFactor = 1.0 / 20.0;   // [501,inf]
     186          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 20.0; // [501,inf]
     187
     188        treeLengthsTableRow.VisualProperties.IsVisibleInLegend = false;
    174189
    175190        // visual properties for the X-axis
     
    178193        treeLengthsTable.VisualProperties.XAxisMinimumFixedValue = 0.0;
    179194        if (maxLength > maximumAllowedTreeLength + 1)
    180           treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = solutions.Max(s => s.Length) + 1; // +1 so the histogram column for the maximum length won't get trimmed
     195          treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed
    181196        else
    182197          treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1;
    183         // visual properties for the Y-axis
     198        treeLengthsTable.VisualProperties.XAxisTitle = xAxisTitle;
     199        //visual properties for the Y-axis
    184200        treeLengthsTable.VisualProperties.YAxisMinimumAuto = false;
    185201        treeLengthsTable.VisualProperties.YAxisMaximumAuto = false;
    186202        treeLengthsTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
    187         treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0);
     203        int maxFreq = solutions.GroupBy(s => s.Length).Max(g => g.Count());
     204        if (maxFreq % 5 != 0)
     205          maxFreq += (5 - maxFreq % 5);
     206        double yAxisMaximumFixedValue = maxFreq;
     207
     208        treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue;
     209        treeLengthsTable.VisualProperties.YAxisTitle = yAxisTitle;
    188210
    189211        var results = ResultsParameter.ActualValue;
    190212
    191         if (!results.ContainsKey("Tree Lengths")) {
    192           results.Add(new Result("Tree Lengths", treeLengthsTable));
     213        if (!results.ContainsKey(treeLengthsTableRowName)) {
     214          results.Add(new Result(treeLengthsTableRowName, treeLengthsTable));
    193215        } else {
    194           results["Tree Lengths"].Value = treeLengthsTable;
     216          results[treeLengthsTableRowName].Value = treeLengthsTable;
    195217        }
    196218
    197219        bool storeHistory = StoreHistoryParameter.Value.Value;
     220        const string treeLengthHistoryTableName = "Tree lengths history";
    198221
    199222        if (storeHistory) {
    200223          // store tree lengths for each generation
    201           var historyDataRow = new DataRow("Tree Lengths " + results["Generations"].Value, "", dataRow.Values);
     224          var historyDataRow = new DataRow("Tree lengths", "", treeLengthsTableRow.Values);
    202225          historyDataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    203226          historyDataRow.VisualProperties.ExactBins = false;
    204           historyDataRow.VisualProperties.Bins = solutions.Max(s => s.Length) - solutions.Min(s => s.Length);
    205           historyDataRow.VisualProperties.ScaleFactor = dataRow.VisualProperties.ScaleFactor;
    206           var historyTable = new DataTable("Lengths Table " + results["Generations"]);
     227          historyDataRow.VisualProperties.Bins = range;
     228          historyDataRow.VisualProperties.ScaleFactor = treeLengthsTableRow.VisualProperties.ScaleFactor;
     229          historyDataRow.VisualProperties.IsVisibleInLegend = false;
     230          var historyTable = new DataTable("Tree lengths");
    207231          historyTable.Rows.Add(historyDataRow);
    208232          // visual properties for the X-axis
     
    210234          historyTable.VisualProperties.XAxisMaximumAuto = false;
    211235          historyTable.VisualProperties.XAxisMinimumFixedValue = 0.0;
    212           if (solutions.Max(s => s.Length) > maximumAllowedTreeLength + 1)
     236          if (maxLength > maximumAllowedTreeLength + 1)
    213237            historyTable.VisualProperties.XAxisMaximumFixedValue = maxLength + 1; // +1 so the histogram column for the maximum length won't get trimmed
    214238          else
    215239            historyTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1;
     240          historyTable.VisualProperties.XAxisTitle = xAxisTitle;
    216241          // visual properties for the Y-axis
    217242          historyTable.VisualProperties.YAxisMinimumAuto = false;
    218243          historyTable.VisualProperties.YAxisMaximumAuto = false;
    219244          historyTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
    220           historyTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0);
     245          historyTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue;
     246          historyTable.VisualProperties.YAxisTitle = yAxisTitle;
    221247
    222248          var treeLengthsHistory = SymbolicExpressionTreeLengthsHistoryParameter.ActualValue;
     
    228254          treeLengthsHistory.Add(historyTable);
    229255
    230           if (!results.ContainsKey("Tree Lengths History")) {
    231             results.Add(new Result("Tree Lengths History", treeLengthsHistory));
     256          if (!results.ContainsKey(treeLengthHistoryTableName)) {
     257            results.Add(new Result(treeLengthHistoryTableName, treeLengthsHistory));
    232258          } else {
    233             results["Tree Lengths History"].Value = treeLengthsHistory;
     259            results[treeLengthHistoryTableName].Value = treeLengthsHistory;
    234260          }
    235261        }
    236262      }
    237 
    238263      return base.Apply();
    239264    }
Note: See TracChangeset for help on using the changeset viewer.