Changeset 8915 for branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective
- Timestamp:
- 11/15/12 16:47:25 (12 years ago)
- Location:
- branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r7259 r8915 47 47 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 48 var solution = SymbolicExpressionTreeParameter.ActualValue; 49 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows );49 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 50 QualitiesParameter.ActualValue = new DoubleArray(qualities); 51 51 return base.Apply(); 52 52 } 53 53 54 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows ) {54 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 56 IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 57 IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 57 OnlineCalculatorError errorState; 59 double mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState); 58 59 double mse; 60 if (applyLinearScaling) { 61 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows); 63 errorState = mseCalculator.ErrorState; 64 mse = mseCalculator.MeanSquaredError; 65 } else { 66 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 67 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 68 } 60 69 if (errorState != OnlineCalculatorError.None) mse = double.NaN; 61 70 return new double[2] { mse, solution.Length }; … … 65 74 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 66 75 EstimationLimitsParameter.ExecutionContext = context; 76 ApplyLinearScalingParameter.ExecutionContext = context; 67 77 68 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows );78 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 69 79 70 80 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 71 81 EstimationLimitsParameter.ExecutionContext = null; 82 ApplyLinearScalingParameter.ExecutionContext = null; 72 83 73 84 return quality; -
branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r7259 r8915 47 47 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 48 var solution = SymbolicExpressionTreeParameter.ActualValue; 49 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows );49 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 50 QualitiesParameter.ActualValue = new DoubleArray(qualities); 51 51 return base.Apply(); 52 52 } 53 53 54 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows ) {54 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 56 IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 57 57 OnlineCalculatorError errorState; 58 double r2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedValues, originalValues, out errorState); 59 if (errorState != OnlineCalculatorError.None) r2 = 0.0; 60 return new double[] { r2, solution.Length }; 58 59 double r2; 60 if (applyLinearScaling) { 61 var r2Calculator = new OnlinePearsonsRSquaredCalculator(); 62 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows); 63 errorState = r2Calculator.ErrorState; 64 r2 = r2Calculator.RSquared; 65 } else { 66 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 67 r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 68 } 69 70 if (errorState != OnlineCalculatorError.None) r2 = double.NaN; 71 return new double[2] { r2, solution.Length }; 61 72 } 62 73 … … 64 75 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 65 76 EstimationLimitsParameter.ExecutionContext = context; 77 ApplyLinearScalingParameter.ExecutionContext = context; 66 78 67 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows );79 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 68 80 69 81 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 70 82 EstimationLimitsParameter.ExecutionContext = null; 83 ApplyLinearScalingParameter.ExecutionContext = null; 71 84 72 85 return quality; -
branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs
r8175 r8915 65 65 EstimationLimitsParameter.Hidden = true; 66 66 67 ApplyLinearScalingParameter.Value.Value = true; 67 68 Maximization = new BoolArray(new bool[] { true, false }); 68 69 MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth; -
branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs
r7259 r8915 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 25 using HeuristicLab.Parameters; … … 38 37 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 39 38 private const string EstimationLimitsParameterName = "EstimationLimits"; 40 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";41 39 #region parameter properties 42 40 public ILookupParameter<IRegressionProblemData> ProblemDataParameter { … … 48 46 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter { 49 47 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 50 }51 public IValueParameter<BoolValue> ApplyLinearScalingParameter {52 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }53 }54 #endregion55 56 #region properties57 public BoolValue ApplyLinearScaling {58 get { return ApplyLinearScalingParameter.Value; }59 48 } 60 49 #endregion … … 68 57 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 69 58 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model.")); 70 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));71 59 } 72 60 … … 77 65 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 78 66 var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 79 if (ApplyLinearScaling.Value) 80 SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue); 67 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable); 81 68 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); 82 69 } -
branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs
r7259 r8915 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 25 using HeuristicLab.Parameters; … … 36 35 ISymbolicDataAnalysisBoundedOperator { 37 36 private const string EstimationLimitsParameterName = "EstimationLimits"; 38 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";39 37 40 38 #region parameter properties … … 42 40 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 43 41 } 44 public IValueParameter<BoolValue> ApplyLinearScalingParameter {45 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }46 }47 42 #endregion 48 43 49 #region properties50 public BoolValue ApplyLinearScaling {51 get { return ApplyLinearScalingParameter.Value; }52 }53 #endregion54 44 [StorableConstructor] 55 45 private SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 58 48 : base() { 59 49 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model.")); 60 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));61 50 } 62 51 public override IDeepCloneable Clone(Cloner cloner) { … … 66 55 protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 67 56 var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 68 if (ApplyLinearScaling.Value) 69 SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue); 57 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable); 70 58 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); 71 59 }
Note: See TracChangeset
for help on using the changeset viewer.