Changeset 8010
- Timestamp:
- 06/15/12 13:17:07 (12 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 5 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/Interfaces/ISymbolicTimeSeriesPrognogisExpressionTreeInterpreter.cs
r7989 r8010 27 27 string TargetVariable { get; set; } 28 28 IEnumerable<IEnumerable<double>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows, int horizon); 29 IEnumerable<IEnumerable<double>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizon); 29 30 } 30 31 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs
r7998 r8010 54 54 double quality = Calculate(interpreter, solution, 55 55 EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 56 ProblemDataParameter.ActualValue, 57 rows,HorizonParameter.ActualValue.Value, ApplyLinearScaling);56 ProblemDataParameter.ActualValue, rows, EvaluationPartitionParameter.ActualValue, 57 HorizonParameter.ActualValue.Value, ApplyLinearScaling); 58 58 QualityParameter.ActualValue = new DoubleValue(quality); 59 59 … … 61 61 } 62 62 63 public static double Calculate(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows, int horizon, bool applyLinearScaling) {64 int horizion2 = problemData.TrainingPartition.End - problemData.TrainingPartition.Start;65 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows. Take(1).Select(r => Enumerable.Range(r, horizion2)).First());66 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows .Take(1), horizion2).SelectMany(x => x);63 public static double Calculate(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows, IntRange evaluationPartition, int horizon, bool applyLinearScaling) { 64 var horizions = rows.Select(r => Math.Min(horizon, evaluationPartition.End - r)); 65 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows.Zip(horizions, Enumerable.Range).SelectMany(r => r)); 66 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows, horizions).SelectMany(x => x); 67 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 68 68 OnlineCalculatorError errorState; … … 71 71 if (applyLinearScaling) { 72 72 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 73 CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows );73 CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows * horizon); 74 74 errorState = mseCalculator.ErrorState; 75 75 mse = mseCalculator.MeanSquaredError; … … 79 79 if (errorState != OnlineCalculatorError.None) return Double.NaN; 80 80 else return mse; 81 81 82 } 82 83 … … 86 87 EstimationLimitsParameter.ExecutionContext = context; 87 88 HorizonParameter.ExecutionContext = context; 89 EvaluationPartitionParameter.ExecutionContext = context; 88 90 89 double mse = Calculate( SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, HorizonParameter.ActualValue.Value, ApplyLinearScaling);91 double mse = Calculate((ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter)SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, EvaluationPartitionParameter.ActualValue, HorizonParameter.ActualValue.Value, ApplyLinearScaling); 90 92 91 93 HorizonParameter.ExecutionContext = null; 92 94 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 93 95 EstimationLimitsParameter.ExecutionContext = null; 96 EvaluationPartitionParameter.ExecutionContext = null; 94 97 95 98 return mse; -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs
r7989 r8010 86 86 } 87 87 88 public IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, int horizon) {89 var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows, horizon );88 public IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { 89 var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows, horizons); 90 90 return estimatedValues.Select(predictionPerRow => predictionPerRow.LimitToRange(lowerEstimationLimit, upperEstimationLimit)); 91 91 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisSolution.cs
r6802 r8010 25 25 using HeuristicLab.Optimization; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 28 28 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis { -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/TimeSeriesPrognosisSolutionView.Designer.cs
r7183 r8010 99 99 this.horizonTextBox.Size = new System.Drawing.Size(100, 20); 100 100 this.horizonTextBox.TabIndex = 1; 101 this.horizonTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.horizonTextBox_KeyDown);102 101 this.horizonTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.horizonTextBox_Validating); 103 102 this.horizonTextBox.Validated += new System.EventHandler(this.horizonTextBox_Validated); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/TimeSeriesPrognosisSolutionView.cs
r7989 r8010 61 61 int val; 62 62 if (int.TryParse(horizonTextBox.Text, out val)) { 63 e.Cancel = val <= 0 || val >= Content.ProblemData.TrainingPartition.End - Content.ProblemData.TrainingPartition.Start;63 //e.Cancel = val <= 0 || val >= Content.ProblemData.TrainingPartition.End - Content.ProblemData.TrainingPartition.Start; 64 64 } else { 65 65 e.Cancel = true; … … 72 72 Content.Horizon = val; 73 73 } 74 75 private void horizonTextBox_KeyDown(object sender, KeyEventArgs e) {76 if (e.KeyCode == Keys.Enter) {77 e.Handled = true;78 this.Focus();79 } else {80 e.Handled = false;81 }82 }83 84 74 } 85 75 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionLineChartView.cs
r7998 r8010 25 25 using System.Windows.Forms; 26 26 using System.Windows.Forms.DataVisualization.Charting; 27 using HeuristicLab.Common; 27 28 using HeuristicLab.MainForm; 28 29 using HeuristicLab.MainForm.WindowsForms; … … 77 78 this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Points 78 79 .DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), 79 Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.Training Partition.Size).SelectMany(x => x).ToArray());80 Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingIndizes.Count().ToEnumerable()).First().ToArray()); 80 81 } else { 81 82 this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Points 82 83 .DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), 83 Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes, 1).SelectMany(x => x).ToArray());84 Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes, Enumerable.Repeat(1, Content.ProblemData.TrainingIndizes.Count())).SelectMany(x => x).ToArray()); 84 85 } 85 86 this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Tag = Content; … … 95 96 this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points 96 97 .DataBindXY(Content.ProblemData.TestIndizes.ToArray(), 97 Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.Test Partition.Size).SelectMany(x => x).ToArray());98 Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestIndizes.Count().ToEnumerable()).First().ToArray()); 98 99 } else { 99 100 this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points 100 101 .DataBindXY(Content.ProblemData.TestIndizes.ToArray(), 101 Content.GetPrognosedValues(Content.ProblemData.TestIndizes, 1).SelectMany(x => x).ToArray());102 Content.GetPrognosedValues(Content.ProblemData.TestIndizes, Enumerable.Repeat(1, Content.ProblemData.TestIndizes.Count())).SelectMany(x => x).ToArray()); 102 103 } 103 104 this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Tag = Content; … … 220 221 case PROGNOSEDVALUES_TRAINING_SERIES_NAME: 221 222 indizes = Content.ProblemData.TrainingIndizes.ToArray(); 222 predictedValues = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size ).First();223 predictedValues = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size.ToEnumerable()).First(); 223 224 break; 224 225 case PROGNOSEDVALUES_TEST_SERIES_NAME: 225 226 testPrognosisStart = Content.ProblemData.TestPartition.Start; 226 227 indizes = Content.ProblemData.TestIndizes.ToArray(); 227 predictedValues = Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestPartition.Size ).First();228 predictedValues = Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestPartition.Size.ToEnumerable()).First(); 228 229 break; 229 230 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionPrognosedValuesView.cs
r7998 r8010 23 23 using System.Linq; 24 24 using System.Windows.Forms; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Data.Views; … … 94 95 95 96 string[,] values = new string[Content.ProblemData.Dataset.Rows, 4]; 96 var prognosedTraining = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size ).First();97 var prognosedTest = Content.GetPrognosedValues(Content.ProblemData.T rainingIndizes.Take(1), Content.ProblemData.TestPartition.Size).First();97 var prognosedTraining = Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes.Take(1), Content.ProblemData.TrainingPartition.Size.ToEnumerable()).First(); 98 var prognosedTest = Content.GetPrognosedValues(Content.ProblemData.TestIndizes.Take(1), Content.ProblemData.TestPartition.Size.ToEnumerable()).First(); 98 99 double[] target = Content.ProblemData.Dataset.GetDoubleValues(targetVariable).ToArray(); 99 100 -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r7886 r8010 140 140 </Compile> 141 141 <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" /> 142 <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisConstantModel.cs" /> 143 <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisMovingAverageModel.cs" /> 144 <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisAutoRegressiveModel.cs" /> 142 145 <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblem.cs" /> 143 146 <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblemData.cs" /> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolution.cs
r7989 r8010 29 29 /// </summary> 30 30 [StorableClass] 31 public abstract class TimeSeriesPrognosisSolution : TimeSeriesPrognosisSolutionBase { 32 31 public class TimeSeriesPrognosisSolution : TimeSeriesPrognosisSolutionBase { 33 32 [StorableConstructor] 34 33 protected TimeSeriesPrognosisSolution(bool deserializing) : base(deserializing) { } 35 34 protected TimeSeriesPrognosisSolution(TimeSeriesPrognosisSolution original, Cloner cloner) : base(original, cloner) { } 36 protected TimeSeriesPrognosisSolution(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) : base(model, problemData) { }35 protected internal TimeSeriesPrognosisSolution(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) : base(model, problemData) { } 37 36 38 37 protected override void RecalculateResults() { … … 40 39 } 41 40 42 public override IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, int horizon) {43 return Model.GetPrognosedValues(ProblemData.Dataset, rows, horizon );41 public override IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizons) { 42 return Model.GetPrognosedValues(ProblemData.Dataset, rows, horizons); 44 43 } 45 44 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
r7989 r8010 74 74 } 75 75 76 public abstract IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, inthorizon);76 public abstract IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizon); 77 77 78 78 #region Results … … 192 192 193 193 protected void CalculateResults() { 194 string targetVariable = ProblemData.TargetVariable; 195 196 var trainingMseCalculators = new OnlineMeanSquaredErrorCalculator(); 197 var testMseCalculators = new OnlineMeanSquaredErrorCalculator(); 198 var trainingMaeCalculators = new OnlineMeanAbsoluteErrorCalculator(); 199 var testMaeCalculators = new OnlineMeanAbsoluteErrorCalculator(); 200 var trainingRSquaredCalculators = new OnlinePearsonsRSquaredCalculator(); 201 var testRSquaredCalculators = new OnlinePearsonsRSquaredCalculator(); 202 var trainingRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator(); 203 var testRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator(); 204 var trainingNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator(); 205 var testNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator(); 206 207 var trainingDsCalculators = new OnlineDirectionalSymmetryCalculator(); 208 var testDsCalculators = new OnlineDirectionalSymmetryCalculator(); 209 var trainingWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator(); 210 var testWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator(); 211 var trainingTheilsULastCalculators = new OnlineTheilsUStatisticCalculator(); 212 var testTheilsULastCalculators = new OnlineTheilsUStatisticCalculator(); 213 var trainingTheilsUMeanCalculators = new OnlineTheilsUStatisticCalculator(); 214 var testTheilsUMeanCalculators = new OnlineTheilsUStatisticCalculator(); 215 var trainingTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator(); 216 var testTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator(); 217 218 double mean = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TrainingIndizes).Average(); 219 220 foreach (var row in ProblemData.TrainingIndizes) { 221 if (row + horizon < ProblemData.Dataset.Rows) { 222 var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(row, horizon)).ToList(); 223 var prognosedContinuation = GetPrognosedValues(new List<int> { row }, horizon).First().ToList(); 224 225 int maWindow = 10 * horizon; 226 var movingAverageContinuation = from h in Enumerable.Range(0, horizon) 227 select (from r in Enumerable.Range(row + h - maWindow, maWindow - h) 228 where r > 0 229 select ProblemData.Dataset.GetDoubleValue(targetVariable, r) 230 ).Average(); 231 232 double startValue = ProblemData.Dataset.GetDoubleValue(targetVariable, row - 1); 233 234 trainingDsCalculators.Add(startValue, actualContinuation, prognosedContinuation); 235 trainingWdsCalculators.Add(startValue, actualContinuation, prognosedContinuation); 236 trainingTheilsULastCalculators.Add(startValue, actualContinuation, prognosedContinuation); 237 trainingTheilsUMeanCalculators.Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation); 238 trainingTheilsUMovingAverageCalculators.Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation); 239 240 var actualContinuationEnumerator = actualContinuation.GetEnumerator(); 241 var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator(); 242 243 while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) { 244 trainingMseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 245 trainingMaeCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 246 trainingRelErrorCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 247 trainingRSquaredCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 248 trainingNmseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 249 } 250 if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext()) 251 throw new ArgumentException("Different number of elements in Actual continuation and prognosed continuation."); 252 } 253 } 254 255 mean = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TestIndizes).Average(); 256 foreach (var row in ProblemData.TestIndizes) { 257 if (row + horizon < ProblemData.Dataset.Rows) { 258 var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(row, horizon)).ToList(); 259 var prognosedContinuation = GetPrognosedValues(new List<int> { row }, horizon).First().ToList(); 260 261 int maWindow = 10 * horizon; 262 var movingAverageContinuation = from h in Enumerable.Range(0, horizon) 263 select (from r in Enumerable.Range(row + h - maWindow, maWindow - h) 264 where r > 0 265 select ProblemData.Dataset.GetDoubleValue(targetVariable, r) 266 ).Average(); 267 268 double startValue = ProblemData.Dataset.GetDoubleValue(targetVariable, row - 1); 269 testDsCalculators.Add(startValue, actualContinuation, prognosedContinuation); 270 testWdsCalculators.Add(startValue, actualContinuation, prognosedContinuation); 271 testTheilsULastCalculators.Add(startValue, actualContinuation, prognosedContinuation); 272 testTheilsUMeanCalculators.Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation); 273 testTheilsUMovingAverageCalculators.Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation); 274 275 var actualContinuationEnumerator = actualContinuation.GetEnumerator(); 276 var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator(); 277 while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) { 278 testMseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 279 testMaeCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 280 testRelErrorCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 281 testRSquaredCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 282 testNmseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current); 283 } 284 if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext()) 285 throw new ArgumentException("Different number of elements in Actual continuation and prognosed continuation."); 286 } 287 } 288 289 TrainingMeanSquaredError = trainingMseCalculators.ErrorState == OnlineCalculatorError.None ? trainingMseCalculators.Value : double.PositiveInfinity; 290 TestMeanSquaredError = testMseCalculators.ErrorState == OnlineCalculatorError.None ? testMseCalculators.Value : double.PositiveInfinity; 291 TrainingMeanAbsoluteError = trainingMaeCalculators.ErrorState == OnlineCalculatorError.None ? trainingMaeCalculators.Value : double.PositiveInfinity; 292 TestMeanAbsoluteError = testMaeCalculators.ErrorState == OnlineCalculatorError.None ? testMaeCalculators.Value : double.PositiveInfinity; 293 TrainingRelativeError = trainingRelErrorCalculators.ErrorState == OnlineCalculatorError.None ? trainingRelErrorCalculators.Value : double.PositiveInfinity; 294 TestRelativeError = testRelErrorCalculators.ErrorState == OnlineCalculatorError.None ? testRelErrorCalculators.Value : double.PositiveInfinity; 295 TrainingRSquared = trainingRSquaredCalculators.ErrorState == OnlineCalculatorError.None ? trainingRSquaredCalculators.Value : 0.0; 296 TestRSquared = testRSquaredCalculators.ErrorState == OnlineCalculatorError.None ? testRSquaredCalculators.Value : 0.0; 297 TrainingNormalizedMeanSquaredError = trainingNmseCalculators.ErrorState == OnlineCalculatorError.None ? trainingNmseCalculators.Value : double.PositiveInfinity; 298 TestNormalizedMeanSquaredError = testNmseCalculators.ErrorState == OnlineCalculatorError.None ? testNmseCalculators.Value : double.PositiveInfinity; 299 300 TrainingDirectionalSymmetry = trainingDsCalculators.ErrorState == OnlineCalculatorError.None ? trainingDsCalculators.Value : 0.0; 301 TestDirectionalSymmetry = testDsCalculators.ErrorState == OnlineCalculatorError.None ? testDsCalculators.Value : 0.0; 302 TrainingWeightedDirectionalSymmetry = trainingWdsCalculators.ErrorState == OnlineCalculatorError.None ? trainingWdsCalculators.Value : double.PositiveInfinity; 303 TestWeightedDirectionalSymmetry = testWdsCalculators.ErrorState == OnlineCalculatorError.None ? testWdsCalculators.Value : double.PositiveInfinity; 304 TrainingTheilsUStatisticLast = trainingTheilsULastCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsULastCalculators.Value : double.PositiveInfinity; 305 TestTheilsUStatisticLast = testTheilsULastCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsULastCalculators.Value : double.PositiveInfinity; 306 TrainingTheilsUStatisticMean = trainingTheilsUMeanCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsUMeanCalculators.Value : double.PositiveInfinity; 307 TestTheilsUStatisticMean = testTheilsUMeanCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsUMeanCalculators.Value : double.PositiveInfinity; 308 TrainingTheilsUStatisticMovingAverage = trainingTheilsUMovingAverageCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsUMovingAverageCalculators.Value : double.PositiveInfinity; 309 TestTheilsUStatisticMovingAverage = testTheilsUMovingAverageCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsUMovingAverageCalculators.Value : double.PositiveInfinity; 194 OnlineCalculatorError errorState; 195 //mean model 196 double trainingMean = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average(); 197 var meanModel = new TimeSeriesPrognosisConstantModel(trainingMean); 198 199 //AR1 model 200 double alpha, beta; 201 IEnumerable<double> trainingStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes.Select(r => r - 1).Where(r => r > 0)).ToList(); 202 OnlineLinearScalingParameterCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes.Where(x => x > 0)), trainingStartValues, out alpha, out beta, out errorState); 203 var AR1model = new TimeSeriesPrognosisAutoRegressiveModel(alpha, beta, ProblemData.TargetVariable); 204 205 //MA model 206 int movingAverageWindowSize = 10 + horizon; 207 var MovingAverageModel = new TimeSeriesPrognosisMovingAverageModel(movingAverageWindowSize, ProblemData.TargetVariable); 208 209 #region Calculate training quality measures 210 var trainingHorizions = ProblemData.TrainingIndizes.Select(r => Math.Min(horizon, ProblemData.TrainingPartition.End - r)).ToList(); 211 IEnumerable<IEnumerable<double>> trainingTargetValues = ProblemData.TrainingIndizes.Zip(trainingHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList(); 212 IEnumerable<IEnumerable<double>> trainingEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndizes, trainingHorizions).ToList(); 213 214 TrainingMeanSquaredError = OnlineMeanSquaredErrorCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState); 215 TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? TrainingMeanSquaredError : double.PositiveInfinity; 216 TrainingMeanAbsoluteError = OnlineMeanAbsoluteErrorCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState); 217 TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? TrainingMeanAbsoluteError : double.PositiveInfinity; 218 TrainingRelativeError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState); 219 TrainingRelativeError = errorState == OnlineCalculatorError.None ? TrainingRelativeError : double.PositiveInfinity; 220 TrainingRSquared = OnlinePearsonsRSquaredCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState); 221 TrainingRSquared = errorState == OnlineCalculatorError.None ? TrainingRSquared : 0.0; 222 TrainingNormalizedMeanSquaredError = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(trainingTargetValues.SelectMany(x => x), trainingEstimatedValues.SelectMany(x => x), out errorState); 223 TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? TrainingNormalizedMeanSquaredError : double.PositiveInfinity; 224 225 IEnumerable<IEnumerable<double>> trainingMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndizes, trainingHorizions); 226 IEnumerable<IEnumerable<double>> trainingAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndizes, trainingHorizions); 227 IEnumerable<IEnumerable<double>> trainingMovingAverageModelPredictions = MovingAverageModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndizes, trainingHorizions); 228 229 TrainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingEstimatedValues, out errorState); 230 TrainingDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TrainingDirectionalSymmetry : 0.0; 231 TrainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingEstimatedValues, out errorState); 232 TrainingWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TrainingWeightedDirectionalSymmetry : 0.0; 233 TrainingTheilsUStatisticLast = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingAR1ModelPredictions, trainingEstimatedValues, out errorState); 234 TrainingTheilsUStatisticLast = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticLast : double.PositiveInfinity; ; 235 TrainingTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingMeanModelPredictions, trainingEstimatedValues, out errorState); 236 TrainingTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticMean : double.PositiveInfinity; ; 237 TrainingTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(trainingStartValues, trainingTargetValues, trainingMovingAverageModelPredictions, trainingEstimatedValues, out errorState); 238 TrainingTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? TrainingTheilsUStatisticMovingAverage : double.PositiveInfinity; ; ; 239 #endregion 240 241 #region Calculate test quality measures 242 var testHorizions = ProblemData.TestIndizes.Select(r => Math.Min(horizon, ProblemData.TestPartition.End - r)).ToList(); 243 IEnumerable<IEnumerable<double>> testTargetValues = ProblemData.TestIndizes.Zip(testHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList(); 244 IEnumerable<IEnumerable<double>> testEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndizes, testHorizions).ToList(); 245 246 TestMeanSquaredError = OnlineMeanSquaredErrorCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState); 247 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? TestMeanSquaredError : double.PositiveInfinity; 248 TestMeanAbsoluteError = OnlineMeanAbsoluteErrorCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState); 249 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? TestMeanAbsoluteError : double.PositiveInfinity; 250 TestRelativeError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState); 251 TestRelativeError = errorState == OnlineCalculatorError.None ? TestRelativeError : double.PositiveInfinity; 252 TestRSquared = OnlinePearsonsRSquaredCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState); 253 TestRSquared = errorState == OnlineCalculatorError.None ? TestRSquared : 0.0; 254 TestNormalizedMeanSquaredError = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(testTargetValues.SelectMany(x => x), testEstimatedValues.SelectMany(x => x), out errorState); 255 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? TestNormalizedMeanSquaredError : double.PositiveInfinity; 256 257 IEnumerable<double> testStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndizes.Select(r => r - 1).Where(r => r > 0)).ToList(); 258 IEnumerable<IEnumerable<double>> testMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndizes, testHorizions); 259 IEnumerable<IEnumerable<double>> testAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndizes, testHorizions); 260 IEnumerable<IEnumerable<double>> testMovingAverageModelPredictions = MovingAverageModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndizes, testHorizions); 261 262 TestDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(testStartValues, testTargetValues, testEstimatedValues, out errorState); 263 TestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TestDirectionalSymmetry : 0.0; 264 TestWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(testStartValues, testTargetValues, testEstimatedValues, out errorState); 265 TestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? TestWeightedDirectionalSymmetry : 0.0; 266 TestTheilsUStatisticLast = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testAR1ModelPredictions, testEstimatedValues, out errorState); 267 TestTheilsUStatisticLast = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticLast : double.PositiveInfinity; ; 268 TestTheilsUStatisticMean = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testMeanModelPredictions, testEstimatedValues, out errorState); 269 TestTheilsUStatisticMean = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticMean : double.PositiveInfinity; ; 270 TestTheilsUStatisticMovingAverage = OnlineTheilsUStatisticCalculator.Calculate(testStartValues, testTargetValues, testMovingAverageModelPredictions, testEstimatedValues, out errorState); 271 TestTheilsUStatisticMovingAverage = errorState == OnlineCalculatorError.None ? TestTheilsUStatisticMovingAverage : double.PositiveInfinity; ; ; 272 #endregion 310 273 } 311 274 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisModel.cs
r7989 r8010 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 24 public interface ITimeSeriesPrognosisModel : IDataAnalysisModel { 25 IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, int horizon);25 IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons); 26 26 ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData); 27 27 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisSolution.cs
r7989 r8010 27 27 new ITimeSeriesPrognosisProblemData ProblemData { get; set; } 28 28 29 IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, inthorizon);29 IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizon); 30 30 31 31 double TrainingMeanSquaredError { get; } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs
r7160 r8010 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common;26 25 27 26 namespace HeuristicLab.Problems.DataAnalysis { … … 97 96 #endregion 98 97 99 public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) {98 public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> referenceContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) { 100 99 IEnumerator<double> startValueEnumerator = startValues.GetEnumerator(); 101 100 IEnumerator<IEnumerable<double>> actualContinuationsEnumerator = actualContinuations.GetEnumerator(); 101 IEnumerator<IEnumerable<double>> referenceContinuationsEnumerator = referenceContinuations.GetEnumerator(); 102 102 IEnumerator<IEnumerable<double>> predictedContinuationsEnumerator = predictedContinuations.GetEnumerator(); 103 103 104 OnlineTheilsUStatisticCalculator calculator = new OnlineTheilsUStatisticCalculator(); 104 105 105 106 // always move forward all enumerators (do not use short-circuit evaluation!) 106 while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) {107 calculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current);107 while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & referenceContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) { 108 calculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, referenceContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current); 108 109 if (calculator.ErrorState != OnlineCalculatorError.None) break; 109 110 } … … 111 112 // check if all enumerators are at the end to make sure both enumerations have the same length 112 113 if (calculator.ErrorState == OnlineCalculatorError.None && 113 (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) {114 throw new ArgumentException("Number of elements in startValues, actualContinuations and estimatedValues predictedContinuations doesn't match.");114 (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || referenceContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) { 115 throw new ArgumentException("Number of elements in startValues, actualContinuations, referenceContinuation and estimatedValues predictedContinuations doesn't match."); 115 116 } else { 116 117 errorState = calculator.ErrorState; -
branches/HeuristicLab.TimeSeries/HeuristicLab.TimeSeries-3.3.sln
r7890 r8010 7 7 ConfigMerger.exe = ConfigMerger.exe 8 8 ..\documentation\License\gpl-3.0.txt = ..\documentation\License\gpl-3.0.txt 9 HeuristicLab.TimeSeries-3.32.vsmdi = HeuristicLab.TimeSeries-3.32.vsmdi 9 10 LocalTestRun.testrunconfig = LocalTestRun.testrunconfig 10 11 MergeConfigs.cmd = MergeConfigs.cmd … … 32 33 EndProject 33 34 Global 35 GlobalSection(TestCaseManagementSettings) = postSolution 36 CategoryFile = HeuristicLab.TimeSeries-3.32.vsmdi 37 EndGlobalSection 34 38 GlobalSection(SolutionConfigurationPlatforms) = preSolution 35 39 Debug|Any CPU = Debug|Any CPU
Note: See TracChangeset
for help on using the changeset viewer.