Changeset 7147


Ignore:
Timestamp:
12/07/11 13:24:39 (10 years ago)
Author:
bburlacu
Message:

#1661: Fixed a couple of bugs in the SymbolicExpressionTreeLengthAnalyzer and made some minor aesthetic changes (relating to the way chart columns are displayed).

File:
1 edited

Legend:

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

    r7143 r7147  
    127127        Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1)));
    128128      }
    129       if (!Parameters.ContainsKey(UpdateCounterParameterName)) {
    130         Parameters.Add(new LookupParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update"));
    131       }
     129      if (Parameters.ContainsKey(UpdateCounterParameterName))
     130        Parameters.Remove(UpdateCounterParameterName);
     131      Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called since the last update", new IntValue(0)));
    132132      if (!Parameters.ContainsKey(GenerationCounterParameterName)) {
    133133        Parameters.Add(new ValueParameter<IntValue>(GenerationCounterParameterName, "The value of the total number of generations this operator has been applied.", new IntValue(1)));
     
    163163        const string yAxisTitle = "Frequency / Number of tree individuals";
    164164
    165         var treeLengths = solutions.Select(s => (double)s.Length);
    166         int maxLength = solutions.Max(s => s.Length);
    167         int minLength = solutions.Min(s => s.Length);
     165        var treeLengths = solutions.Select(s => (int)s.Length).ToList();
     166
     167        int maxLength = treeLengths.Max(t => t);
     168        int minLength = treeLengths.Min(t => t);
    168169
    169170        if (!treeLengthsTable.Rows.ContainsKey(treeLengthsTableRowName)) {
    170           treeLengthsTableRow = new DataRow(treeLengthsTableRowName, treeLengthsTableRowDesc, treeLengths);
     171          treeLengthsTableRow = new DataRow(treeLengthsTableRowName, treeLengthsTableRowDesc, treeLengths.Select(x => (double)x));
    171172          treeLengthsTable.Rows.Add(treeLengthsTableRow);
    172173        } else {
    173174          treeLengthsTableRow = treeLengthsTable.Rows[treeLengthsTableRowName];
    174           treeLengthsTableRow.Values.Replace(treeLengths);
     175          treeLengthsTableRow.Values.Replace(treeLengths.Select(x => (double)x));
    175176        }
    176177
     
    180181        treeLengthsTableRow.VisualProperties.ExactBins = false;
    181182
     183        int range = maxLength - minLength;
     184        if (range == 0) range = 1;
    182185        // the following trick should result in an integer intervalWidth of 1,2,4,...
    183         treeLengthsTableRow.VisualProperties.Bins = maxLength - minLength;
     186        treeLengthsTableRow.VisualProperties.Bins = range;
    184187
    185188        if (maxLength <= 25) // [0,25]
    186189          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0;
    187         else if (maxLength <= 100) // [26,100])
     190        else if (maxLength <= 100) // [26,100]
    188191          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 2.0;
    189         else if (maxLength <= 250) // [100,250]
     192        else if (maxLength <= 250) // [101,250]
    190193          treeLengthsTableRow.VisualProperties.ScaleFactor = 1.0 / 5.0;
    191194        else if (maxLength <= 500) // [251,500]
     
    205208          treeLengthsTable.VisualProperties.XAxisMaximumFixedValue = maximumAllowedTreeLength + 1;
    206209        treeLengthsTable.VisualProperties.XAxisTitle = xAxisTitle;
    207         // visual properties for the Y-axis
     210        //visual properties for the Y-axis
    208211        treeLengthsTable.VisualProperties.YAxisMinimumAuto = false;
    209212        treeLengthsTable.VisualProperties.YAxisMaximumAuto = false;
    210213        treeLengthsTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
    211         treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0);
     214        int maxFreq = solutions.GroupBy(s => s.Length).Max(g => g.Count());
     215        double yAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0) > maxFreq ? Math.Ceiling(solutions.Length / 2.0) : maxFreq;
     216        // round up yAxisMaximumFixedValue to the nearest multiple of 5, so it would look nice in the chart
     217        yAxisMaximumFixedValue = yAxisMaximumFixedValue + 5 - ((int)yAxisMaximumFixedValue % 5);
     218
     219        treeLengthsTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue;
    212220        treeLengthsTable.VisualProperties.YAxisTitle = yAxisTitle;
    213221
     
    229237          historyDataRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    230238          historyDataRow.VisualProperties.ExactBins = false;
    231           historyDataRow.VisualProperties.Bins = maxLength - minLength;
     239          historyDataRow.VisualProperties.Bins = range;
    232240          historyDataRow.VisualProperties.ScaleFactor = treeLengthsTableRow.VisualProperties.ScaleFactor;
    233241          var historyTable = new DataTable();
     
    246254          historyTable.VisualProperties.YAxisMaximumAuto = false;
    247255          historyTable.VisualProperties.YAxisMinimumFixedValue = 0.0;
    248           historyTable.VisualProperties.YAxisMaximumFixedValue = Math.Ceiling(solutions.Length / 2.0);
     256          historyTable.VisualProperties.YAxisMaximumFixedValue = yAxisMaximumFixedValue;
    249257          historyTable.VisualProperties.YAxisTitle = yAxisTitle;
    250258
Note: See TracChangeset for help on using the changeset viewer.