Changeset 4555 for branches/DataAnalysis
- Timestamp:
- 10/05/10 16:30:57 (14 years ago)
- Location:
- branches/DataAnalysis
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Symbolic/Analyzer/ValidationBestScaledSymbolicTimeSeriesPrognosisSolutionAnalyzer.cs
r4475 r4555 344 344 int dimension = selectedTargetVariables.Count(); 345 345 346 IEnumerable<double[]> oneStepPredictions = 347 SymbolicExpressionTreeInterpreter.GetSymbolicExpressionTreeValues(tree, ProblemData.Dataset, selectedTargetVariables, trainingRows, 1); 348 IEnumerable<double[]> originalValues = from row in trainingRows 349 select (from targetVariable in selectedTargetVariables 350 select ProblemData.Dataset[targetVariable, row]).ToArray(); 346 IEnumerable<IEnumerable<double>> oneStepPredictions = 347 SymbolicExpressionTreeInterpreter.GetSymbolicExpressionTreeValues(tree, ProblemData.Dataset, selectedTargetVariables, trainingRows, 1) 348 .Cast<IEnumerable<double>>(); 349 IEnumerable<IEnumerable<double>> originalValues = from row in trainingRows 350 select (from targetVariable in selectedTargetVariables 351 select ProblemData.Dataset[targetVariable, row]); 351 352 alpha = new double[dimension]; 352 353 beta = new double[dimension]; -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Symbolic/Evaluators/SymbolicTimeSeriesPrognosisMahalanobisEvaluator.cs
r4475 r4555 60 60 double quality; 61 61 62 Dataset dataset = problemData.Dataset; 62 63 // calculate scaling parameters based on one-step-predictions 63 IEnumerable<string> selectedTargetVariables = from item in problemData.TargetVariables64 where problemData.TargetVariables.ItemChecked(item)65 select item.Value;64 IEnumerable<string> selectedTargetVariables = (from item in problemData.TargetVariables 65 where problemData.TargetVariables.ItemChecked(item) 66 select item.Value).ToArray(); 66 67 int dimension = selectedTargetVariables.Count(); 67 68 68 IEnumerable<double[]> oneStepPredictions = 69 interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, selectedTargetVariables, rows, 1); 70 IEnumerable<double[]> originalValues = from row in rows 71 select (from targetVariable in selectedTargetVariables 72 select problemData.Dataset[targetVariable, row]).ToArray(); 69 IEnumerable<int> selectedTargetVariableIndexes = (from targetVariable in selectedTargetVariables 70 select dataset.GetVariableIndex(targetVariable)).ToArray(); 71 IEnumerable<IEnumerable<double>> oneStepPredictions = 72 interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, selectedTargetVariables, rows, 1) 73 .Cast<IEnumerable<double>>(); 74 IEnumerable<IEnumerable<double>> originalValues = from row in rows 75 select (from targetVariableIndex in selectedTargetVariableIndexes 76 select dataset[row, targetVariableIndex]); 73 77 alpha = new double[dimension]; 74 78 beta = new double[dimension]; … … 89 93 IEnumerable<int> rows, int predictionHorizon, 90 94 DoubleArray lowerEstimationLimit, DoubleArray upperEstimationLimit, 91 double[] alpha, double[] beta) {95 double[] beta, double[] alpha) { 92 96 97 Dataset dataset = problemData.Dataset; 93 98 94 IEnumerable<string> selectedTargetVariables = from targetVariable in problemData.TargetVariables95 where problemData.TargetVariables.ItemChecked(targetVariable)96 select targetVariable.Value;99 IEnumerable<string> selectedTargetVariables = (from targetVariable in problemData.TargetVariables 100 where problemData.TargetVariables.ItemChecked(targetVariable) 101 select targetVariable.Value).ToArray(); 97 102 103 IEnumerable<int> selectedTargetVariableIndexes = (from targetVariable in selectedTargetVariables 104 select dataset.GetVariableIndex(targetVariable)).ToArray(); 98 105 IEnumerable<double[]> estimatedValues = 99 interpreter.GetScaledSymbolicExpressionTreeValues(tree, problemData.Dataset, selectedTargetVariables,106 interpreter.GetScaledSymbolicExpressionTreeValues(tree, dataset, selectedTargetVariables, 100 107 rows, predictionHorizon, beta, alpha); 101 108 102 IEnumerable< double[]> originalValues = from row in rows103 from step in Enumerable.Range(0, predictionHorizon)104 select (from targetVariable in selectedTargetVariables105 select problemData.Dataset[targetVariable, row + step]).ToArray();109 IEnumerable<IEnumerable<double>> originalValues = from row in rows 110 from step in Enumerable.Range(0, predictionHorizon) 111 select (from targetVariableIndex in selectedTargetVariableIndexes 112 select dataset[row + step, targetVariableIndex]); 106 113 107 114 OnlineMeanMahalanobisDistanceEvaluator evaluator = new OnlineMeanMahalanobisDistanceEvaluator(); 108 IEnumerable<double>[] targetValues = (from targetVariable in problemData.TargetVariables.CheckedItems 109 select problemData.Dataset.GetEnumeratedVariableValues(targetVariable.Value.Value, rows)) 115 // for covariance calculation: array of variables 116 IEnumerable<double>[] targetValues = (from targetVariableIndex in selectedTargetVariableIndexes 117 select dataset.GetEnumeratedVariableValues(targetVariableIndex, rows)) 110 118 .ToArray(); 111 119 evaluator.InitializeCovarianceMatrixFromSamples(targetValues); … … 114 122 var originalValuesEnumerator = originalValues.GetEnumerator(); 115 123 while (originalValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) { 116 double[]currentOriginal = originalValuesEnumerator.Current;124 IEnumerable<double> currentOriginal = originalValuesEnumerator.Current; 117 125 double[] currentEstimated = estimatedValuesEnumerator.Current; 126 // limit estimated values to bounds 118 127 for (int i = 0; i < currentEstimated.Length; i++) { 119 128 if (double.IsNaN(currentEstimated[i])) currentEstimated[i] = upperEstimationLimit[i]; -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Symbolic/Evaluators/SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.cs
r4475 r4555 56 56 double quality; 57 57 58 Dataset dataset = problemData.Dataset; 58 59 // calculate scaling parameters based on one-step-predictions 59 IEnumerable<string> selectedTargetVariables = from item in problemData.TargetVariables60 where problemData.TargetVariables.ItemChecked(item)61 select item.Value;60 IEnumerable<string> selectedTargetVariables = (from item in problemData.TargetVariables 61 where problemData.TargetVariables.ItemChecked(item) 62 select item.Value).ToArray(); 62 63 int dimension = selectedTargetVariables.Count(); 63 64 64 IEnumerable<double[]> oneStepPredictions = 65 interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, selectedTargetVariables, rows, 1); 66 IEnumerable<double[]> originalValues = from row in rows 67 select (from targetVariable in selectedTargetVariables 68 select problemData.Dataset[targetVariable, row]).ToArray(); 65 IEnumerable<int> selectedTargetVariableIndexes = (from targetVariable in selectedTargetVariables 66 select dataset.GetVariableIndex(targetVariable)).ToArray(); 67 IEnumerable<IEnumerable<double>> oneStepPredictions = 68 interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, selectedTargetVariables, rows, 1).Cast<IEnumerable<double>>(); 69 IEnumerable<IEnumerable<double>> originalValues = from row in rows 70 select (from targetVariableIndex in selectedTargetVariableIndexes 71 select dataset[row, targetVariableIndex]); 69 72 alpha = new double[dimension]; 70 73 beta = new double[dimension]; … … 85 88 DoubleArray lowerEstimationLimit, DoubleArray upperEstimationLimit, 86 89 double[] beta, double[] alpha) { 87 IEnumerable<string> selectedTargetVariables = from targetVariable in problemData.TargetVariables 88 where problemData.TargetVariables.ItemChecked(targetVariable) 89 select targetVariable.Value; 90 Dataset dataset = problemData.Dataset; 91 IEnumerable<string> selectedTargetVariables = (from targetVariable in problemData.TargetVariables 92 where problemData.TargetVariables.ItemChecked(targetVariable) 93 select targetVariable.Value).ToArray(); 94 IEnumerable<int> selectedTargetVariableIndexes = (from targetVariable in selectedTargetVariables 95 select dataset.GetVariableIndex(targetVariable)).ToArray(); 90 96 91 97 IEnumerable<double[]> estimatedValues = 92 interpreter.GetScaledSymbolicExpressionTreeValues(tree, problemData.Dataset, selectedTargetVariables,98 interpreter.GetScaledSymbolicExpressionTreeValues(tree, dataset, selectedTargetVariables, 93 99 rows, predictionHorizon, beta, alpha); 94 100 95 IEnumerable< double[]> originalValues = from row in rows96 from step in Enumerable.Range(0, predictionHorizon)97 select (from targetVariable in selectedTargetVariables98 select problemData.Dataset[targetVariable, row + step]).ToArray();101 IEnumerable<IEnumerable<double>> originalValues = from row in rows 102 from step in Enumerable.Range(0, predictionHorizon) 103 select (from targetVariableIndex in selectedTargetVariableIndexes 104 select dataset[row + step, targetVariableIndex]); 99 105 100 106 var evaluator = new OnlineMultiVariateEvaluator<OnlineNormalizedMeanSquaredErrorEvaluator>(); … … 103 109 var originalValuesEnumerator = originalValues.GetEnumerator(); 104 110 while (originalValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) { 105 double[]original = originalValuesEnumerator.Current;111 IEnumerable<double> original = originalValuesEnumerator.Current; 106 112 double[] estimated = estimatedValuesEnumerator.Current; 107 113 for (int i = 0; i < estimated.Length; i++) { … … 116 122 } 117 123 118 public static void CalculateScalingParameters(IEnumerable<double[]> originalValues, IEnumerable<double[]> estimatedValues, ref double[] beta, ref double[] alpha) { 119 List<OnlineMeanAndVarianceCalculator> estimatedVarianceEvaluators = new List<OnlineMeanAndVarianceCalculator>(); 120 List<OnlineCovarianceEvaluator> covarianceEvaluators = new List<OnlineCovarianceEvaluator>(); 121 List<OnlineMeanAndVarianceCalculator> originalMeanCalculators = new List<OnlineMeanAndVarianceCalculator>(); 122 int[] cnt = null; 124 public static void CalculateScalingParameters(IEnumerable<IEnumerable<double>> originalValues, IEnumerable<IEnumerable<double>> estimatedValues, ref double[] beta, ref double[] alpha) { 125 List<OnlineLinearScalingCalculator> linearScalingCalculators = new List<OnlineLinearScalingCalculator>(); 126 // initialize lists 127 int dimension = originalValues.First().Count(); 128 for (int i = 0; i < dimension; i++) { 129 linearScalingCalculators.Add(new OnlineLinearScalingCalculator()); 130 } 123 131 124 132 var estimatedEnumerator = estimatedValues.GetEnumerator(); 125 133 var originalEnumerator = originalValues.GetEnumerator(); 134 // foreach row vector in both series 126 135 while (estimatedEnumerator.MoveNext() & originalEnumerator.MoveNext()) { 127 double[]original = originalEnumerator.Current;128 double[]estimated = estimatedEnumerator.Current;129 int dimension = original.Length;130 // initialize131 if (cnt == null) { 132 cnt = new int[dimension];133 for (int i = 0; i < dimension; i++) {134 estimatedVarianceEvaluators.Add(new OnlineMeanAndVarianceCalculator());135 covarianceEvaluators.Add(new OnlineCovarianceEvaluator());136 originalMeanCalculators.Add(new OnlineMeanAndVarianceCalculator());136 IEnumerable<double> original = originalEnumerator.Current; 137 IEnumerable<double> estimated = estimatedEnumerator.Current; 138 var originalComponentValuesEnumerator = original.GetEnumerator(); 139 var estimatedComponentValuesEnumerator = estimated.GetEnumerator(); 140 141 int component = 0; 142 // for each component in both row vectors 143 while (originalComponentValuesEnumerator.MoveNext() & estimatedComponentValuesEnumerator.MoveNext() && component < dimension) { 144 if (IsValidValue(originalComponentValuesEnumerator.Current) && IsValidValue(estimatedComponentValuesEnumerator.Current)) { 145 linearScalingCalculators[component].Add(originalComponentValuesEnumerator.Current, estimatedComponentValuesEnumerator.Current); 137 146 } 138 } else if (cnt.Length == dimension) { 139 for (int component = 0; component < dimension; component++) { 140 if (IsValidValue(original[component]) && IsValidValue(estimated[component])) { 141 cnt[component]++; 142 estimatedVarianceEvaluators[component].Add(estimated[component]); 143 covarianceEvaluators[component].Add(original[component], estimated[component]); 144 originalMeanCalculators[component].Add(original[component]); 145 } 146 } 147 } else { 148 throw new ArgumentException("Dimension of input array doesn't match"); 147 component++; 148 } 149 // check if both row vectors are finished 150 if (originalComponentValuesEnumerator.MoveNext() | estimatedComponentValuesEnumerator.MoveNext() || component < dimension) { 151 throw new ArgumentException("Number of elements in original and estimated row vectors does not match."); 149 152 } 150 153 } 151 154 155 // check if both series are finished 152 156 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) 153 157 throw new InvalidOperationException("Number of elements in estimated and original series doesn't match."); 154 if (cnt == null) throw new ArgumentException("No elements in estimated and original.");155 158 156 for (int component = 0; component < cnt.Length; component++) { 157 if (cnt[component] < 2) { 158 alpha[component] = 0; 159 beta[component] = 1; 160 } else { 161 if (estimatedVarianceEvaluators[component].PopulationVariance.IsAlmost(0.0)) 162 beta[component] = 1; 163 else 164 beta[component] = covarianceEvaluators[component].Covariance / estimatedVarianceEvaluators[component].PopulationVariance; 165 166 alpha[component] = originalMeanCalculators[component].Mean - beta[component] * estimatedVarianceEvaluators[component].Mean; 167 } 159 // get alpha and beta for each component 160 for (int component = 0; component < dimension; component++) { 161 alpha[component] = linearScalingCalculators[component].Alpha; 162 beta[component] = linearScalingCalculators[component].Beta; 168 163 } 169 164 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate/3.3/Evaluators/OnlineMeanMahalanobisDistanceEvaluator.cs
r4475 r4555 14 14 private double distance; 15 15 private double[,] covMatrix; 16 private double[] diff; 17 private double[] target; 16 18 public double MeanMahalanobisDistance { 17 19 get { … … 39 41 } 40 42 41 public void Add(double[] original, double[] estimated) { 42 if (original.Length != estimated.Length) throw new ArgumentException("Number of elements of original and estimated doesn't match."); 43 if (original.Length != covMatrix.GetLength(0)) throw new ArgumentException("Original and estimated is not compatible with covariance matrix."); 43 public void Add(IEnumerable<double> original, IEnumerable<double> estimated) { 44 if (covMatrix == null) throw new InvalidOperationException("Covariance matrix must be initialized before values can be added."); 44 45 45 double[] diff = new double[original.Length]; 46 for (int i = 0; i < diff.Length; i++) { 47 diff[i] = original[i] - estimated[i]; 46 { 47 // calculate difference vector 48 var originalEnumerator = original.GetEnumerator(); 49 var estimatedEnumerator = estimated.GetEnumerator(); 50 int i = 0; 51 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext() && i < diff.Length) { 52 diff[i++] = originalEnumerator.Current - estimatedEnumerator.Current; 53 } 54 if (originalEnumerator.MoveNext() | estimatedEnumerator.MoveNext() || i < diff.Length) { 55 throw new ArgumentException("Number of elements of original and estimated doesn't match or is not compatible with covariance matrix."); 56 } 48 57 } 49 double[] target = new double[original.Length];50 58 51 alglib.ablas.rmatrixmv(covMatrix.GetLength(0), covMatrix.GetLength(1), ref covMatrix, 0, 0, 0, ref diff, 0, ref target, 0); 59 { 60 // calculate mahalanobis distance using covariance matrix 61 // covMatrix^(-1) * diff => target 62 alglib.ablas.rmatrixmv(covMatrix.GetLength(0), covMatrix.GetLength(1), ref covMatrix, 0, 0, 0, ref diff, 0, ref target, 0); 52 63 53 double sum = 0.0; 54 for (int i = 0; i < original.Length; i++) { 55 sum += diff[i] * target[i]; 64 // diff^T * (covMatrix^(-1) * diff) => sum 65 double sum = 0.0; 66 for (int i = 0; i < diff.Length; i++) { 67 sum += diff[i] * target[i]; 68 } 69 distance += sum; 70 n++; 56 71 } 57 distance += sum;58 n++;59 72 } 60 73 … … 62 75 n = 0; 63 76 distance = 0.0; 77 covMatrix = null; 78 diff = null; 79 target = null; 64 80 } 65 81 … … 88 104 alglib.matinv.rmatrixinverse(ref covMatrix, covMatrix.GetLength(0), ref info, ref report); 89 105 if (info != 1) throw new InvalidOperationException("Can't invert covariance matrix."); 106 diff = new double[samples.Length]; 107 target = new double[samples.Length]; 90 108 } 91 109 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate/3.3/Evaluators/OnlineMultiVariateEvaluator.cs
r4475 r4555 23 23 } 24 24 25 public void Add(double[] original, double[] estimated) { 26 if (original.Length != estimated.Length) throw new ArgumentException("Number of elements of original and estimated doesn't match."); 27 if (evaluators == null) InitializeEvaluators(original.Length); 28 if (original.Length != evaluators.Count) throw new ArgumentException("Dimension doesn't match previous array dimensions."); 29 for (int i = 0; i < original.Length; i++) { 30 evaluators[i].Add(original[i], estimated[i]); 25 public void Add(IEnumerable<double> original, IEnumerable<double> estimated) { 26 var originalEnumerator = original.GetEnumerator(); 27 var estimatedEnumerator = estimated.GetEnumerator(); 28 // first call of Add() => initialize evaluators list 29 if (evaluators == null) { 30 evaluators = new List<T>(); 31 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 32 T evaluator = new T(); 33 evaluator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 34 evaluators.Add(evaluator); 35 } 36 } else { 37 // subsequent call of Add(): for each evaluator a value must be added 38 int i = 0; 39 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext() && i < evaluators.Count) { 40 evaluators[i++].Add(originalEnumerator.Current, estimatedEnumerator.Current); 41 } 42 if (i < evaluators.Count) { 43 throw new ArgumentException("Number of elements in original and estimated does not match the number of elements in previously added vectors."); 44 } 31 45 } 32 } 33 34 private void InitializeEvaluators(int count) { 35 evaluators = new List<T>(); 36 for (int i = 0; i < count; i++) { 37 evaluators.Add(new T()); 46 if (originalEnumerator.MoveNext() | estimatedEnumerator.MoveNext()) { 47 throw new ArgumentException("Number of elements in original and estimated does not match."); 38 48 } 39 49 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate/3.3/Interfaces/IMultiVariateDataAnalysisSolution.cs
r4401 r4555 35 35 IEnumerable<double[]> EstimatedTrainingValues { get; } 36 36 IEnumerable<double[]> EstimatedTestValues { get; } 37 38 37 } 39 38 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate/3.3/Interfaces/IMultiVariateOnlineEvaluator.cs
r4475 r4555 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Optimization; 24 using System.Collections.Generic; 24 25 25 26 namespace HeuristicLab.Problems.DataAnalysis.MultiVariate { … … 27 28 double Value { get; } 28 29 void Reset(); 29 void Add( double[] original, double[]estimated);30 void Add(IEnumerable<double> original, IEnumerable<double> estimated); 30 31 } 31 32 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs
r4460 r4555 126 126 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 127 127 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 128 CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha);128 SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha); 129 129 130 130 return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance); … … 174 174 } 175 175 } 176 177 /// <summary>178 /// Calculates linear scaling parameters in one pass.179 /// The formulas to calculate the scaling parameters were taken from Scaled Symblic Regression by Maarten Keijzer.180 /// http://www.springerlink.com/content/x035121165125175/181 /// </summary>182 public static void CalculateScalingParameters(IEnumerable<double> original, IEnumerable<double> estimated, out double beta, out double alpha) {183 IEnumerator<double> originalEnumerator = original.GetEnumerator();184 IEnumerator<double> estimatedEnumerator = estimated.GetEnumerator();185 OnlineMeanAndVarianceCalculator yVarianceCalculator = new OnlineMeanAndVarianceCalculator();186 OnlineMeanAndVarianceCalculator tMeanCalculator = new OnlineMeanAndVarianceCalculator();187 OnlineCovarianceEvaluator ytCovarianceEvaluator = new OnlineCovarianceEvaluator();188 int cnt = 0;189 190 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {191 double y = estimatedEnumerator.Current;192 double t = originalEnumerator.Current;193 if (IsValidValue(t) && IsValidValue(y)) {194 tMeanCalculator.Add(t);195 yVarianceCalculator.Add(y);196 ytCovarianceEvaluator.Add(y, t);197 198 cnt++;199 }200 }201 202 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())203 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match.");204 if (cnt < 2) {205 alpha = 0;206 beta = 1;207 } else {208 if (yVarianceCalculator.PopulationVariance.IsAlmost(0.0))209 beta = 1;210 else211 beta = ytCovarianceEvaluator.Covariance / yVarianceCalculator.PopulationVariance;212 213 alpha = tMeanCalculator.Mean - beta * yVarianceCalculator.Mean;214 }215 }216 217 private static bool IsValidValue(double d) {218 return !double.IsInfinity(d) && !double.IsNaN(d) && d > -1.0E07 && d < 1.0E07; // don't consider very large or very small values for scaling219 }220 176 } 221 177 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs
r4458 r4555 100 100 } 101 101 102 /// <summary>103 /// Calculates linear scaling parameters in one pass.104 /// The formulas to calculate the scaling parameters were taken from Scaled Symblic Regression by Maarten Keijzer.105 /// http://www.springerlink.com/content/x035121165125175/106 /// </summary>107 102 public static void CalculateScalingParameters(IEnumerable<double> original, IEnumerable<double> estimated, out double beta, out double alpha) { 108 103 IEnumerator<double> originalEnumerator = original.GetEnumerator(); 109 104 IEnumerator<double> estimatedEnumerator = estimated.GetEnumerator(); 110 OnlineMeanAndVarianceCalculator yVarianceCalculator = new OnlineMeanAndVarianceCalculator(); 111 OnlineMeanAndVarianceCalculator tMeanCalculator = new OnlineMeanAndVarianceCalculator(); 112 OnlineCovarianceEvaluator ytCovarianceEvaluator = new OnlineCovarianceEvaluator(); 113 int cnt = 0; 105 OnlineLinearScalingCalculator linearScalingCalculator = new OnlineLinearScalingCalculator(); 114 106 115 107 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { … … 117 109 double t = originalEnumerator.Current; 118 110 if (IsValidValue(t) && IsValidValue(y)) { 119 tMeanCalculator.Add(t); 120 yVarianceCalculator.Add(y); 121 ytCovarianceEvaluator.Add(y, t); 122 123 cnt++; 111 linearScalingCalculator.Add(t, y); 124 112 } 125 113 } … … 127 115 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) 128 116 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match."); 129 if (cnt < 2) { 130 alpha = 0; 131 beta = 1; 132 } else { 133 if (yVarianceCalculator.PopulationVariance.IsAlmost(0.0)) 134 beta = 1; 135 else 136 beta = ytCovarianceEvaluator.Covariance / yVarianceCalculator.PopulationVariance; 137 138 alpha = tMeanCalculator.Mean - beta * yVarianceCalculator.Mean; 117 else { 118 beta = linearScalingCalculator.Beta; 119 alpha = linearScalingCalculator.Alpha; 139 120 } 140 121 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj
r4309 r4555 109 109 <None Include="HeuristicLabProblemsDataAnalysisPlugin.cs.frame" /> 110 110 <None Include="Properties\AssemblyInfo.frame" /> 111 <Compile Include="Evaluators\OnlineLinearScalingCalculator.cs" /> 111 112 <Compile Include="Evaluators\OnlineCovarianceEvaluator.cs" /> 112 113 <Compile Include="Evaluators\OnlineMeanAndVarianceCalculator.cs" />
Note: See TracChangeset
for help on using the changeset viewer.