Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/18/16 17:14:33 (8 years ago)
Author:
bburlacu
Message:

#2635: Improve performance and accuracy of evaluator and analyzer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/OSGAPredictionCountsAnalyzer.cs

    r14072 r14104  
    1 using HeuristicLab.Common;
     1using System.Linq;
     2using HeuristicLab.Analysis;
     3using HeuristicLab.Common;
    24using HeuristicLab.Core;
     5using HeuristicLab.Optimization;
     6using HeuristicLab.Parameters;
    37using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    48using HeuristicLab.Problems.DataAnalysis.Symbolic;
     9using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    510
    611namespace HeuristicLab.OSGAEvaluator {
     
    914
    1015  public class OSGAPredictionCountsAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer {
     16    private const string EvaluatorParameterName = "Evaluator";
     17    private const string ResultCollectionParameterName = "Results";
     18
     19    public ILookupParameter<SymbolicRegressionSingleObjectiveOsgaEvaluator> EvaluatorParameter {
     20      get { return (ILookupParameter<SymbolicRegressionSingleObjectiveOsgaEvaluator>)Parameters[EvaluatorParameterName]; }
     21    }
     22
     23    public OSGAPredictionCountsAnalyzer() {
     24      Parameters.Add(new LookupParameter<SymbolicRegressionSingleObjectiveOsgaEvaluator>(EvaluatorParameterName));
     25    }
    1126
    1227    protected OSGAPredictionCountsAnalyzer(OSGAPredictionCountsAnalyzer original, Cloner cloner) : base(original, cloner) {
     
    1631      return new OSGAPredictionCountsAnalyzer(this, cloner);
    1732    }
     33
     34    public override IOperation Apply() {
     35      var evaluator = EvaluatorParameter.ActualValue;
     36      if (evaluator == null)
     37        return base.Apply();
     38
     39      var rejectedStats = evaluator.RejectedStats;
     40      var totalStats = evaluator.TotalStats;
     41
     42      if (rejectedStats.Rows == 0 || totalStats.Rows == 0)
     43        return base.Apply();
     44
     45      ResultCollection predictionResults;
     46      DataTable rejectedStatsTable, totalStatsTable;
     47      if (!ResultCollection.ContainsKey("OS Prediction")) {
     48        predictionResults = new ResultCollection();
     49        rejectedStatsTable = new DataTable("Rejected Stats");
     50        foreach (var rowName in rejectedStats.RowNames) {
     51          rejectedStatsTable.Rows.Add(new DataRow(rowName) { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Columns, LineWidth = 1 } });
     52        }
     53        predictionResults.Add(new Result("Rejected Stats", rejectedStatsTable));
     54        totalStatsTable = new DataTable("Total Stats");
     55        foreach (var rowName in totalStats.RowNames) {
     56          totalStatsTable.Rows.Add(new DataRow(rowName) { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Columns, LineWidth = 1 } });
     57        }
     58        predictionResults.Add(new Result("Total Stats", totalStatsTable));
     59
     60        ResultCollection.Add(new Result("OS Prediction", predictionResults));
     61      } else {
     62        predictionResults = (ResultCollection)ResultCollection["OS Prediction"].Value;
     63        rejectedStatsTable = (DataTable)predictionResults["Rejected Stats"].Value;
     64        totalStatsTable = (DataTable)predictionResults["Total Stats"].Value;
     65      }
     66
     67      int i = 0;
     68      foreach (var rowName in rejectedStats.RowNames) {
     69        // add a padding zero below to prevent columns from being cut off to the left
     70        rejectedStatsTable.Rows[rowName].Values.Replace(new[] { 0d }.Concat(Enumerable.Range(0, rejectedStats.Columns).Select(j => (double)rejectedStats[i, j])).Concat(new[] { 0d }));
     71        ++i;
     72      }
     73      i = 0;
     74      foreach (var rowName in totalStats.RowNames) {
     75        totalStatsTable.Rows[rowName].Values.Replace(new[] { 0d }.Concat(Enumerable.Range(0, totalStats.Columns).Select(j => (double)totalStats[i, j])).Concat(new[] { 0d }));
     76        ++i;
     77      }
     78      return base.Apply();
     79    }
    1880  }
    1981}
Note: See TracChangeset for help on using the changeset viewer.