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:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP

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

    r15275 r15289  
    1919    private const string RESULTS_PARAMETER_NAME = "Results";
    2020    private const string INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME = "ZeroErrorIndividualsPerCase";
     21    private const string INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME = INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME + "History";
    2122
    2223    private const string RESULT_PARAMETER_NAME = "Zero Error Individuals Per Case";
    2324    private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population.";
    2425    private const string Y_AXIS_TITLE = "Count of zero error individuals";
    25     private const string X_AXIS_TITLE = "Case Index";
     26    private const string X_AXIS_TITLE = "Case Nr";
    2627    private const string ROW_NAME = "Cases";
     28    private const string HISTORY_TABLE_NAME = "Individual Zero Error history";
    2729
    2830    public IndividualZeroErrorAnalyzer() {
     
    3133        "The data table to store the count of individuals with zero error."));
    3234
     35      Parameters.Add(new ValueLookupParameter<DataTableHistory>(
     36        INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME,
     37        "The data table to store the history."));
     38
    3339      Parameters.Add(new LookupParameter<ResultCollection>(
    3440        RESULTS_PARAMETER_NAME,
     
    3844       IntegerVectorPushProblem.CaseQualitiesScopeParameterName,
    3945       "The quality of every single training case for each individual."));
     46
     47      Parameters.Add(new ValueParameter<BoolValue>(
     48        "StoreHistory",
     49        "True if the history of the analysis should be stored.",
     50        new BoolValue(false)));
     51
     52      Parameters.Add(new ValueParameter<IntValue>(
     53        "UpdateInterval",
     54        "The interval in which the analysis should be applied.",
     55        new IntValue(1)));
     56
     57      Parameters.Add(new ValueParameter<IntValue>(
     58        "UpdateCounter",
     59        "The value which counts how many times the operator was called since the last update.",
     60        new IntValue(0)));
     61
     62      IndividualZeroErrorParameter.Hidden = true;
     63      IndividualZeroErrorHistoryParameter.Hidden = true;
     64      ResultsParameter.Hidden = true;
     65      UpdateCounterParameter.Hidden = true;
    4066    }
    4167
     
    5177    public bool EnabledByDefault { get { return true; } }
    5278
     79    public ValueParameter<BoolValue> StoreHistoryParameter
     80    {
     81      get { return (ValueParameter<BoolValue>)Parameters["StoreHistory"]; }
     82    }
     83    public ValueParameter<IntValue> UpdateIntervalParameter
     84    {
     85      get { return (ValueParameter<IntValue>)Parameters["UpdateInterval"]; }
     86    }
     87    public ValueParameter<IntValue> UpdateCounterParameter
     88    {
     89      get { return (ValueParameter<IntValue>)Parameters["UpdateCounter"]; }
     90    }
     91
    5392    public ILookupParameter<DataTable> IndividualZeroErrorParameter
    5493    {
     
    5695    }
    5796
     97    public ValueLookupParameter<DataTableHistory> IndividualZeroErrorHistoryParameter
     98    {
     99      get { return (ValueLookupParameter<DataTableHistory>)Parameters[INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME]; }
     100    }
     101
    58102    public ILookupParameter<ResultCollection> ResultsParameter
    59103    {
     
    67111
    68112    public override IOperation Apply() {
     113      UpdateCounterParameter.Value.Value++;
     114      // the analyzer runs periodically, every 'updateInterval' times
     115      if (UpdateCounterParameter.Value.Value != UpdateIntervalParameter.Value.Value)
     116        return base.Apply();
     117
     118      UpdateCounterParameter.Value.Value = 0; // reset counter
     119
    69120      var caseQualitiesPerIndividual = CaseQualitiesParameter.ActualValue;
    70121      var caseCount = caseQualitiesPerIndividual[0].Length;
     
    80131            YAxisTitle = Y_AXIS_TITLE,
    81132            XAxisTitle = X_AXIS_TITLE,
    82             XAxisMinimumFixedValue = 0,
     133            YAxisMinimumFixedValue = 0,
     134            YAxisMaximumFixedValue = 1,
     135            YAxisMinimumAuto = false,
     136            SecondYAxisMaximumAuto = false,
     137            XAxisMinimumFixedValue = 1,
    83138            XAxisMaximumFixedValue = caseCount,
    84139            XAxisMaximumAuto = false,
     
    100155              StartIndexZero = true,
    101156              IsVisibleInLegend = false,
    102               ChartType = DataRowVisualProperties.DataRowChartType.Bars,
     157              ChartType = DataRowVisualProperties.DataRowChartType.Columns,
    103158            }
    104159        };
     
    107162      }
    108163
    109       var caseCountChanged = row.Values.Count != caseCount;
    110 
    111       if (caseCountChanged) {
    112         individualZeroErrorCounts.VisualProperties.XAxisMaximumFixedValue = caseCount;
    113         row.Values.Clear();
    114       }
     164      row.Values.Clear();
    115165
    116166      for (var i = 0; i < caseCount; i++) {
     
    124174        }
    125175
    126         if (caseCountChanged)
    127           row.Values.Add(count);
    128         else
    129           row.Values[i] = count;
     176        var relativeCount = count / (double)caseQualitiesPerIndividual.Length;
     177
     178        row.Values.Add(relativeCount);
     179      }
     180
     181      var storeHistory = StoreHistoryParameter.Value.Value;
     182
     183      if (storeHistory) {
     184        var history = IndividualZeroErrorHistoryParameter.ActualValue;
     185
     186        if (history == null) {
     187          history = new DataTableHistory();
     188          IndividualZeroErrorHistoryParameter.ActualValue = history;
     189        }
     190
     191        history.Add((DataTable)individualZeroErrorCounts.Clone());
     192
     193        if (!results.ContainsKey(HISTORY_TABLE_NAME)) {
     194          results.Add(new Result(HISTORY_TABLE_NAME, history));
     195        } else {
     196          results[HISTORY_TABLE_NAME].Value = history;
     197        }
    130198      }
    131199
  • 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
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs

    r15273 r15289  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer {
    22  using System;
     3  using System.Collections.Generic;
    34  using System.Linq;
    45
     
    1415  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    1516  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
     17  using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding;
    1618  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1719  using HeuristicLab.Problems.ProgramSynthesis.Push.Individual;
    18   using HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random;
    1920
    2021  /// <summary>
     
    2425  [StorableClass]
    2526  public class PushExpressionFrequencyAnalyzer : SingleSuccessorOperator, IPushExpressionAnalyzer {
    26     private readonly SeededRandomPool randomPool = new SeededRandomPool();
    2727
    2828    private const string PUSH_CONFIGURATION_PARAMETER_NAME = "PushConfiguration";
     
    4040      Parameters.Add(new LookupParameter<IReadOnlyPushConfiguration>(PUSH_CONFIGURATION_PARAMETER_NAME, "The current specified push configuration."));
    4141      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>(INTEGER_VECTOR_PARAMETER_NAME, "The integer vectors to analyze."));
     42      Parameters.Add(new ScopeTreeLookupParameter<PlushVector>("Plush", "The plush vectors to analyze."));
    4243      Parameters.Add(new LookupParameter<DataTable>(EXPRESSION_FREQUENCIES_PARAMETER_NAME, "The data table to store the instruction frequencies."));
    4344      Parameters.Add(new LookupParameter<ResultCollection>(RESULTS_PARAMETER_NAME, "The result collection where the symbol frequencies should be stored."));
     
    6061    {
    6162      get { return (ILookupParameter<IReadOnlyPushConfiguration>)Parameters[PUSH_CONFIGURATION_PARAMETER_NAME]; }
     63    }
     64
     65    public IScopeTreeLookupParameter<PlushVector> PlushVectorParameter
     66    {
     67      get { return (IScopeTreeLookupParameter<PlushVector>)Parameters["Plush"]; }
    6268    }
    6369
     
    95101    public override IOperation Apply() {
    96102      var config = PushConfigurationParameter.ActualValue;
    97       var integerVectors = IntegerVectorParameter.ActualValue;
    98103
    99       randomPool.Seed = config.Seed;
     104      IReadOnlyList<PushProgram> pushPrograms = null;
    100105
    101       var pushPrograms = integerVectors.Select(iv => {
    102         var random = randomPool.ResetAndAllocate();
    103         var program = iv.ToPushProgram(config, random);
    104         randomPool.Free(random);
    105 
    106         return program;
    107       });
     106      if (IntegerVectorParameter.ActualValue.Length > 0) {
     107        pushPrograms = IntegerVectorParameter.ActualValue.Select(iv => iv.ToPushProgram(config)).ToList();
     108      } else if (PlushVectorParameter.ActualValue.Length > 0) {
     109        pushPrograms = PlushVectorParameter.ActualValue.Select(pv => pv.PushProgram).ToList();
     110      } else {
     111        // nothing to do
     112        return base.Apply();
     113      }
    108114
    109115      var results = ResultsParameter.ActualValue;
     
    136142          group => group.Count());
    137143
    138       var totalNumberofExpressions = Math.Max(1.0, expressionFrequencies.Values.Sum());
     144      var totalNumberOfExpressions = Math.Max(1.0, expressionFrequencies.Values.Sum());
    139145
    140146      // all rows must have the same number of values so we can just take the first
     
    152158        }
    153159
    154         frequencies.Rows[pair.Key].Values.Add(Math.Round(pair.Value / totalNumberofExpressions, 3));
     160        frequencies.Rows[pair.Key].Values.Add(Math.Round(pair.Value / totalNumberOfExpressions, 3));
    155161      }
    156162
Note: See TracChangeset for help on using the changeset viewer.