Changeset 4128 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs
- Timestamp:
- 08/02/10 15:21:07 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs
r4127 r4128 37 37 private const string QualityVarianceParameterName = "QualityVariance"; 38 38 private const string QualitySamplesParameterName = "QualitySamples"; 39 private const string DecompositionBiasParameterName = "QualityDecompositionBias"; 40 private const string DecompositionVarianceParameterName = "QualityDecompositionVariance"; 41 private const string DecompositionCovarianceParameterName = "QualityDecompositionCovariance"; 42 private const string ApplyScalingParameterName = "ApplyScaling"; 39 43 40 44 #region parameter properties 45 public IValueLookupParameter<BoolValue> ApplyScalingParameter { 46 get { return (IValueLookupParameter<BoolValue>)Parameters[ApplyScalingParameterName]; } 47 } 41 48 public ILookupParameter<DoubleValue> AlphaParameter { 42 49 get { return (ILookupParameter<DoubleValue>)Parameters["Alpha"]; } … … 51 58 get { return (ILookupParameter<IntValue>)Parameters[QualitySamplesParameterName]; } 52 59 } 60 public ILookupParameter<DoubleValue> DecompositionBiasParameter { 61 get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionBiasParameterName]; } 62 } 63 public ILookupParameter<DoubleValue> DecompositionVarianceParameter { 64 get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionVarianceParameterName]; } 65 } 66 public ILookupParameter<DoubleValue> DecompositionCovarianceParameter { 67 get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionCovarianceParameterName]; } 68 } 53 69 54 70 #endregion 55 71 #region properties 72 public BoolValue ApplyScaling { 73 get { return ApplyScalingParameter.ActualValue; } 74 } 56 75 public DoubleValue Alpha { 57 76 get { return AlphaParameter.ActualValue; } … … 73 92 public SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator() 74 93 : base() { 94 Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyScalingParameterName, "Determines if the estimated values should be scaled.", new BoolValue(true))); 75 95 Parameters.Add(new LookupParameter<DoubleValue>("Alpha", "Alpha parameter for linear scaling of the estimated values.")); 76 96 Parameters.Add(new LookupParameter<DoubleValue>("Beta", "Beta parameter for linear scaling of the estimated values.")); 77 97 Parameters.Add(new LookupParameter<DoubleValue>(QualityVarianceParameterName, "A parameter which stores the variance of the squared errors.")); 78 98 Parameters.Add(new LookupParameter<IntValue>(QualitySamplesParameterName, " The number of evaluated samples.")); 99 Parameters.Add(new LookupParameter<DoubleValue>(DecompositionBiasParameterName, "A parameter which stores the relativ bias of the MSE.")); 100 Parameters.Add(new LookupParameter<DoubleValue>(DecompositionVarianceParameterName, "A parameter which stores the relativ bias of the MSE.")); 101 Parameters.Add(new LookupParameter<DoubleValue>(DecompositionCovarianceParameterName, "A parameter which stores the relativ bias of the MSE.")); 79 102 } 80 103 … … 83 106 double meanSE, varianceSE; 84 107 int count; 85 double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha, out meanSE, out varianceSE, out count); 86 Alpha = new DoubleValue(alpha); 87 Beta = new DoubleValue(beta); 108 double bias, variance, covariance; 109 double mse; 110 if (ApplyScaling.Value) { 111 mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance); 112 Alpha = new DoubleValue(alpha); 113 Beta = new DoubleValue(beta); 114 } else { 115 mse = CalculateWithScaling(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, 1, 0, out meanSE, out varianceSE, out count, out bias, out variance, out covariance); 116 } 88 117 QualityVariance = new DoubleValue(varianceSE); 89 118 QualitySamples = new IntValue(count); 119 DecompositionBiasParameter.ActualValue = new DoubleValue(bias / meanSE); 120 DecompositionVarianceParameter.ActualValue = new DoubleValue(variance / meanSE); 121 DecompositionCovarianceParameter.ActualValue = new DoubleValue(covariance / meanSE); 90 122 return mse; 91 123 } 92 124 93 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha, out double meanSE, out double varianceSE, out int count ) {125 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha, out double meanSE, out double varianceSE, out int count, out double bias, out double variance, out double covariance) { 94 126 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 95 127 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 96 128 CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha); 97 129 98 return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count );99 } 100 101 public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha, out double meanSE, out double varianceSE, out int count ) {130 return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance); 131 } 132 133 public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha, out double meanSE, out double varianceSE, out int count, out double bias, out double variance, out double covariance) { 102 134 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 103 135 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); … … 105 137 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 106 138 OnlineMeanAndVarianceCalculator seEvaluator = new OnlineMeanAndVarianceCalculator(); 139 OnlineMeanAndVarianceCalculator originalMeanEvaluator = new OnlineMeanAndVarianceCalculator(); 140 OnlineMeanAndVarianceCalculator estimatedMeanEvaluator = new OnlineMeanAndVarianceCalculator(); 141 OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator(); 107 142 108 143 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { … … 116 151 error *= error; 117 152 seEvaluator.Add(error); 153 originalMeanEvaluator.Add(original); 154 estimatedMeanEvaluator.Add(estimated); 155 r2Evaluator.Add(original, estimated); 118 156 } 119 157 … … 124 162 varianceSE = seEvaluator.Variance; 125 163 count = seEvaluator.Count; 164 bias = (originalMeanEvaluator.Mean - estimatedMeanEvaluator.Mean); 165 bias *= bias; 166 167 double sO = Math.Sqrt(originalMeanEvaluator.Variance); 168 double sE = Math.Sqrt(estimatedMeanEvaluator.Variance); 169 variance = sO - sE; 170 variance *= variance; 171 double r = Math.Sqrt(r2Evaluator.RSquared); 172 covariance = 2 * sO * sE * (1 - r); 126 173 return seEvaluator.Mean; 127 174 }
Note: See TracChangeset
for help on using the changeset viewer.