Changeset 15289 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Analyzer/IndividualZeroErrorDistributionAnalyzer.cs
- Timestamp:
- 07/26/17 19:34:13 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 2 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/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
Note: See TracChangeset
for help on using the changeset viewer.