- Timestamp:
- 09/17/12 11:18:40 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r7259 r8664 65 65 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 66 66 EstimationLimitsParameter.ExecutionContext = context; 67 ApplyLinearScalingParameter.ExecutionContext = context; 67 68 68 69 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows); … … 70 71 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 71 72 EstimationLimitsParameter.ExecutionContext = null; 73 ApplyLinearScalingParameter.ExecutionContext = null; 72 74 73 75 return quality; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r6740 r8664 26 26 IEnumerable<int> rows = GenerateRowsToEvaluate(); 27 27 var solution = SymbolicExpressionTreeParameter.ActualValue; 28 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows );28 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 29 29 QualitiesParameter.ActualValue = new DoubleArray(qualities); 30 30 return base.Apply(); 31 31 } 32 32 33 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows ) {33 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 34 34 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 35 IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);35 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 36 36 OnlineCalculatorError errorState; 37 double r2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedValues, originalValues, out errorState); 38 if (errorState != OnlineCalculatorError.None) r2 = 0.0; 39 return new double[] { r2, solution.Length }; 37 38 double r2; 39 if (applyLinearScaling) { 40 var r2Calculator = new OnlinePearsonsRSquaredCalculator(); 41 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows); 42 errorState = r2Calculator.ErrorState; 43 r2 = r2Calculator.RSquared; 44 } else { 45 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 46 r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 47 } 48 49 if (errorState != OnlineCalculatorError.None) r2 = double.NaN; 50 return new double[2] { r2, solution.Length }; 40 51 41 52 } … … 45 56 EstimationLimitsParameter.ExecutionContext = context; 46 57 47 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows );58 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 48 59 49 60 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs
r8594 r8664 68 68 Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator())); 69 69 70 ApplyLinearScalingParameter.Value.Value = false; 70 71 EstimationLimitsParameter.Hidden = true; 71 72 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r8594 r8664 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; … … 39 38 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 40 39 private const string EstimationLimitsParameterName = "EstimationLimits"; 41 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";42 40 43 41 #region parameter properties … … 57 55 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 58 56 } 59 public IValueParameter<BoolValue> ApplyLinearScalingParameter {60 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }61 }62 #endregion63 64 #region properties65 public BoolValue ApplyLinearScaling {66 get { return ApplyLinearScalingParameter.Value; }67 }68 57 #endregion 69 58 … … 77 66 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 78 67 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model.")); 79 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));80 68 } 81 69 public override IDeepCloneable Clone(Cloner cloner) { … … 91 79 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 92 80 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 93 if (ApplyLinearScaling .Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);81 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable); 94 82 95 83 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs
r8594 r8664 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; … … 37 36 private const string ModelCreatorParameterName = "ModelCreator"; 38 37 private const string EstimationLimitsParameterName = "EstimationLimits"; 39 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";40 38 41 39 #region parameter properties 42 40 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter { 43 41 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 44 }45 public IValueParameter<BoolValue> ApplyLinearScalingParameter {46 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }47 42 } 48 43 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { … … 54 49 #endregion 55 50 56 #region properties57 public BoolValue ApplyLinearScaling {58 get { return ApplyLinearScalingParameter.Value; }59 }60 #endregion61 51 [StorableConstructor] 62 52 private SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 65 55 : base() { 66 56 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The loewr and upper limit for the estimated values produced by the symbolic classification model.")); 67 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));68 57 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 69 58 } … … 72 61 } 73 62 74 [StorableHook(HookType.AfterDeserialization)]75 private void AfterDeserialization() {76 if (!Parameters.ContainsKey(ModelCreatorParameterName))77 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));78 }79 63 80 64 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQualities) { 81 65 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 82 if (ApplyLinearScaling .Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);66 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable); 83 67 84 68 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs
r7259 r8664 47 47 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 48 var solution = SymbolicExpressionTreeParameter.ActualValue; 49 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows );49 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 50 QualityParameter.ActualValue = new DoubleValue(quality); 51 51 return base.Apply(); 52 52 } 53 53 54 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows ) {54 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData 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); 57 OnlineCalculatorError errorState; 58 58 59 double minClassValue = problemData.ClassValues.OrderBy(x => x).First();60 double maxClassValue = problemData.ClassValues.OrderBy(x => x).Last();59 double lowestClassValue = problemData.ClassValues.OrderBy(x => x).First(); 60 double upmostClassValue = problemData.ClassValues.OrderByDescending(x => x).First(); 61 61 62 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 63 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 64 double errorSum = 0.0; 65 int n = 0; 66 67 // always move forward both enumerators (do not use short-circuit evaluation!) 68 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 69 double estimated = estimatedEnumerator.Current; 70 double original = originalEnumerator.Current; 71 double error = estimated - original; 72 73 if (estimated < minClassValue || estimated > maxClassValue) 74 errorSum += Math.Abs(error); 75 else 76 errorSum += Math.Pow(error, 2); 77 n++; 62 double boundedMse; 63 if (applyLinearScaling) { 64 var boundedMseCalculator = new OnlineBoundedMeanSquaredErrorCalculator(lowestClassValue, upmostClassValue); 65 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, boundedMseCalculator, problemData.Dataset.Rows); 66 errorState = boundedMseCalculator.ErrorState; 67 boundedMse = boundedMseCalculator.BoundedMeanSquaredError; 68 } else { 69 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 70 boundedMse = OnlineBoundedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, lowestClassValue, upmostClassValue, out errorState); 78 71 } 79 80 // check if both enumerators are at the end to make sure both enumerations have the same length 81 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) { 82 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 83 } else { 84 return errorSum / n; 85 } 72 if (errorState != OnlineCalculatorError.None) return Double.NaN; 73 return boundedMse; 86 74 } 87 75 … … 89 77 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 90 78 EstimationLimitsParameter.ExecutionContext = context; 79 ApplyLinearScalingParameter.ExecutionContext = context; 91 80 92 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows );81 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 93 82 94 83 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 95 84 EstimationLimitsParameter.ExecutionContext = null; 85 ApplyLinearScalingParameter.ExecutionContext = null; 96 86 97 87 return mse; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator.cs
r7259 r8664 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 47 48 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 49 var solution = SymbolicExpressionTreeParameter.ActualValue; 49 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows );50 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 51 QualityParameter.ActualValue = new DoubleValue(quality); 51 52 return base.Apply(); 52 53 } 53 54 54 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows ) {55 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 56 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); 57 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 58 OnlineCalculatorError errorState; 59 double mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState); 60 if (errorState != OnlineCalculatorError.None) return double.NaN; 61 else return mse; 59 60 double mse; 61 if (applyLinearScaling) { 62 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 63 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows); 64 errorState = mseCalculator.ErrorState; 65 mse = mseCalculator.MeanSquaredError; 66 } else { 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 68 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 69 } 70 if (errorState != OnlineCalculatorError.None) return Double.NaN; 71 return mse; 62 72 } 63 73 … … 65 75 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 66 76 EstimationLimitsParameter.ExecutionContext = context; 77 ApplyLinearScalingParameter.ExecutionContext = context; 67 78 68 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows );79 double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 69 80 70 81 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 71 82 EstimationLimitsParameter.ExecutionContext = null; 83 ApplyLinearScalingParameter.ExecutionContext = null; 72 84 73 85 return mse; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs
r8646 r8664 47 47 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 48 var solution = SymbolicExpressionTreeParameter.ActualValue; 49 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows );49 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 50 QualityParameter.ActualValue = new DoubleValue(quality); 51 51 return base.Apply(); 52 52 } 53 53 54 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows ) {54 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData 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 r2 = OnlinePearsonsRSquaredCalculator.Calculate(boundedEstimationValues, originalValues, out errorState); 60 if (errorState != OnlineCalculatorError.None) return 0.0; 61 else return r2; 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 if (errorState != OnlineCalculatorError.None) return double.NaN; 70 return r2; 62 71 } 63 72 … … 65 74 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 66 75 EstimationLimitsParameter.ExecutionContext = context; 76 ApplyLinearScalingParameter.ExecutionContext = context; 67 77 68 double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows );78 double r2 = 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 r2; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePenaltyScoreEvaluator.cs
r8594 r8664 86 86 EstimationLimitsParameter.ExecutionContext = context; 87 87 ModelCreatorParameter.ExecutionContext = context; 88 ApplyLinearScalingParameter.ExecutionContext = context; 88 89 89 90 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 91 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, problemData, problemData.TargetVariable); 90 92 model.RecalculateModelParameters(problemData, rows); 91 93 double penalty = Calculate(model, problemData, rows); … … 94 96 EstimationLimitsParameter.ExecutionContext = null; 95 97 ModelCreatorParameter.ExecutionContext = null; 98 ApplyLinearScalingParameter.ExecutionContext = null; 96 99 97 100 return penalty; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r8594 r8664 66 66 Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator())); 67 67 68 ApplyLinearScalingParameter.Value.Value = false; 68 69 EstimationLimitsParameter.Hidden = true; 69 70 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs
r8594 r8664 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; … … 39 38 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 40 39 private const string EstimationLimitsParameterName = "UpperEstimationLimit"; 41 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";42 40 #region parameter properties 43 41 public ILookupParameter<IClassificationProblemData> ProblemDataParameter { … … 56 54 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 57 55 } 58 public IValueParameter<BoolValue> ApplyLinearScalingParameter {59 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }60 }61 56 #endregion 62 #region properties 63 public BoolValue ApplyLinearScaling { 64 get { return ApplyLinearScalingParameter.Value; } 65 } 66 #endregion 57 67 58 68 59 [StorableConstructor] … … 75 66 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 76 67 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model.")); 77 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));78 68 } 79 69 … … 89 79 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 90 80 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 91 if (ApplyLinearScaling .Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);81 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable); 92 82 93 83 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs
r8594 r8664 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; … … 34 33 [StorableClass] 35 34 public sealed class SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IClassificationProblemData, ISymbolicClassificationSolution>, ISymbolicClassificationModelCreatorOperator { 36 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";37 35 private const string ModelCreatorParameterName = "ModelCreator"; 38 36 #region parameter properties 39 public IValueParameter<BoolValue> ApplyLinearScalingParameter {40 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }41 }42 37 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 43 38 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } … … 48 43 #endregion 49 44 50 #region properties51 public BoolValue ApplyLinearScaling {52 get { return ApplyLinearScalingParameter.Value; }53 }54 #endregion55 56 45 [StorableConstructor] 57 46 private SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 59 48 public SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer() 60 49 : base() { 61 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));62 50 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 63 51 } … … 74 62 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) { 75 63 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 76 if (ApplyLinearScaling .Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);64 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable); 77 65 78 66 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs
r8594 r8664 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, ISymbolicClassificationModelCreatorOperator { 37 36 private const string EstimationLimitsParameterName = "EstimationLimits"; 38 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";39 37 private const string ModelCreatorParameterName = "ModelCreator"; 40 38 … … 42 40 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter { 43 41 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 44 }45 public IValueParameter<BoolValue> ApplyLinearScalingParameter {46 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }47 42 } 48 43 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { … … 54 49 #endregion 55 50 56 #region properties57 public BoolValue ApplyLinearScaling {58 get { return ApplyLinearScalingParameter.Value; }59 }60 #endregion61 51 [StorableConstructor] 62 52 private SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 65 55 : base() { 66 56 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model.")); 67 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));68 57 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 69 58 } … … 80 69 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 81 70 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 82 if (ApplyLinearScaling .Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);71 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable); 83 72 84 73 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer.cs
r8594 r8664 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; … … 34 33 [StorableClass] 35 34 public sealed class SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData>, ISymbolicClassificationModelCreatorOperator { 36 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";37 35 private const string ModelCreatorParameterName = "ModelCreator"; 38 36 #region parameter properties 39 public IValueParameter<BoolValue> ApplyLinearScalingParameter {40 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }41 }42 37 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 43 38 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } … … 48 43 #endregion 49 44 50 #region properties51 public BoolValue ApplyLinearScaling {52 get { return ApplyLinearScalingParameter.Value; }53 }54 #endregion55 56 45 [StorableConstructor] 57 46 private SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 59 48 public SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer() 60 49 : base() { 61 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));62 50 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 63 51 } … … 74 62 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) { 75 63 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 76 if (ApplyLinearScaling .Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);64 if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable); 77 65 78 66 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs
r8623 r8664 62 62 return CreateClassificationSolution(problemData); 63 63 } 64 65 #region scaling66 public static void Scale(ISymbolicClassificationModel model, IClassificationProblemData problemData) {67 var dataset = problemData.Dataset;68 var targetVariable = problemData.TargetVariable;69 var rows = problemData.TrainingIndices;70 var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows);71 var targetValues = dataset.GetDoubleValues(targetVariable, rows);72 double alpha;73 double beta;74 OnlineCalculatorError errorState;75 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta, out errorState);76 if (errorState != OnlineCalculatorError.None) return;77 78 ConstantTreeNode alphaTreeNode = null;79 ConstantTreeNode betaTreeNode = null;80 // check if model has been scaled previously by analyzing the structure of the tree81 var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0);82 if (startNode.GetSubtree(0).Symbol is Addition) {83 var addNode = startNode.GetSubtree(0);84 if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {85 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode;86 var mulNode = addNode.GetSubtree(0);87 if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {88 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode;89 }90 }91 }92 // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes93 if (alphaTreeNode != null && betaTreeNode != null) {94 betaTreeNode.Value *= beta;95 alphaTreeNode.Value *= beta;96 alphaTreeNode.Value += alpha;97 } else {98 var mainBranch = startNode.GetSubtree(0);99 startNode.RemoveSubtree(0);100 var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha);101 startNode.AddSubtree(scaledMainBranch);102 }103 }104 105 private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) {106 if (alpha.IsAlmost(0.0)) {107 return treeNode;108 } else {109 var addition = new Addition();110 var node = addition.CreateTreeNode();111 var alphaConst = MakeConstant(alpha);112 node.AddSubtree(treeNode);113 node.AddSubtree(alphaConst);114 return node;115 }116 }117 118 private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {119 if (beta.IsAlmost(1.0)) {120 return treeNode;121 } else {122 var multipliciation = new Multiplication();123 var node = multipliciation.CreateTreeNode();124 var betaConst = MakeConstant(beta);125 node.AddSubtree(treeNode);126 node.AddSubtree(betaConst);127 return node;128 }129 }130 131 private static ISymbolicExpressionTreeNode MakeConstant(double c) {132 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();133 node.Value = c;134 return node;135 }136 #endregion137 64 } 138 65 }
Note: See TracChangeset
for help on using the changeset viewer.