[14584] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[16818] | 22 | using HEAL.Attic;
|
---|
[14104] | 23 | using HeuristicLab.Analysis;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
[14072] | 25 | using HeuristicLab.Core;
|
---|
[14104] | 26 | using HeuristicLab.Optimization;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
[14072] | 28 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
[14104] | 29 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
[16818] | 30 | using System.Linq;
|
---|
[14072] | 31 |
|
---|
| 32 | namespace HeuristicLab.OSGAEvaluator {
|
---|
| 33 | [Item("OSGAPredictionCountsAnalyzer", "An analyzer which records the counts of the rejected offspring predicted by the evaluator without evaluating all rows.")]
|
---|
[16818] | 34 | [StorableType("7730D977-A422-4C64-83C2-8989EA4B3922")]
|
---|
[14072] | 35 | public class OSGAPredictionCountsAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer {
|
---|
[14104] | 36 | private const string EvaluatorParameterName = "Evaluator";
|
---|
| 37 | private const string ResultCollectionParameterName = "Results";
|
---|
[14072] | 38 |
|
---|
[14428] | 39 | public ILookupParameter<SymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
|
---|
| 40 | get { return (ILookupParameter<SymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
|
---|
[14104] | 41 | }
|
---|
| 42 |
|
---|
[16818] | 43 | [StorableConstructor]
|
---|
| 44 | protected OSGAPredictionCountsAnalyzer(StorableConstructorFlag _) : base(_) {
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[14104] | 47 | public OSGAPredictionCountsAnalyzer() {
|
---|
[14428] | 48 | Parameters.Add(new LookupParameter<SymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
|
---|
[14104] | 49 | }
|
---|
| 50 |
|
---|
[14072] | 51 | protected OSGAPredictionCountsAnalyzer(OSGAPredictionCountsAnalyzer original, Cloner cloner) : base(original, cloner) {
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 55 | return new OSGAPredictionCountsAnalyzer(this, cloner);
|
---|
| 56 | }
|
---|
[14104] | 57 |
|
---|
| 58 | public override IOperation Apply() {
|
---|
[14428] | 59 | var evaluator = EvaluatorParameter.ActualValue as SymbolicRegressionSingleObjectiveOsgaEvaluator;
|
---|
[14104] | 60 | if (evaluator == null)
|
---|
| 61 | return base.Apply();
|
---|
| 62 |
|
---|
| 63 | var rejectedStats = evaluator.RejectedStats;
|
---|
| 64 | var totalStats = evaluator.TotalStats;
|
---|
| 65 |
|
---|
| 66 | if (rejectedStats.Rows == 0 || totalStats.Rows == 0)
|
---|
| 67 | return base.Apply();
|
---|
| 68 |
|
---|
| 69 | ResultCollection predictionResults;
|
---|
[14584] | 70 | DataTable rejectedStatsTable, totalStatsTable, rejectedStatsPerGenerationTable;
|
---|
[14104] | 71 | if (!ResultCollection.ContainsKey("OS Prediction")) {
|
---|
| 72 | predictionResults = new ResultCollection();
|
---|
| 73 | rejectedStatsTable = new DataTable("Rejected Stats");
|
---|
| 74 | foreach (var rowName in rejectedStats.RowNames) {
|
---|
| 75 | rejectedStatsTable.Rows.Add(new DataRow(rowName) { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Columns, LineWidth = 1 } });
|
---|
| 76 | }
|
---|
| 77 | predictionResults.Add(new Result("Rejected Stats", rejectedStatsTable));
|
---|
| 78 | totalStatsTable = new DataTable("Total Stats");
|
---|
| 79 | foreach (var rowName in totalStats.RowNames) {
|
---|
| 80 | totalStatsTable.Rows.Add(new DataRow(rowName) { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Columns, LineWidth = 1 } });
|
---|
| 81 | }
|
---|
| 82 | predictionResults.Add(new Result("Total Stats", totalStatsTable));
|
---|
[14231] | 83 | rejectedStatsPerGenerationTable = new DataTable("Rejected Per Generation");
|
---|
| 84 | foreach (var rowName in rejectedStats.RowNames) {
|
---|
| 85 | rejectedStatsPerGenerationTable.Rows.Add(new DataRow(rowName) { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Line, LineWidth = 1 } });
|
---|
| 86 | rejectedStatsPerGenerationTable.Rows[rowName].Values.Add(0d);
|
---|
| 87 | }
|
---|
| 88 | predictionResults.Add(new Result("Rejected Stats Per Generation", rejectedStatsPerGenerationTable));
|
---|
[14104] | 89 | ResultCollection.Add(new Result("OS Prediction", predictionResults));
|
---|
| 90 | } else {
|
---|
| 91 | predictionResults = (ResultCollection)ResultCollection["OS Prediction"].Value;
|
---|
| 92 | rejectedStatsTable = (DataTable)predictionResults["Rejected Stats"].Value;
|
---|
| 93 | totalStatsTable = (DataTable)predictionResults["Total Stats"].Value;
|
---|
[14231] | 94 | rejectedStatsPerGenerationTable = (DataTable)predictionResults["Rejected Stats Per Generation"].Value;
|
---|
[14104] | 95 | }
|
---|
| 96 |
|
---|
| 97 | int i = 0;
|
---|
| 98 | foreach (var rowName in rejectedStats.RowNames) {
|
---|
[14231] | 99 | // pad values with a 0 on each side to prevent clipping
|
---|
[14104] | 100 | rejectedStatsTable.Rows[rowName].Values.Replace(new[] { 0d }.Concat(Enumerable.Range(0, rejectedStats.Columns).Select(j => (double)rejectedStats[i, j])).Concat(new[] { 0d }));
|
---|
| 101 | ++i;
|
---|
| 102 | }
|
---|
| 103 | i = 0;
|
---|
| 104 | foreach (var rowName in totalStats.RowNames) {
|
---|
| 105 | totalStatsTable.Rows[rowName].Values.Replace(new[] { 0d }.Concat(Enumerable.Range(0, totalStats.Columns).Select(j => (double)totalStats[i, j])).Concat(new[] { 0d }));
|
---|
[14231] | 106 | var row = rejectedStatsPerGenerationTable.Rows[rowName];
|
---|
| 107 | var sum = row.Values.Sum();
|
---|
| 108 | row.Values.Add(totalStats[i, 0] - sum);
|
---|
[14104] | 109 | ++i;
|
---|
| 110 | }
|
---|
| 111 | return base.Apply();
|
---|
| 112 | }
|
---|
[14072] | 113 | }
|
---|
| 114 | }
|
---|