Changeset 12848 for branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Timestamp:
- 08/12/15 10:35:02 (9 years ago)
- Location:
- branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNestedTreeSizeEvaluator.cs
r12147 r12848 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Parameters;30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 30 … … 34 33 [StorableClass] 35 34 public class PearsonRSquaredNestedTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 36 private const string useConstantOptimizationParameterName = "Use constant optimization";37 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {38 get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }39 }40 public bool UseConstantOptimization {41 get { return UseConstantOptimizationParameter.Value.Value; }42 set { UseConstantOptimizationParameter.Value.Value = value; }43 }44 45 35 [StorableConstructor] 46 36 protected PearsonRSquaredNestedTreeSizeEvaluator(bool deserializing) : base(deserializing) { } … … 52 42 } 53 43 54 public PearsonRSquaredNestedTreeSizeEvaluator() 55 : base() { 56 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 57 } 44 public PearsonRSquaredNestedTreeSizeEvaluator() : base() { } 58 45 59 46 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } … … 71 58 } 72 59 73 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value );60 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 74 61 QualitiesParameter.ActualValue = new DoubleArray(qualities); 75 62 return base.InstrumentedApply(); 76 63 } 77 64 78 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling ) {65 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 79 66 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 80 r2 = Math.Round(r2, 3); 67 if (decimalPlaces >= 0) 68 r2 = Math.Round(r2, decimalPlaces); 81 69 return new double[2] { r2, solution.IterateNodesPostfix().Sum(n => n.GetLength()) }; 82 70 } … … 87 75 ApplyLinearScalingParameter.ExecutionContext = context; 88 76 89 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value );77 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 90 78 91 79 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNumberOfVariablesEvaluator.cs
r12147 r12848 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Security.Cryptography;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core; 28 27 using HeuristicLab.Data; 29 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 using HeuristicLab.Parameters;31 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 30 … … 35 33 [StorableClass] 36 34 public class PearsonRSquaredNumberOfVariablesEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 37 private const string useConstantOptimizationParameterName = "Use constant optimization";38 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {39 get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }40 }41 public bool UseConstantOptimization {42 get { return UseConstantOptimizationParameter.Value.Value; }43 set { UseConstantOptimizationParameter.Value.Value = value; }44 }45 46 35 [StorableConstructor] 47 36 protected PearsonRSquaredNumberOfVariablesEvaluator(bool deserializing) : base(deserializing) { } … … 53 42 } 54 43 55 public PearsonRSquaredNumberOfVariablesEvaluator() 56 : base() { 57 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 58 } 44 public PearsonRSquaredNumberOfVariablesEvaluator() : base() { } 59 45 60 46 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } … … 71 57 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower); 72 58 } 73 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value );59 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 74 60 QualitiesParameter.ActualValue = new DoubleArray(qualities); 75 61 return base.InstrumentedApply(); 76 62 } 77 63 78 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling ) {64 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 79 65 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 80 r2 = Math.Round(r2, 3); 66 if (decimalPlaces >= 0) 67 r2 = Math.Round(r2, decimalPlaces); 81 68 return new double[2] { r2, solution.IterateNodesPostfix().OfType<VariableTreeNode>().Count() }; 82 69 } … … 87 74 ApplyLinearScalingParameter.ExecutionContext = context; 88 75 89 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value );76 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 90 77 91 78 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredTreeComplexityEvaluator.cs
r12147 r12848 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Parameters;29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 29 … … 33 32 [StorableClass] 34 33 public class PearsonRSquaredTreeComplexityEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 35 private const string useConstantOptimizationParameterName = "Use constant optimization";36 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {37 get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }38 }39 public bool UseConstantOptimization {40 get { return UseConstantOptimizationParameter.Value.Value; }41 set { UseConstantOptimizationParameter.Value.Value = value; }42 }43 44 34 [StorableConstructor] 45 35 protected PearsonRSquaredTreeComplexityEvaluator(bool deserializing) : base(deserializing) { } … … 51 41 } 52 42 53 public PearsonRSquaredTreeComplexityEvaluator() 54 : base() { 55 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 56 } 57 58 [StorableHook(HookType.AfterDeserialization)] 59 private void AfterDeserialization() { 60 if (!Parameters.ContainsKey(useConstantOptimizationParameterName)) { 61 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 62 } 63 } 43 public PearsonRSquaredTreeComplexityEvaluator() : base() { } 64 44 65 45 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } … … 76 56 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower); 77 57 } 78 double[] qualities = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling );58 double[] qualities = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling, DecimalPlaces); 79 59 QualitiesParameter.ActualValue = new DoubleArray(qualities); 80 60 return base.InstrumentedApply(); 81 61 } 82 62 83 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling ) {63 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 84 64 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 85 r2 = Math.Round(r2, 3); 65 if (decimalPlaces >= 0) 66 r2 = Math.Round(r2, decimalPlaces); 86 67 return new double[2] { r2, SymbolicDataAnalysisModelComplexityAnalyzer.CalculateComplexity(solution.Root.GetSubtree(0).GetSubtree(0)) }; 87 68 } … … 92 73 ApplyLinearScalingParameter.ExecutionContext = context; 93 74 94 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value );75 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 95 76 96 77 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveEvaluator.cs
r12130 r12848 22 22 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 26 using HeuristicLab.Parameters; 24 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 25 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 [StorableClass] 26 31 public abstract class SymbolicRegressionMultiObjectiveEvaluator : SymbolicDataAnalysisMultiObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionMultiObjectiveEvaluator { 32 private const string DecimalPlacesParameterName = "Decimal Places"; 33 private const string UseConstantOptimizationParameterName = "Use constant optimization"; 34 35 public IFixedValueParameter<IntValue> DecimalPlacesParameter { 36 get { return (IFixedValueParameter<IntValue>)Parameters[DecimalPlacesParameterName]; } 37 } 38 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter { 39 get { return (IFixedValueParameter<BoolValue>)Parameters[UseConstantOptimizationParameterName]; } 40 } 41 42 public int DecimalPlaces { 43 get { return DecimalPlacesParameter.Value.Value; } 44 set { DecimalPlacesParameter.Value.Value = value; } 45 } 46 public bool UseConstantOptimization { 47 get { return UseConstantOptimizationParameter.Value.Value; } 48 set { UseConstantOptimizationParameter.Value.Value = value; } 49 } 50 27 51 [StorableConstructor] 28 52 protected SymbolicRegressionMultiObjectiveEvaluator(bool deserializing) : base(deserializing) { } … … 31 55 } 32 56 33 protected SymbolicRegressionMultiObjectiveEvaluator() : base() { } 57 protected SymbolicRegressionMultiObjectiveEvaluator() 58 : base() { 59 Parameters.Add(new FixedValueParameter<IntValue>(DecimalPlacesParameterName, "The number of decimal places used for rounding the quality values.", new IntValue(5)) { Hidden = true }); 60 Parameters.Add(new FixedValueParameter<BoolValue>(UseConstantOptimizationParameterName, "", new BoolValue(false))); 61 } 62 63 [StorableHook(HookType.AfterDeserialization)] 64 private void AfterDeserialization() { 65 if (!Parameters.ContainsKey(UseConstantOptimizationParameterName)) { 66 Parameters.Add(new FixedValueParameter<BoolValue>(UseConstantOptimizationParameterName, "", new BoolValue(false))); 67 } 68 if (!Parameters.ContainsKey(DecimalPlacesParameterName)) { 69 Parameters.Add(new FixedValueParameter<IntValue>(DecimalPlacesParameterName, "The number of decimal places used for rounding the quality values.", new IntValue(-1)) { Hidden = true }); 70 } 71 } 34 72 } 35 73 } -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r12130 r12848 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[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 50 var problemData = ProblemDataParameter.ActualValue; 51 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 52 var estimationLimits = EstimationLimitsParameter.ActualValue; 53 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 54 55 if (UseConstantOptimization) { 56 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower); 57 } 58 59 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 50 60 QualitiesParameter.ActualValue = new DoubleArray(qualities); 51 61 return base.InstrumentedApply(); 52 62 } 53 63 54 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 57 OnlineCalculatorError errorState; 64 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 65 var mse = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, 66 upperEstimationLimit, problemData, rows, applyLinearScaling); 58 67 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 } 69 if (errorState != OnlineCalculatorError.None) mse = double.NaN; 68 if (decimalPlaces >= 0) 69 mse = Math.Round(mse, decimalPlaces); 70 70 71 return new double[2] { mse, solution.Length }; 71 72 } … … 76 77 ApplyLinearScalingParameter.ExecutionContext = context; 77 78 78 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value );79 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 79 80 80 81 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r12147 r12848 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Parameters;29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 29 … … 33 32 [StorableClass] 34 33 public class SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 35 private const string useConstantOptimizationParameterName = "Use constant optimization";36 public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {37 get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }38 }39 public bool UseConstantOptimization {40 get { return UseConstantOptimizationParameter.Value.Value; }41 set { UseConstantOptimizationParameter.Value.Value = value; }42 }43 44 34 [StorableConstructor] 45 35 protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(bool deserializing) : base(deserializing) { } … … 51 41 } 52 42 53 public SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base() 54 { 55 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 56 } 57 58 [StorableHook(HookType.AfterDeserialization)] 59 private void AfterDeserialization() { 60 if (!Parameters.ContainsKey(useConstantOptimizationParameterName)) { 61 Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false))); 62 } 63 } 43 public SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base() { } 64 44 65 45 public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } } … … 76 56 SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower); 77 57 } 78 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value );58 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 79 59 QualitiesParameter.ActualValue = new DoubleArray(qualities); 80 60 return base.InstrumentedApply(); 81 61 } 82 62 83 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling ) {63 public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) { 84 64 double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 85 r2 = Math.Round(r2, 3); 65 if (decimalPlaces >= 0) 66 r2 = Math.Round(r2, decimalPlaces); 86 67 return new double[2] { r2, solution.Length }; 87 68 } … … 92 73 ApplyLinearScalingParameter.ExecutionContext = context; 93 74 94 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value );75 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces); 95 76 96 77 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Plugin.cs.frame
r12130 r12848 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4. 7.$WCREV$")]28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4.8.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")] -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Properties/AssemblyInfo.cs.frame
r12130 r12848 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.4.0.0")] 55 [assembly: AssemblyFileVersion("3.4. 7.$WCREV$")]55 [assembly: AssemblyFileVersion("3.4.8.$WCREV$")] -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r12130 r12848 59 59 OnlineCalculatorError errorState; 60 60 61 double r 2;61 double r; 62 62 if (applyLinearScaling) { 63 var r 2Calculator = new OnlinePearsonsRSquaredCalculator();64 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r 2Calculator, problemData.Dataset.Rows);65 errorState = r 2Calculator.ErrorState;66 r 2 = r2Calculator.RSquared;63 var rCalculator = new OnlinePearsonsRCalculator(); 64 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows); 65 errorState = rCalculator.ErrorState; 66 r = rCalculator.R; 67 67 } else { 68 68 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 69 r 2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);69 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 70 70 } 71 71 if (errorState != OnlineCalculatorError.None) return double.NaN; 72 return r 2;72 return r*r; 73 73 } 74 74 -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningAnalyzer.cs
r12547 r12848 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 49 50 Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator()))); 50 51 } 52 53 [StorableHook(HookType.AfterDeserialization)] 54 private void AfterDeserialization() { 55 // BackwardsCompatibility3.3 56 57 #region Backwards compatible code, remove with 3.4 58 if (Parameters.ContainsKey(PruningOperatorParameterName)) { 59 var oldParam = Parameters[PruningOperatorParameterName] as ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>; 60 if (oldParam != null) { 61 Parameters.Remove(oldParam); 62 Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator()))); 63 } 64 } else { 65 // not yet contained 66 Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator()))); 67 } 68 69 70 if (Parameters.ContainsKey("PruneOnlyZeroImpactNodes")) { 71 PruningOperator.PruneOnlyZeroImpactNodes = ((IFixedValueParameter<BoolValue>)Parameters["PruneOnlyZeroImpactNodes"]).Value.Value; 72 Parameters.Remove(Parameters["PruneOnlyZeroImpactNodes"]); 73 } 74 if (Parameters.ContainsKey("ImpactThreshold")) { 75 PruningOperator.NodeImpactThreshold = ((IFixedValueParameter<DoubleValue>)Parameters["ImpactThreshold"]).Value.Value; 76 Parameters.Remove(Parameters["ImpactThreshold"]); 77 } 78 if (Parameters.ContainsKey("ImpactValuesCalculator")) { 79 PruningOperator.ImpactValuesCalculator = ((ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>)Parameters["ImpactValuesCalculator"]).Value; 80 Parameters.Remove(Parameters["ImpactValuesCalculator"]); 81 } 82 83 #endregion 84 } 51 85 } 52 86 } -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs
r12547 r12848 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 31 … … 33 34 [Item("SymbolicRegressionPruningOperator", "An operator which prunes symbolic regression trees.")] 34 35 public class SymbolicRegressionPruningOperator : SymbolicDataAnalysisExpressionPruningOperator { 36 private const string EvaluatorParameterName = "Evaluator"; 37 38 #region parameter properties 39 public ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter { 40 get { return (ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; } 41 } 42 #endregion 43 35 44 protected SymbolicRegressionPruningOperator(SymbolicRegressionPruningOperator original, Cloner cloner) 36 45 : base(original, cloner) { … … 45 54 public SymbolicRegressionPruningOperator(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactValuesCalculator) 46 55 : base(impactValuesCalculator) { 56 Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName)); 57 } 58 59 [StorableHook(HookType.AfterDeserialization)] 60 private void AfterDeserialization() { 61 // BackwardsCompatibility3.3 62 #region Backwards compatible code, remove with 3.4 63 base.ImpactValuesCalculator = new SymbolicRegressionSolutionImpactValuesCalculator(); 64 if (!Parameters.ContainsKey(EvaluatorParameterName)) { 65 Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName)); 66 } 67 #endregion 47 68 } 48 69 … … 52 73 53 74 protected override double Evaluate(IDataAnalysisModel model) { 54 var regressionModel = (I RegressionModel)model;75 var regressionModel = (ISymbolicRegressionModel)model; 55 76 var regressionProblemData = (IRegressionProblemData)ProblemDataParameter.ActualValue; 56 var rows = Enumerable.Range(FitnessCalculationPartitionParameter.ActualValue.Start, FitnessCalculationPartitionParameter.ActualValue.Size); 57 return Evaluate(regressionModel, regressionProblemData, rows); 58 } 59 60 private static double Evaluate(IRegressionModel model, IRegressionProblemData problemData, 61 IEnumerable<int> rows) { 62 var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values 63 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 64 OnlineCalculatorError errorState; 65 var quality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState); 66 if (errorState != OnlineCalculatorError.None) return double.NaN; 67 return quality; 77 var evaluator = EvaluatorParameter.ActualValue; 78 var fitnessEvaluationPartition = FitnessCalculationPartitionParameter.ActualValue; 79 var rows = Enumerable.Range(fitnessEvaluationPartition.Start, fitnessEvaluationPartition.Size); 80 return evaluator.Evaluate(this.ExecutionContext, regressionModel.SymbolicExpressionTree, regressionProblemData, rows); 68 81 } 69 82 … … 72 85 var model = new SymbolicRegressionModel(clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper); 73 86 var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); // skip the nodes corresponding to the ProgramRootSymbol and the StartSymbol 74 double quality = Evaluate(model, problemData, rows); 87 88 double qualityForImpactsCalculation = double.NaN; // pass a NaN value initially so the impact calculator will calculate the quality 75 89 76 90 for (int i = 0; i < nodes.Count; ++i) { … … 79 93 80 94 double impactValue, replacementValue; 81 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality); 95 double newQualityForImpactsCalculation; 96 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation); 82 97 83 98 if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue; … … 90 105 i += node.GetLength() - 1; // skip subtrees under the node that was folded 91 106 92 quality -= impactValue;107 qualityForImpactsCalculation = newQualityForImpactsCalculation; 93 108 } 94 109 return model.SymbolicExpressionTree; -
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs
r12130 r12848 48 48 } 49 49 50 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality= double.NaN) {51 double impactValue, replacementValue ;52 CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, o riginalQuality);50 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN) { 51 double impactValue, replacementValue, newQualityForImpactsCalculation; 52 CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation); 53 53 return impactValue; 54 54 } 55 55 56 56 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, 57 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, 58 double originalQuality= Double.NaN) {57 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, 58 double qualityForImpactsCalculation = Double.NaN) { 59 59 var regressionModel = (ISymbolicRegressionModel)model; 60 60 var regressionProblemData = (IRegressionProblemData)problemData; … … 64 64 65 65 OnlineCalculatorError errorState; 66 if (double.IsNaN(originalQuality)) { 67 var originalValues = regressionModel.GetEstimatedValues(dataset, rows); 68 originalQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalValues, out errorState); 69 if (errorState != OnlineCalculatorError.None) originalQuality = 0.0; 70 } 66 if (double.IsNaN(qualityForImpactsCalculation)) 67 qualityForImpactsCalculation = CalculateQualityForImpacts(regressionModel, regressionProblemData, rows); 71 68 72 69 replacementValue = CalculateReplacementValue(regressionModel, node, regressionProblemData, rows); … … 83 80 84 81 var estimatedValues = tempModel.GetEstimatedValues(dataset, rows); 85 double newQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState); 86 if (errorState != OnlineCalculatorError.None) newQuality = 0.0; 82 double r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState); 83 if (errorState != OnlineCalculatorError.None) r = 0.0; 84 newQualityForImpactsCalculation = r * r; 87 85 88 impactValue = originalQuality - newQuality; 86 impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation; 87 } 88 89 public static double CalculateQualityForImpacts(ISymbolicRegressionModel model, IRegressionProblemData problemData, IEnumerable<int> rows) { 90 var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values 91 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 92 OnlineCalculatorError errorState; 93 var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState); 94 var quality = r * r; 95 if (errorState != OnlineCalculatorError.None) return double.NaN; 96 return quality; 89 97 } 90 98 }
Note: See TracChangeset
for help on using the changeset viewer.