Changeset 4555 for branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Symbolic
- Timestamp:
- 10/05/10 16:30:57 (14 years ago)
- Location:
- branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Symbolic
- Files:
-
- 3 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 }
Note: See TracChangeset
for help on using the changeset viewer.