Changeset 8206 for branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective
- Timestamp:
- 07/03/12 16:46:35 (12 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators
- Property svn:mergeinfo changed
/trunk/sources merged: 8084,8088-8090,8092-8100,8102-8113,8115,8117-8132,8134-8146,8148-8156,8158-8160,8163-8170,8173-8176,8178-8190,8192-8205
- Property svn:mergeinfo changed
-
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs
r7677 r8206 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 59 60 private static double[] cache; 60 61 61 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, IOnlineCalculator calculator, int maxRows) { 62 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, 63 double lowerEstimationLimit, double upperEstimationLimit, 64 IOnlineCalculator calculator, int maxRows) { 62 65 if (cache == null || cache.GetLength(0) < maxRows) { 63 66 cache = new double[maxRows]; … … 83 86 //calculate the quality by using the passed online calculator 84 87 targetValuesEnumerator = targetValues.GetEnumerator(); 85 i = 0; 86 while (targetValuesEnumerator.MoveNext()) { 87 double target = targetValuesEnumerator.Current; 88 double estimated = cache[i] * beta + alpha; 89 calculator.Add(target, estimated); 90 i++; 88 var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha) 89 .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator(); 90 91 while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) { 92 calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current); 91 93 } 92 94 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs
r7677 r8206 56 56 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 57 57 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);59 58 OnlineCalculatorError errorState; 60 59 … … 62 61 if (applyLinearScaling) { 63 62 var maeCalculator = new OnlineMaxAbsoluteErrorCalculator(); 64 CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);63 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, maeCalculator, problemData.Dataset.Rows); 65 64 errorState = maeCalculator.ErrorState; 66 65 mse = maeCalculator.MaxAbsoluteError; 67 } else 66 } else { 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 68 68 mse = OnlineMaxAbsoluteErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 69 69 } 70 70 if (errorState != OnlineCalculatorError.None) return Double.NaN; 71 71 else return mse; -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs
r7677 r8206 56 56 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 57 57 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);59 58 OnlineCalculatorError errorState; 60 59 … … 62 61 if (applyLinearScaling) { 63 62 var maeCalculator = new OnlineMeanAbsoluteErrorCalculator(); 64 CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);63 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, maeCalculator, problemData.Dataset.Rows); 65 64 errorState = maeCalculator.ErrorState; 66 65 mse = maeCalculator.MeanAbsoluteError; 67 } else 66 } else { 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, 68 upperEstimationLimit); 68 69 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 69 70 } 70 71 if (errorState != OnlineCalculatorError.None) return Double.NaN; 71 72 else return mse; -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r7677 r8206 56 56 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 57 57 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);59 58 OnlineCalculatorError errorState; 60 59 … … 62 61 if (applyLinearScaling) { 63 62 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 64 CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows);63 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows); 65 64 errorState = mseCalculator.ErrorState; 66 65 mse = mseCalculator.MeanSquaredError; 67 } else 66 } else { 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 68 68 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 69 69 } 70 70 if (errorState != OnlineCalculatorError.None) return Double.NaN; 71 71 else return mse; -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r8085 r8206 49 49 [StorableConstructor] 50 50 protected SymbolicRegressionSingleObjectiveProblem(bool deserializing) : base(deserializing) { } 51 protected SymbolicRegressionSingleObjectiveProblem(SymbolicRegressionSingleObjectiveProblem original, Cloner cloner) : base(original, cloner) { } 51 protected SymbolicRegressionSingleObjectiveProblem(SymbolicRegressionSingleObjectiveProblem original, Cloner cloner) 52 : base(original, cloner) { 53 RegisterEventHandlers(); 54 } 52 55 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionSingleObjectiveProblem(this, cloner); } 53 56 … … 62 65 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; 63 66 64 SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols(); 65 67 RegisterEventHandlers(); 66 68 ConfigureGrammarSymbols(); 67 69 InitializeOperators(); 68 70 UpdateEstimationLimits(); 71 } 72 73 [StorableHook(HookType.AfterDeserialization)] 74 private void AfterDeserialization() { 75 RegisterEventHandlers(); 76 // compatibility 77 bool changed = false; 78 if (!Operators.OfType<SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer>().Any()) { 79 Operators.Add(new SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer()); 80 changed = true; 81 } 82 if (!Operators.OfType<SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer>().Any()) { 83 Operators.Add(new SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer()); 84 changed = true; 85 } 86 if (changed) { 87 ParameterizeOperators(); 88 } 89 } 90 91 private void RegisterEventHandlers() { 92 SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols(); 69 93 } 70 94 … … 85 109 86 110 private void UpdateEstimationLimits() { 87 if (ProblemData.TrainingIndi zes.Any()) {88 var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndi zes).ToList();111 if (ProblemData.TrainingIndices.Any()) { 112 var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToList(); 89 113 var mean = targetValues.Average(); 90 114 var range = targetValues.Max() - targetValues.Min(); -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs
r7726 r8206 33 33 [Item("SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer", "An operator that collects the training Pareto-best symbolic regression solutions for single objective symbolic regression problems.")] 34 34 [StorableClass] 35 public sealed class SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<ISymbolicRegressionSolution>, 36 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator { 37 private const string ProblemDataParameterName = "ProblemData"; 38 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 39 private const string EstimationLimitsParameterName = "EstimationLimits"; 35 public sealed class SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IRegressionProblemData, ISymbolicRegressionSolution> { 40 36 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 41 37 #region parameter properties 42 public ILookupParameter<IRegressionProblemData> ProblemDataParameter {43 get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }44 }45 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {46 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }47 }48 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {49 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }50 }51 38 public IValueParameter<BoolValue> ApplyLinearScalingParameter { 52 39 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } … … 65 52 public SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer() 66 53 : base() { 67 Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution."));68 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));69 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));70 54 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true))); 71 55 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs
r7734 r8206 33 33 [Item("SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer", "An operator that collects the validation Pareto-best symbolic regression solutions for single objective symbolic regression problems.")] 34 34 [StorableClass] 35 public sealed class SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData>, 36 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator { 37 private const string EstimationLimitsParameterName = "EstimationLimits"; 35 public sealed class SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData> { 38 36 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 39 37 #region parameter properties 40 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {41 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }42 }43 38 public IValueParameter<BoolValue> ApplyLinearScalingParameter { 44 39 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } … … 57 52 public SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer() 58 53 : base() { 59 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));60 54 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true))); 61 55 }
Note: See TracChangeset
for help on using the changeset viewer.