Changeset 5747 for branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs
- Timestamp:
- 03/18/11 10:01:00 (14 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs
r5735 r5747 31 31 using HeuristicLab.Parameters; 32 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 using HeuristicLab.Problems.DataAnalysis.Evaluators;34 33 using HeuristicLab.Problems.DataAnalysis.Symbolic; 35 34 using System; 36 35 37 namespace HeuristicLab.Problems.DataAnalysis. Regression.Symbolic.Analyzers{38 [Item("SymbolicRegression OverfittingAnalyzer", "Calculates and tracks correlation of training and validation fitness of symbolic regression models.")]36 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 37 [Item("SymbolicRegressionSingleObjectiveOverfittingAnalyzer", "Calculates and tracks correlation of training and validation fitness of symbolic regression models.")] 39 38 [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"; 45 42 private const string LowerCorrelationThresholdParameterName = "LowerCorrelationThreshold"; 46 43 private const string UpperCorrelationThresholdParameterName = "UpperCorrelationThreshold"; 47 44 private const string OverfittingParameterName = "IsOverfitting"; 48 private const string ResultsParameterName = "Results";49 45 50 46 #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 }57 47 public ILookupParameter<DoubleValue> TrainingValidationQualityCorrelationParameter { 58 48 get { return (ILookupParameter<DoubleValue>)Parameters[TrainingValidationCorrelationParameterName]; } … … 70 60 get { return (ILookupParameter<BoolValue>)Parameters[OverfittingParameterName]; } 71 61 } 72 public ILookupParameter<ResultCollection> ResultsParameter {73 get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }74 }75 #endregion76 #region properties77 public BoolValue Maximization {78 get { return MaximizationParameter.ActualValue; }79 }80 62 #endregion 81 63 82 64 [StorableConstructor] 83 private SymbolicRegression OverfittingAnalyzer(bool deserializing) : base(deserializing) { }84 private SymbolicRegression OverfittingAnalyzer(SymbolicRegressionOverfittingAnalyzer original, Cloner cloner) : base(original, cloner) { }85 public SymbolicRegression OverfittingAnalyzer()65 private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(bool deserializing) : base(deserializing) { } 66 private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(SymbolicRegressionSingleObjectiveOverfittingAnalyzer original, Cloner cloner) : base(original, cloner) { } 67 public SymbolicRegressionSingleObjectiveOverfittingAnalyzer() 86 68 : base() { 87 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "Training fitness"));88 Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));89 69 Parameters.Add(new LookupParameter<DoubleValue>(TrainingValidationCorrelationParameterName, "Correlation of training and validation fitnesses")); 90 70 Parameters.Add(new LookupParameter<DataTable>(TrainingValidationCorrelationTableParameterName, "Data table of training and validation fitness correlation values over the whole run.")); … … 92 72 Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperCorrelationThresholdParameterName, "Upper threshold for correlation value that marks the boundary from overfitting to non-overfitting.", new DoubleValue(0.75))); 93 73 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() {99 74 } 100 75 101 76 public override IDeepCloneable Clone(Cloner cloner) { 102 return new SymbolicRegression OverfittingAnalyzer(this, cloner);77 return new SymbolicRegressionSingleObjectiveOverfittingAnalyzer(this, cloner); 103 78 } 104 79 105 p rotected override void Analyze(SymbolicExpressionTree[] trees, double[] validationQuality) {80 public override IOperation Apply() { 106 81 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(); 108 90 double r = alglib.spearmancorr2(trainingQuality, validationQuality); 109 91 … … 111 93 112 94 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)); 115 97 TrainingValidationQualityCorrelationTableParameter.ActualValue = dataTable; 116 Result sParameter.ActualValue.Add(new Result(TrainingValidationCorrelationTableParameterName, dataTable));98 ResultCollectionParameter.ActualValue.Add(new Result(TrainingValidationQualityCorrelationTableParameter.Name, dataTable)); 117 99 } 118 100 119 TrainingValidationQualityCorrelationTableParameter.ActualValue.Rows[ "Training and validation fitness correlation"].Values.Add(r);101 TrainingValidationQualityCorrelationTableParameter.ActualValue.Rows[TrainingValidationQualityCorrelationParameter.Name].Values.Add(r); 120 102 121 103 if (OverfittingParameter.ActualValue != null && OverfittingParameter.ActualValue.Value) { … … 128 110 OverfittingParameter.ActualValue = new BoolValue(r < LowerCorrelationThresholdParameter.ActualValue.Value); 129 111 } 112 113 return base.Apply(); 130 114 } 131 115 }
Note: See TracChangeset
for help on using the changeset viewer.