Changeset 14231
- Timestamp:
- 08/03/16 18:26:24 (8 years ago)
- Location:
- branches/HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/OSGAPredictionCountsAnalyzer.cs
r14104 r14231 44 44 45 45 ResultCollection predictionResults; 46 DataTable rejectedStatsTable, totalStatsTable ;46 DataTable rejectedStatsTable, totalStatsTable, rejectedStatsPerGenerationTable, nonRejectedStatsPerGenerationTable; 47 47 if (!ResultCollection.ContainsKey("OS Prediction")) { 48 48 predictionResults = new ResultCollection(); … … 57 57 } 58 58 predictionResults.Add(new Result("Total Stats", totalStatsTable)); 59 59 rejectedStatsPerGenerationTable = new DataTable("Rejected Per Generation"); 60 nonRejectedStatsPerGenerationTable = new DataTable("Non Rejected Stats per Generation"); 61 foreach (var rowName in rejectedStats.RowNames) { 62 rejectedStatsPerGenerationTable.Rows.Add(new DataRow(rowName) { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Line, LineWidth = 1 } }); 63 rejectedStatsPerGenerationTable.Rows[rowName].Values.Add(0d); 64 nonRejectedStatsPerGenerationTable.Rows.Add(new DataRow(rowName) { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Line, LineWidth = 1 } }); 65 nonRejectedStatsPerGenerationTable.Rows[rowName].Values.Add(0d); 66 } 67 predictionResults.Add(new Result("Rejected Stats Per Generation", rejectedStatsPerGenerationTable)); 68 predictionResults.Add(new Result("Non Rejected Stats Per Generation", nonRejectedStatsPerGenerationTable)); 60 69 ResultCollection.Add(new Result("OS Prediction", predictionResults)); 61 70 } else { … … 63 72 rejectedStatsTable = (DataTable)predictionResults["Rejected Stats"].Value; 64 73 totalStatsTable = (DataTable)predictionResults["Total Stats"].Value; 74 rejectedStatsPerGenerationTable = (DataTable)predictionResults["Rejected Stats Per Generation"].Value; 75 nonRejectedStatsPerGenerationTable = (DataTable)predictionResults["Non Rejected Stats Per Generation"].Value; 65 76 } 66 77 67 78 int i = 0; 68 79 foreach (var rowName in rejectedStats.RowNames) { 69 // add a padding zero below to prevent columns from being cut off to the left80 // pad values with a 0 on each side to prevent clipping 70 81 rejectedStatsTable.Rows[rowName].Values.Replace(new[] { 0d }.Concat(Enumerable.Range(0, rejectedStats.Columns).Select(j => (double)rejectedStats[i, j])).Concat(new[] { 0d })); 71 82 ++i; … … 74 85 foreach (var rowName in totalStats.RowNames) { 75 86 totalStatsTable.Rows[rowName].Values.Replace(new[] { 0d }.Concat(Enumerable.Range(0, totalStats.Columns).Select(j => (double)totalStats[i, j])).Concat(new[] { 0d })); 87 var row = rejectedStatsPerGenerationTable.Rows[rowName]; 88 var sum = row.Values.Sum(); 89 row.Values.Add(totalStats[i, 0] - sum); 90 row = nonRejectedStatsPerGenerationTable.Rows[rowName]; 91 sum = row.Values.Sum(); 92 row.Values.Add(totalStats[i, 1] - sum); 76 93 ++i; 77 94 } -
branches/HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/SymbolicRegressionSingleObjectiveOSGAEvaluator.cs
r14184 r14231 38 38 private const string RelativeFitnessEvaluationIntervalSizeParameterName = "RelativeFitnessEvaluationIntervalSize"; 39 39 private const string ResultCollectionParameterName = "Results"; 40 private const string AggregateStatisticsParameterName = "AggregateStatistics"; 40 41 41 42 #region parameters … … 43 44 get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; } 44 45 } 45 46 public IValueParameter<BoolValue> AggregateStatisticsParameter { 47 get { return (IValueParameter<BoolValue>)Parameters[AggregateStatisticsParameterName]; } 48 } 46 49 public IValueParameter<IntMatrix> RejectedStatsParameter { 47 50 get { return (IValueParameter<IntMatrix>)Parameters["RejectedStats"]; } … … 96 99 Parameters.Add(new ValueParameter<IntMatrix>("RejectedStats", new IntMatrix())); 97 100 Parameters.Add(new ValueParameter<IntMatrix>("TotalStats", new IntMatrix())); 101 Parameters.Add(new ValueParameter<BoolValue>(AggregateStatisticsParameterName, new BoolValue(false))); 98 102 } 99 103 … … 184 188 var targetValuesEnumerator = targetValues.GetEnumerator(); 185 189 var estimatedValuesEnumerator = estimatedValues.GetEnumerator(); 186 187 var i = 0;188 190 var trainingPartitionSize = problemData.TrainingPartition.Size; 189 191 var interval = (int)Math.Floor(trainingPartitionSize * RelativeFitnessEvaluationIntervalSize); 190 while (targetValuesEnumerator.MoveNext() && estimatedValuesEnumerator.MoveNext()) { 191 pearsonRCalculator.Add(targetValuesEnumerator.Current, estimatedValuesEnumerator.Current); 192 ++i; 193 if (i % interval == 0 || i == trainingPartitionSize) { 194 var q = pearsonRCalculator.ErrorState != OnlineCalculatorError.None ? double.NaN : pearsonRCalculator.R; 195 var quality = q * q; 196 if (!(quality > threshold)) 197 return quality; 198 } 192 193 var aggregateStatistics = AggregateStatisticsParameter.Value.Value; 194 var i = 0; 195 if (aggregateStatistics) { 196 var trainingEnd = problemData.TrainingPartition.End; 197 var qualityPerInterval = new List<double>(); 198 while (targetValuesEnumerator.MoveNext() && estimatedValuesEnumerator.MoveNext()) { 199 pearsonRCalculator.Add(targetValuesEnumerator.Current, estimatedValuesEnumerator.Current); 200 ++i; 201 if (i % interval == 0 || i == trainingPartitionSize) { 202 var q = pearsonRCalculator.ErrorState != OnlineCalculatorError.None ? double.NaN : pearsonRCalculator.R; 203 qualityPerInterval.Add(q * q); 204 } 205 } 206 var r = pearsonRCalculator.ErrorState != OnlineCalculatorError.None ? double.NaN : pearsonRCalculator.R; 207 var actualQuality = r * r; 208 209 bool predictedRejected = false; 210 211 i = 0; 212 double quality = actualQuality; 213 foreach (var q in qualityPerInterval) { 214 if (double.IsNaN(q) || !(q > threshold)) { 215 predictedRejected = true; 216 quality = q; 217 break; 218 } 219 ++i; 220 } 221 222 var actuallyRejected = !(actualQuality > parentQuality); 223 224 if (RejectedStats.Rows == 0 || TotalStats.Rows == 0) { 225 RejectedStats = new IntMatrix(2, qualityPerInterval.Count); 226 RejectedStats.RowNames = new[] { "Predicted", "Actual" }; 227 RejectedStats.ColumnNames = Enumerable.Range(1, RejectedStats.Columns).Select(x => string.Format("0-{0}", Math.Min(trainingEnd, x * interval))); 228 TotalStats = new IntMatrix(2, 2); 229 TotalStats.RowNames = new[] { "Predicted", "Actual" }; 230 TotalStats.ColumnNames = new[] { "Rejected", "Not Rejected" }; 231 } 232 // gather some statistics 233 if (predictedRejected) { 234 RejectedStats[0, i]++; 235 TotalStats[0, 0]++; 236 } else { 237 TotalStats[0, 1]++; 238 } 239 if (actuallyRejected) { 240 TotalStats[1, 0]++; 241 } else { 242 TotalStats[1, 1]++; 243 } 244 if (predictedRejected && actuallyRejected) { 245 RejectedStats[1, i]++; 246 } 247 return quality; 248 } else { 249 while (targetValuesEnumerator.MoveNext() && estimatedValuesEnumerator.MoveNext()) { 250 pearsonRCalculator.Add(targetValuesEnumerator.Current, estimatedValuesEnumerator.Current); 251 ++i; 252 if (i % interval == 0 || i == trainingPartitionSize) { 253 var q = pearsonRCalculator.ErrorState != OnlineCalculatorError.None ? double.NaN : pearsonRCalculator.R; 254 var quality = q * q; 255 if (!(quality > threshold)) 256 return quality; 257 } 258 } 259 var r = pearsonRCalculator.ErrorState != OnlineCalculatorError.None ? double.NaN : pearsonRCalculator.R; 260 var actualQuality = r * r; 261 return actualQuality; 199 262 } 200 var r = pearsonRCalculator.ErrorState != OnlineCalculatorError.None ? double.NaN : pearsonRCalculator.R;201 var actualQuality = r * r;202 return actualQuality;203 263 } 204 264
Note: See TracChangeset
for help on using the changeset viewer.