Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/17 19:34:13 (7 years ago)
Author:
pkimmesw
Message:

#2665 Fixed analyzer, fixed Plush encoding + operators, adpated print evaluation according to McPhee

Location:
branches/PushGP/HeuristicLab.PushGP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP

    • Property svn:ignore set to
      *.user
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/IndividualZeroErrorDistributionAnalyzer.cs

    r15275 r15289  
    2020    private const string RESULTS_PARAMETER_NAME = "Results";
    2121    private const string INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME = "ZeroErrorIndividualsPerCaseDistribution";
     22    private const string INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME = "ZeroErrorIndividualsPerCaseDistributionHistory";
    2223
     24    private const string HISTORY_TABLE_NAME = "Individual Zero Error Distribution History";
    2325    private const string RESULT_PARAMETER_NAME = "Zero Error Individual Per Case Distribution";
    2426    private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population.";
    2527    private const string Y_AXIS_TITLE = "Number of zero error cases";
    26     private const string X_AXIS_TITLE = "Number of individuals";
     28    private const string X_AXIS_TITLE = "Individuals Nr";
    2729    private const string ROW_NAME = "Cases";
    2830
     
    3133        INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME,
    3234        "The data table to store the count of individuals with zero error."));
     35
     36      Parameters.Add(new ValueLookupParameter<DataTableHistory>(
     37        INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME,
     38        "The data table to store the history."));
    3339
    3440      Parameters.Add(new LookupParameter<ResultCollection>(
     
    3945       IntegerVectorPushProblem.CaseQualitiesScopeParameterName,
    4046       "The quality of every single training case for each individual."));
     47
     48      Parameters.Add(new ValueParameter<BoolValue>(
     49        "StoreHistory",
     50        "True if the history of the analysis should be stored.",
     51        new BoolValue(false)));
     52
     53      Parameters.Add(new ValueParameter<IntValue>(
     54        "UpdateInterval",
     55        "The interval in which the analysis should be applied.",
     56        new IntValue(1)));
     57
     58      Parameters.Add(new ValueParameter<IntValue>(
     59        "UpdateCounter",
     60        "The value which counts how many times the operator was called since the last update.",
     61        new IntValue(0)));
     62
     63      IndividualZeroErrorDistributionParameter.Hidden = true;
     64      IndividualZeroErrorDistributionHistoryParameter.Hidden = true;
     65      ResultsParameter.Hidden = true;
     66      UpdateCounterParameter.Hidden = true;
    4167    }
    4268
    43     [StorableConstructorAttribute]
     69    [StorableConstructor]
    4470    public IndividualZeroErrorDistributionAnalyzer(bool deserializing) : base(deserializing) { }
    4571
     
    5278    public bool EnabledByDefault { get { return true; } }
    5379
     80    public ValueParameter<BoolValue> StoreHistoryParameter
     81    {
     82      get { return (ValueParameter<BoolValue>)Parameters["StoreHistory"]; }
     83    }
     84    public ValueParameter<IntValue> UpdateIntervalParameter
     85    {
     86      get { return (ValueParameter<IntValue>)Parameters["UpdateInterval"]; }
     87    }
     88    public ValueParameter<IntValue> UpdateCounterParameter
     89    {
     90      get { return (ValueParameter<IntValue>)Parameters["UpdateCounter"]; }
     91    }
     92
    5493    public ILookupParameter<DataTable> IndividualZeroErrorDistributionParameter
    5594    {
    5695      get { return (ILookupParameter<DataTable>)Parameters[INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME]; }
     96    }
     97
     98    public ValueLookupParameter<DataTableHistory> IndividualZeroErrorDistributionHistoryParameter
     99    {
     100      get { return (ValueLookupParameter<DataTableHistory>)Parameters[INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME]; }
    57101    }
    58102
     
    68112
    69113    public override IOperation Apply() {
     114      UpdateCounterParameter.Value.Value++;
     115      // the analyzer runs periodically, every 'updateInterval' times
     116      if (UpdateCounterParameter.Value.Value != UpdateIntervalParameter.Value.Value)
     117        return base.Apply();
     118
     119      UpdateCounterParameter.Value.Value = 0; // reset counter
     120
    70121      var caseQualitiesPerIndividual = CaseQualitiesParameter.ActualValue;
    71122      var individualCount = caseQualitiesPerIndividual.Length;
     
    82133            YAxisTitle = Y_AXIS_TITLE,
    83134            XAxisTitle = X_AXIS_TITLE,
    84             XAxisMinimumFixedValue = 0,
    85             XAxisMaximumAuto = true,
     135            YAxisMaximumFixedValue = 1,
     136            YAxisMinimumFixedValue = 0,
     137            YAxisMaximumAuto = false,
     138            YAxisMinimumAuto = false,
     139            XAxisMinimumFixedValue = 1,
     140            XAxisMaximumFixedValue = individualCount,
     141            XAxisMaximumAuto = false,
    86142            XAxisMinimumAuto = false,
    87143          }
     
    101157              StartIndexZero = true,
    102158              IsVisibleInLegend = false,
    103               ChartType = DataRowVisualProperties.DataRowChartType.Histogram,
     159              ChartType = DataRowVisualProperties.DataRowChartType.Columns,
    104160            }
    105161        };
     
    108164      }
    109165
    110       var caseCountChanged = row.Values.Count != caseCount;
     166      row.Values.Clear();
    111167
    112       if (caseCountChanged) {
    113         row.Values.Clear();
     168      for (var i = 0; i < caseQualitiesPerIndividual.Length; i++) {
     169        var count = caseQualitiesPerIndividual[i].Count(q => q == 0.0);
     170        var ratio = count / (double)caseCount;
     171
     172        row.Values.Add(ratio);
    114173      }
    115174
    116       // key represents the number of cases with zero error
    117       // value represents the number of individuals with key cases with zero error
    118       var distribution = caseQualitiesPerIndividual
    119               .Select(individual => individual.Count(x => x == 0.0))
    120               .GroupBy(x => x)
    121               .ToDictionary(x => x.Key, x => x.Count());
     175      var storeHistory = StoreHistoryParameter.Value.Value;
    122176
    123       for (var i = 0; i < caseCount; i++) {
    124         int count;
    125         distribution.TryGetValue(i, out count);
    126         var x = count / (double)individualCount;
     177      if (storeHistory) {
     178        var history = IndividualZeroErrorDistributionHistoryParameter.ActualValue;
    127179
    128         if (caseCountChanged)
    129           row.Values.Add(x);
    130         else
    131           row.Values[i] = x;
     180        if (history == null) {
     181          history = new DataTableHistory();
     182          IndividualZeroErrorDistributionHistoryParameter.ActualValue = history;
     183        }
     184
     185        history.Add((DataTable)individualZeroErrorDistribution.Clone());
     186
     187        if (!results.ContainsKey(HISTORY_TABLE_NAME)) {
     188          results.Add(new Result(HISTORY_TABLE_NAME, history));
     189        } else {
     190          results[HISTORY_TABLE_NAME].Value = history;
     191        }
    132192      }
    133193
Note: See TracChangeset for help on using the changeset viewer.