Changeset 15289 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer
- Timestamp:
- 07/26/17 19:34:13 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP
-
Property
svn:ignore
set to
*.user
-
Property
svn:ignore
set to
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/IndividualZeroErrorAnalyzer.cs
r15275 r15289 19 19 private const string RESULTS_PARAMETER_NAME = "Results"; 20 20 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"; 21 22 22 23 private const string RESULT_PARAMETER_NAME = "Zero Error Individuals Per Case"; 23 24 private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population."; 24 25 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"; 26 27 private const string ROW_NAME = "Cases"; 28 private const string HISTORY_TABLE_NAME = "Individual Zero Error history"; 27 29 28 30 public IndividualZeroErrorAnalyzer() { … … 31 33 "The data table to store the count of individuals with zero error.")); 32 34 35 Parameters.Add(new ValueLookupParameter<DataTableHistory>( 36 INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME, 37 "The data table to store the history.")); 38 33 39 Parameters.Add(new LookupParameter<ResultCollection>( 34 40 RESULTS_PARAMETER_NAME, … … 38 44 IntegerVectorPushProblem.CaseQualitiesScopeParameterName, 39 45 "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; 40 66 } 41 67 … … 51 77 public bool EnabledByDefault { get { return true; } } 52 78 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 53 92 public ILookupParameter<DataTable> IndividualZeroErrorParameter 54 93 { … … 56 95 } 57 96 97 public ValueLookupParameter<DataTableHistory> IndividualZeroErrorHistoryParameter 98 { 99 get { return (ValueLookupParameter<DataTableHistory>)Parameters[INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME]; } 100 } 101 58 102 public ILookupParameter<ResultCollection> ResultsParameter 59 103 { … … 67 111 68 112 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 69 120 var caseQualitiesPerIndividual = CaseQualitiesParameter.ActualValue; 70 121 var caseCount = caseQualitiesPerIndividual[0].Length; … … 80 131 YAxisTitle = Y_AXIS_TITLE, 81 132 XAxisTitle = X_AXIS_TITLE, 82 XAxisMinimumFixedValue = 0, 133 YAxisMinimumFixedValue = 0, 134 YAxisMaximumFixedValue = 1, 135 YAxisMinimumAuto = false, 136 SecondYAxisMaximumAuto = false, 137 XAxisMinimumFixedValue = 1, 83 138 XAxisMaximumFixedValue = caseCount, 84 139 XAxisMaximumAuto = false, … … 100 155 StartIndexZero = true, 101 156 IsVisibleInLegend = false, 102 ChartType = DataRowVisualProperties.DataRowChartType. Bars,157 ChartType = DataRowVisualProperties.DataRowChartType.Columns, 103 158 } 104 159 }; … … 107 162 } 108 163 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(); 115 165 116 166 for (var i = 0; i < caseCount; i++) { … … 124 174 } 125 175 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 } 130 198 } 131 199 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/IndividualZeroErrorDistributionAnalyzer.cs
r15275 r15289 20 20 private const string RESULTS_PARAMETER_NAME = "Results"; 21 21 private const string INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME = "ZeroErrorIndividualsPerCaseDistribution"; 22 private const string INDIVIDUAL_ZERO_ERROR_HISTORY_PARAMETER_NAME = "ZeroErrorIndividualsPerCaseDistributionHistory"; 22 23 24 private const string HISTORY_TABLE_NAME = "Individual Zero Error Distribution History"; 23 25 private const string RESULT_PARAMETER_NAME = "Zero Error Individual Per Case Distribution"; 24 26 private const string RESULT_PARAMETER_DESCRIPTION = "Relative frequency of instructions aggregated over the whole population."; 25 27 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"; 27 29 private const string ROW_NAME = "Cases"; 28 30 … … 31 33 INDIVIDUAL_ZERO_ERROR_PARAMETER_NAME, 32 34 "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.")); 33 39 34 40 Parameters.Add(new LookupParameter<ResultCollection>( … … 39 45 IntegerVectorPushProblem.CaseQualitiesScopeParameterName, 40 46 "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; 41 67 } 42 68 43 [StorableConstructor Attribute]69 [StorableConstructor] 44 70 public IndividualZeroErrorDistributionAnalyzer(bool deserializing) : base(deserializing) { } 45 71 … … 52 78 public bool EnabledByDefault { get { return true; } } 53 79 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 54 93 public ILookupParameter<DataTable> IndividualZeroErrorDistributionParameter 55 94 { 56 95 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]; } 57 101 } 58 102 … … 68 112 69 113 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 70 121 var caseQualitiesPerIndividual = CaseQualitiesParameter.ActualValue; 71 122 var individualCount = caseQualitiesPerIndividual.Length; … … 82 133 YAxisTitle = Y_AXIS_TITLE, 83 134 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, 86 142 XAxisMinimumAuto = false, 87 143 } … … 101 157 StartIndexZero = true, 102 158 IsVisibleInLegend = false, 103 ChartType = DataRowVisualProperties.DataRowChartType. Histogram,159 ChartType = DataRowVisualProperties.DataRowChartType.Columns, 104 160 } 105 161 }; … … 108 164 } 109 165 110 var caseCountChanged = row.Values.Count != caseCount;166 row.Values.Clear(); 111 167 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); 114 173 } 115 174 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; 122 176 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; 127 179 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 } 132 192 } 133 193 -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/PushExpressionFrequencyAnalyzer.cs
r15273 r15289 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Analyzer { 2 2 using System; 3 using System.Collections.Generic; 3 4 using System.Linq; 4 5 … … 14 15 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 15 16 using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration; 17 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 16 18 using HeuristicLab.Problems.ProgramSynthesis.Push.Expressions; 17 19 using HeuristicLab.Problems.ProgramSynthesis.Push.Individual; 18 using HeuristicLab.Problems.ProgramSynthesis.Push.ObjectPools.Random;19 20 20 21 /// <summary> … … 24 25 [StorableClass] 25 26 public class PushExpressionFrequencyAnalyzer : SingleSuccessorOperator, IPushExpressionAnalyzer { 26 private readonly SeededRandomPool randomPool = new SeededRandomPool();27 27 28 28 private const string PUSH_CONFIGURATION_PARAMETER_NAME = "PushConfiguration"; … … 40 40 Parameters.Add(new LookupParameter<IReadOnlyPushConfiguration>(PUSH_CONFIGURATION_PARAMETER_NAME, "The current specified push configuration.")); 41 41 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.")); 42 43 Parameters.Add(new LookupParameter<DataTable>(EXPRESSION_FREQUENCIES_PARAMETER_NAME, "The data table to store the instruction frequencies.")); 43 44 Parameters.Add(new LookupParameter<ResultCollection>(RESULTS_PARAMETER_NAME, "The result collection where the symbol frequencies should be stored.")); … … 60 61 { 61 62 get { return (ILookupParameter<IReadOnlyPushConfiguration>)Parameters[PUSH_CONFIGURATION_PARAMETER_NAME]; } 63 } 64 65 public IScopeTreeLookupParameter<PlushVector> PlushVectorParameter 66 { 67 get { return (IScopeTreeLookupParameter<PlushVector>)Parameters["Plush"]; } 62 68 } 63 69 … … 95 101 public override IOperation Apply() { 96 102 var config = PushConfigurationParameter.ActualValue; 97 var integerVectors = IntegerVectorParameter.ActualValue;98 103 99 randomPool.Seed = config.Seed;104 IReadOnlyList<PushProgram> pushPrograms = null; 100 105 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 } 108 114 109 115 var results = ResultsParameter.ActualValue; … … 136 142 group => group.Count()); 137 143 138 var totalNumber ofExpressions = Math.Max(1.0, expressionFrequencies.Values.Sum());144 var totalNumberOfExpressions = Math.Max(1.0, expressionFrequencies.Values.Sum()); 139 145 140 146 // all rows must have the same number of values so we can just take the first … … 152 158 } 153 159 154 frequencies.Rows[pair.Key].Values.Add(Math.Round(pair.Value / totalNumber ofExpressions, 3));160 frequencies.Rows[pair.Key].Values.Add(Math.Round(pair.Value / totalNumberOfExpressions, 3)); 155 161 } 156 162
Note: See TracChangeset
for help on using the changeset viewer.