Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/19/17 12:55:58 (7 years ago)
Author:
pkimmesw
Message:

#2665 Started Plush Encoding, Added Zero Error Individual Count Analyzer

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs

    r15189 r15273  
    1212  using HeuristicLab.Parameters;
    1313  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     14  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    1415  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
    1516  using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions;
    1617  using HeuristicLab.Problems.ProgramSynthesis.Push.Individual;
     18  using HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random;
    1719
    1820  /// <summary>
     
    2224  [StorableClass]
    2325  public class PushExpressionFrequencyAnalyzer : SingleSuccessorOperator, IPushExpressionAnalyzer {
     26    private readonly SeededRandomPool randomPool = new SeededRandomPool();
    2427
    25     private const string PushConfigurationParameterName = "PushConfiguration";
    26     private const string IntegerVectorParameterName = "IntegerVector";
    27     private const string ResultsParameterName = "Results";
    28     private const string ExpressionFrequenciesParameterName = "InstructionFrequencies";
    29     private const string AggregateStackTypesParameterName = "Aggregate stack types";
     28    private const string PUSH_CONFIGURATION_PARAMETER_NAME = "PushConfiguration";
     29    private const string INTEGER_VECTOR_PARAMETER_NAME = "IntegerVector";
     30    private const string RESULTS_PARAMETER_NAME = "Results";
     31    private const string EXPRESSION_FREQUENCIES_PARAMETER_NAME = "InstructionFrequencies";
     32    private const string AGGREGATE_STACK_TYPES_PARAMETER_NAME = "Aggregate stack types";
     33    private const string IN_EXPRESSION_GROUP_NAME = "IN";
     34    private const string RANDOM_PARAMETER_NAME = "Random";
     35    private const string RESULT_PARAMETER_NAME = "Instruction frequencies";
     36    private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population.";
     37    private const string Y_AXIS_TITLE = "Relative Instruction Frequency";
    3038
    3139    public PushExpressionFrequencyAnalyzer() {
    32       Parameters.Add(new LookupParameter<IReadOnlyPushConfiguration>(PushConfigurationParameterName, "The current specified push configuration."));
    33       Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>(IntegerVectorParameterName, "The integer vectors to analyze."));
    34       Parameters.Add(new LookupParameter<DataTable>(ExpressionFrequenciesParameterName, "The data table to store the instruction frequencies."));
    35       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the symbol frequencies should be stored."));
     40      Parameters.Add(new LookupParameter<IReadOnlyPushConfiguration>(PUSH_CONFIGURATION_PARAMETER_NAME, "The current specified push configuration."));
     41      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>(INTEGER_VECTOR_PARAMETER_NAME, "The integer vectors to analyze."));
     42      Parameters.Add(new LookupParameter<DataTable>(EXPRESSION_FREQUENCIES_PARAMETER_NAME, "The data table to store the instruction frequencies."));
     43      Parameters.Add(new LookupParameter<ResultCollection>(RESULTS_PARAMETER_NAME, "The result collection where the symbol frequencies should be stored."));
    3644
    37       Parameters.Add(new FixedValueParameter<BoolValue>(AggregateStackTypesParameterName, "Determines if expressions should be aggregated by their primary stack type.", new BoolValue(true)));
     45      Parameters.Add(new FixedValueParameter<BoolValue>(AGGREGATE_STACK_TYPES_PARAMETER_NAME, "Determines if expressions should be aggregated by their primary stack type.", new BoolValue(true)));
    3846    }
    3947
     
    5159    public ILookupParameter<IReadOnlyPushConfiguration> PushConfigurationParameter
    5260    {
    53       get { return (ILookupParameter<IReadOnlyPushConfiguration>)Parameters[PushConfigurationParameterName]; }
     61      get { return (ILookupParameter<IReadOnlyPushConfiguration>)Parameters[PUSH_CONFIGURATION_PARAMETER_NAME]; }
    5462    }
    5563
    5664    public IScopeTreeLookupParameter<IntegerVector> IntegerVectorParameter
    5765    {
    58       get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters[IntegerVectorParameterName]; }
     66      get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters[INTEGER_VECTOR_PARAMETER_NAME]; }
    5967    }
    6068
    6169    public ILookupParameter<DataTable> ExpressionFrequenciesParameter
    6270    {
    63       get { return (ILookupParameter<DataTable>)Parameters[ExpressionFrequenciesParameterName]; }
     71      get { return (ILookupParameter<DataTable>)Parameters[EXPRESSION_FREQUENCIES_PARAMETER_NAME]; }
     72    }
     73
     74    public ILookupParameter<IRandom> RandomParameter
     75    {
     76      get { return (ILookupParameter<IRandom>)Parameters[RANDOM_PARAMETER_NAME]; }
    6477    }
    6578
    6679    public ILookupParameter<ResultCollection> ResultsParameter
    6780    {
    68       get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
     81      get { return (ILookupParameter<ResultCollection>)Parameters[RESULTS_PARAMETER_NAME]; }
    6982    }
    7083
    7184    public IValueParameter<BoolValue> AggregateStackTypesParameter
    7285    {
    73       get { return (IValueParameter<BoolValue>)Parameters[AggregateStackTypesParameterName]; }
     86      get { return (IValueParameter<BoolValue>)Parameters[AGGREGATE_STACK_TYPES_PARAMETER_NAME]; }
    7487    }
    7588
     
    8093    }
    8194
    82 
    8395    public override IOperation Apply() {
    8496      var config = PushConfigurationParameter.ActualValue;
    8597      var integerVectors = IntegerVectorParameter.ActualValue;
    86       var pushPrograms = integerVectors.Select(iv => iv.ToPushProgram(config));
     98
     99      randomPool.Seed = config.Seed;
     100
     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      });
    87108
    88109      var results = ResultsParameter.ActualValue;
     
    91112      if (frequencies == null) {
    92113        frequencies = new DataTable(
    93           "Instruction frequencies",
    94           "Relative frequency of instructions aggregated over the whole population.") {
     114          RESULT_PARAMETER_NAME,
     115          RESULT_PARAMETER_DESCRIPTION) {
    95116          VisualProperties = {
    96             YAxisTitle = "Relative Instruction Frequency"
     117            YAxisTitle = Y_AXIS_TITLE
    97118          }
    98119        };
    99120
    100121        ExpressionFrequenciesParameter.ActualValue = frequencies;
    101         results.Add(new Result("Instruction frequencies", frequencies));
     122        results.Add(new Result(RESULT_PARAMETER_NAME, frequencies));
    102123      }
    103124
     
    110131
    111132      var expressionFrequencies = allExpressions
    112         .GroupBy(x => AggregateStackTypes
    113           ? x.Attribute.StackType.ToString()
    114           : x.Attribute.Name)
     133        .GroupBy(x => GetGroupName(x.Attribute, AggregateStackTypes))
    115134        .ToDictionary(
    116135          group => group.Key,
     
    126145          var row = new DataRow(pair.Key, string.Empty, Enumerable.Repeat(0.0, numberOfValues)) {
    127146            VisualProperties = {
    128               StartIndexZero = true
     147              StartIndexZero = true,
    129148            }
    130149          };
     
    142161      return base.Apply();
    143162    }
     163
     164    private string GetGroupName(PushExpressionAttribute attribute, bool aggregateStackTypes) {
     165      if (aggregateStackTypes) {
     166        return attribute.IsInExpression
     167         ? IN_EXPRESSION_GROUP_NAME
     168         : attribute.StackType.ToString();
     169      }
     170
     171      return attribute.Name;
     172    }
    144173  }
    145174}
Note: See TracChangeset for help on using the changeset viewer.