Changeset 5747 for branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Timestamp:
- 03/18/11 10:01:00 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4
- Files:
-
- 7 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj
r5717 r5747 110 110 <Compile Include="Interfaces\ISymbolicDiscriminantFunctionClassificationModel.cs" /> 111 111 <Compile Include="MultiObjective\SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 112 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs" /> 113 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveOverfittingAnalyzer.cs" /> 112 114 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs" /> 113 115 <Compile Include="SymbolicDiscriminantFunctionClassificationModel.cs" /> … … 119 121 <Compile Include="MultiObjective\SymbolicClassificationMultiObjectiveProblem.cs" /> 120 122 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveEvaluator.cs" /> 121 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveBoundeMeanSquaredErrorEvaluator.cs" />122 123 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator.cs" /> 123 124 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs" /> -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r5722 r5747 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r5722 r5747 5 5 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 6 6 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 7 using System; 7 8 8 9 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { … … 33 34 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 34 35 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 35 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(originalValues, estimatedValues); 36 return new double[2] { r2, solution.Length }; 36 try { 37 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(originalValues, estimatedValues); 38 return new double[2] { r2, solution.Length }; 39 } 40 catch (ArgumentException) { 41 // if R² cannot be calcualted because of infinity or NaN values => return worst possible fitness value 42 return new double[2] { 0.0, solution.Length }; 43 } 37 44 } 38 45 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r5736 r5747 38 38 [StorableClass] 39 39 public sealed class SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>, 40 ISymbolicDataAnalysisInterpreterOperator {40 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator { 41 41 private const string ProblemDataParameterName = "ProblemData"; 42 42 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs
r5735 r5747 32 32 [Item("Bounded Mean squared error Evaluator", "Calculates the bounded mean squared error of a symbolic classification solution (estimations above or below the class values are only penaltilized linearly.")] 33 33 [StorableClass] 34 public class SymbolicClassificationSingleObjectiveBounde MeanSquaredErrorEvaluator : SymbolicClassificationSingleObjectiveEvaluator {34 public class SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator : SymbolicClassificationSingleObjectiveEvaluator { 35 35 36 36 [StorableConstructor] 37 protected SymbolicClassificationSingleObjectiveBounde MeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { }38 protected SymbolicClassificationSingleObjectiveBounde MeanSquaredErrorEvaluator(SymbolicClassificationSingleObjectiveBoundeMeanSquaredErrorEvaluator original, Cloner cloner) : base(original, cloner) { }37 protected SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { } 38 protected SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator(SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator original, Cloner cloner) : base(original, cloner) { } 39 39 public override IDeepCloneable Clone(Cloner cloner) { 40 return new SymbolicClassificationSingleObjectiveBounde MeanSquaredErrorEvaluator(this, cloner);40 return new SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator(this, cloner); 41 41 } 42 42 43 public SymbolicClassificationSingleObjectiveBounde MeanSquaredErrorEvaluator() : base() { }43 public SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator() : base() { } 44 44 45 45 public override bool Maximization { get { return false; } } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator.cs
r5722 r5747 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { … … 62 63 LowerEstimationLimitParameter.ExecutionContext = context; 63 64 UpperEstimationLimitParameter.ExecutionContext = context; 64 65 65 66 double mse = Calculate(SymbolicDataAnalysisTreeInterpreter, tree, LowerEstimationLimit.Value, UpperEstimationLimit.Value, problemData, rows); 66 67 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveOverfittingAnalyzer.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("Symbolic RegressionOverfittingAnalyzer", "Calculates and tracks correlation of training and validation fitness of symbolic regression models.")]36 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 37 [Item("SymbolicClassificationSingleObjectiveOverfittingAnalyzer", "Calculates and tracks correlation of training and validation fitness of symbolic classification 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 SymbolicClassificationSingleObjectiveOverfittingAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationAnalyzer<ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData> { 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 Symbolic RegressionOverfittingAnalyzer(bool deserializing) : base(deserializing) { }84 private Symbolic RegressionOverfittingAnalyzer(SymbolicRegressionOverfittingAnalyzer original, Cloner cloner) : base(original, cloner) { }85 public Symbolic RegressionOverfittingAnalyzer()65 private SymbolicClassificationSingleObjectiveOverfittingAnalyzer(bool deserializing) : base(deserializing) { } 66 private SymbolicClassificationSingleObjectiveOverfittingAnalyzer(SymbolicClassificationSingleObjectiveOverfittingAnalyzer original, Cloner cloner) : base(original, cloner) { } 67 public SymbolicClassificationSingleObjectiveOverfittingAnalyzer() 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 Symbolic RegressionOverfittingAnalyzer(this, cloner);77 return new SymbolicClassificationSingleObjectiveOverfittingAnalyzer(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 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs
r5722 r5747 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { … … 54 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 55 56 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 56 return OnlinePearsonsRSquaredEvaluator.Calculate(originalValues, estimatedValues); 57 try { 58 return OnlinePearsonsRSquaredEvaluator.Calculate(originalValues, estimatedValues); 59 } 60 catch (ArgumentException) { 61 // if R² cannot be calculated because of NaN or ininity elements => return worst possible fitness valuse 62 return 0.0; 63 } 57 64 } 58 65 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r5733 r5747 76 76 Operators.Add(new SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer()); 77 77 Operators.Add(new SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer()); 78 Operators.Add(new SymbolicClassificationSingleObjectiveOverfittingAnalyzer()); 78 79 ParameterizeOperators(); 79 80 }
Note: See TracChangeset
for help on using the changeset viewer.