Changeset 15273 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs
- Timestamp:
- 07/19/17 12:55:58 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs
r15189 r15273 12 12 using HeuristicLab.Parameters; 13 13 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 14 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 14 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 15 16 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 16 17 using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; 18 using HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random; 17 19 18 20 /// <summary> … … 22 24 [StorableClass] 23 25 public class PushExpressionFrequencyAnalyzer : SingleSuccessorOperator, IPushExpressionAnalyzer { 26 private readonly SeededRandomPool randomPool = new SeededRandomPool(); 24 27 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"; 30 38 31 39 public PushExpressionFrequencyAnalyzer() { 32 Parameters.Add(new LookupParameter<IReadOnlyPushConfiguration>(P ushConfigurationParameterName, "The current specified push configuration."));33 Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>(I ntegerVectorParameterName, "The integer vectors to analyze."));34 Parameters.Add(new LookupParameter<DataTable>(E xpressionFrequenciesParameterName, "The data table to store the instruction frequencies."));35 Parameters.Add(new LookupParameter<ResultCollection>(R esultsParameterName, "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.")); 36 44 37 Parameters.Add(new FixedValueParameter<BoolValue>(A ggregateStackTypesParameterName, "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))); 38 46 } 39 47 … … 51 59 public ILookupParameter<IReadOnlyPushConfiguration> PushConfigurationParameter 52 60 { 53 get { return (ILookupParameter<IReadOnlyPushConfiguration>)Parameters[P ushConfigurationParameterName]; }61 get { return (ILookupParameter<IReadOnlyPushConfiguration>)Parameters[PUSH_CONFIGURATION_PARAMETER_NAME]; } 54 62 } 55 63 56 64 public IScopeTreeLookupParameter<IntegerVector> IntegerVectorParameter 57 65 { 58 get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters[I ntegerVectorParameterName]; }66 get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters[INTEGER_VECTOR_PARAMETER_NAME]; } 59 67 } 60 68 61 69 public ILookupParameter<DataTable> ExpressionFrequenciesParameter 62 70 { 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]; } 64 77 } 65 78 66 79 public ILookupParameter<ResultCollection> ResultsParameter 67 80 { 68 get { return (ILookupParameter<ResultCollection>)Parameters[R esultsParameterName]; }81 get { return (ILookupParameter<ResultCollection>)Parameters[RESULTS_PARAMETER_NAME]; } 69 82 } 70 83 71 84 public IValueParameter<BoolValue> AggregateStackTypesParameter 72 85 { 73 get { return (IValueParameter<BoolValue>)Parameters[A ggregateStackTypesParameterName]; }86 get { return (IValueParameter<BoolValue>)Parameters[AGGREGATE_STACK_TYPES_PARAMETER_NAME]; } 74 87 } 75 88 … … 80 93 } 81 94 82 83 95 public override IOperation Apply() { 84 96 var config = PushConfigurationParameter.ActualValue; 85 97 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 }); 87 108 88 109 var results = ResultsParameter.ActualValue; … … 91 112 if (frequencies == null) { 92 113 frequencies = new DataTable( 93 "Instruction frequencies",94 "Relative frequency of instructions aggregated over the whole population.") {114 RESULT_PARAMETER_NAME, 115 RESULT_PARAMETER_DESCRIPTION) { 95 116 VisualProperties = { 96 YAxisTitle = "Relative Instruction Frequency"117 YAxisTitle = Y_AXIS_TITLE 97 118 } 98 119 }; 99 120 100 121 ExpressionFrequenciesParameter.ActualValue = frequencies; 101 results.Add(new Result( "Instruction frequencies", frequencies));122 results.Add(new Result(RESULT_PARAMETER_NAME, frequencies)); 102 123 } 103 124 … … 110 131 111 132 var expressionFrequencies = allExpressions 112 .GroupBy(x => AggregateStackTypes 113 ? x.Attribute.StackType.ToString() 114 : x.Attribute.Name) 133 .GroupBy(x => GetGroupName(x.Attribute, AggregateStackTypes)) 115 134 .ToDictionary( 116 135 group => group.Key, … … 126 145 var row = new DataRow(pair.Key, string.Empty, Enumerable.Repeat(0.0, numberOfValues)) { 127 146 VisualProperties = { 128 StartIndexZero = true 147 StartIndexZero = true, 129 148 } 130 149 }; … … 142 161 return base.Apply(); 143 162 } 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 } 144 173 } 145 174 }
Note: See TracChangeset
for help on using the changeset viewer.