Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/11 10:01:00 (14 years ago)
Author:
gkronber
Message:

#1418 renamed bounded evaluator, added base classes for single objective and multi objective validation analzers, added overfitting analyzers for symbolic regression and classification.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs

    r5735 r5747  
    3131using HeuristicLab.Parameters;
    3232using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    33 using HeuristicLab.Problems.DataAnalysis.Evaluators;
    3433using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3534using System;
    3635
    37 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
    38   [Item("SymbolicRegressionOverfittingAnalyzer", "Calculates and tracks correlation of training and validation fitness of symbolic regression models.")]
     36namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     37  [Item("SymbolicRegressionSingleObjectiveOverfittingAnalyzer", "Calculates and tracks correlation of training and validation fitness of symbolic regression models.")]
    3938  [StorableClass]
    40   public sealed class SymbolicRegressionOverfittingAnalyzer : SymbolicRegressionValidationAnalyzer, ISymbolicRegressionAnalyzer {
    41     private const string MaximizationParameterName = "Maximization";
    42     private const string QualityParameterName = "Quality";
    43     private const string TrainingValidationCorrelationParameterName = "TrainingValidationCorrelation";
    44     private const string TrainingValidationCorrelationTableParameterName = "TrainingValidationCorrelationTable";
     39  public sealed class SymbolicRegressionSingleObjectiveOverfittingAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationAnalyzer<ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData> {
     40    private const string TrainingValidationCorrelationParameterName = "Training and validation fitness correlation";
     41    private const string TrainingValidationCorrelationTableParameterName = "Training and validation fitness correlation table";
    4542    private const string LowerCorrelationThresholdParameterName = "LowerCorrelationThreshold";
    4643    private const string UpperCorrelationThresholdParameterName = "UpperCorrelationThreshold";
    4744    private const string OverfittingParameterName = "IsOverfitting";
    48     private const string ResultsParameterName = "Results";
    4945
    5046    #region parameter properties
    51     public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    52       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
    53     }
    54     public ILookupParameter<BoolValue> MaximizationParameter {
    55       get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; }
    56     }
    5747    public ILookupParameter<DoubleValue> TrainingValidationQualityCorrelationParameter {
    5848      get { return (ILookupParameter<DoubleValue>)Parameters[TrainingValidationCorrelationParameterName]; }
     
    7060      get { return (ILookupParameter<BoolValue>)Parameters[OverfittingParameterName]; }
    7161    }
    72     public ILookupParameter<ResultCollection> ResultsParameter {
    73       get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
    74     }
    75     #endregion
    76     #region properties
    77     public BoolValue Maximization {
    78       get { return MaximizationParameter.ActualValue; }
    79     }
    8062    #endregion
    8163
    8264    [StorableConstructor]
    83     private SymbolicRegressionOverfittingAnalyzer(bool deserializing) : base(deserializing) { }
    84     private SymbolicRegressionOverfittingAnalyzer(SymbolicRegressionOverfittingAnalyzer original, Cloner cloner) : base(original, cloner) { }
    85     public SymbolicRegressionOverfittingAnalyzer()
     65    private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(bool deserializing) : base(deserializing) { }
     66    private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(SymbolicRegressionSingleObjectiveOverfittingAnalyzer original, Cloner cloner) : base(original, cloner) { }
     67    public SymbolicRegressionSingleObjectiveOverfittingAnalyzer()
    8668      : base() {
    87       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "Training fitness"));
    88       Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));
    8969      Parameters.Add(new LookupParameter<DoubleValue>(TrainingValidationCorrelationParameterName, "Correlation of training and validation fitnesses"));
    9070      Parameters.Add(new LookupParameter<DataTable>(TrainingValidationCorrelationTableParameterName, "Data table of training and validation fitness correlation values over the whole run."));
     
    9272      Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperCorrelationThresholdParameterName, "Upper threshold for correlation value that marks the boundary from overfitting to non-overfitting.", new DoubleValue(0.75)));
    9373      Parameters.Add(new LookupParameter<BoolValue>(OverfittingParameterName, "Boolean indicator for overfitting."));
    94       Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection."));
    95     }
    96 
    97     [StorableHook(HookType.AfterDeserialization)]
    98     private void AfterDeserialization() {
    9974    }
    10075
    10176    public override IDeepCloneable Clone(Cloner cloner) {
    102       return new SymbolicRegressionOverfittingAnalyzer(this, cloner);
     77      return new SymbolicRegressionSingleObjectiveOverfittingAnalyzer(this, cloner);
    10378    }
    10479
    105     protected override void Analyze(SymbolicExpressionTree[] trees, double[] validationQuality) {
     80    public override IOperation Apply() {
    10681      double[] trainingQuality = QualityParameter.ActualValue.Select(x => x.Value).ToArray();
    107 
     82      // evaluate on validation partition
     83      int start = ValidationSamplesStart.Value;
     84      int end = ValidationSamplesEnd.Value;
     85      var rows = Enumerable.Range(start, end - start);
     86      IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(Evaluator);
     87      double[] validationQuality = (from tree in SymbolicExpressionTrees
     88                                    select Evaluator.Evaluate(childContext, tree, ProblemData, rows))
     89                                   .ToArray();
    10890      double r = alglib.spearmancorr2(trainingQuality, validationQuality);
    10991
     
    11193
    11294      if (TrainingValidationQualityCorrelationTableParameter.ActualValue == null) {
    113         var dataTable = new DataTable("Training and validation fitness correlation table", "Data table of training and validation fitness correlation values over the whole run.");
    114         dataTable.Rows.Add(new DataRow("Training and validation fitness correlation", "Training and validation fitness correlation values"));
     95        var dataTable = new DataTable(TrainingValidationQualityCorrelationTableParameter.Name, TrainingValidationQualityCorrelationTableParameter.Description);
     96        dataTable.Rows.Add(new DataRow(TrainingValidationQualityCorrelationParameter.Name, TrainingValidationQualityCorrelationParameter.Description));
    11597        TrainingValidationQualityCorrelationTableParameter.ActualValue = dataTable;
    116         ResultsParameter.ActualValue.Add(new Result(TrainingValidationCorrelationTableParameterName, dataTable));
     98        ResultCollectionParameter.ActualValue.Add(new Result(TrainingValidationQualityCorrelationTableParameter.Name, dataTable));
    11799      }
    118100
    119       TrainingValidationQualityCorrelationTableParameter.ActualValue.Rows["Training and validation fitness correlation"].Values.Add(r);
     101      TrainingValidationQualityCorrelationTableParameter.ActualValue.Rows[TrainingValidationQualityCorrelationParameter.Name].Values.Add(r);
    120102
    121103      if (OverfittingParameter.ActualValue != null && OverfittingParameter.ActualValue.Value) {
     
    128110        OverfittingParameter.ActualValue = new BoolValue(r < LowerCorrelationThresholdParameter.ActualValue.Value);
    129111      }
     112
     113      return base.Apply();
    130114    }
    131115  }
Note: See TracChangeset for help on using the changeset viewer.