Changeset 7100 for branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis
- Timestamp:
- 11/29/11 20:05:38 (13 years ago)
- Location:
- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs
r6802 r7100 34 34 [Item("TimeSeriesPrognosisProblemData", "Represents an item containing all data defining a time series prognosis problem.")] 35 35 public class TimeSeriesPrognosisProblemData : DataAnalysisProblemData, ITimeSeriesPrognosisProblemData { 36 protected const string TargetVariable ParameterName = "TargetVariable";36 protected const string TargetVariablesParameterName = "TargetVariables"; 37 37 38 38 #region default data … … 1541 1541 private static readonly Dataset defaultDataset; 1542 1542 private static readonly IEnumerable<string> defaultAllowedInputVariables; 1543 private static readonly string defaultTargetVariable;1543 private static readonly string[] defaultTargetVariables; 1544 1544 1545 1545 private static readonly TimeSeriesPrognosisProblemData emptyProblemData; … … 1552 1552 defaultDataset.Name = "Mackey-Glass (t=17) Time Series Benchmark Dataset"; 1553 1553 defaultAllowedInputVariables = new List<string>() { "x" }; 1554 defaultTargetVariable = "x";1554 defaultTargetVariables = new string[] { "x" }; 1555 1555 1556 1556 var problemData = new TimeSeriesPrognosisProblemData(); … … 1564 1564 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 1565 1565 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 1566 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariable ParameterName, new ItemSet<StringValue>()));1566 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariablesParameterName, new ItemSet<StringValue>())); 1567 1567 emptyProblemData = problemData; 1568 1568 } 1569 1569 #endregion 1570 1570 1571 public ConstrainedValueParameter<StringValue> TargetVariableParameter {1572 get { return ( ConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; }1571 public ValueParameter<CheckedItemList<StringValue>> TargetVariablesParameter { 1572 get { return (ValueParameter<CheckedItemList<StringValue>>)Parameters[TargetVariablesParameterName]; } 1573 1573 } 1574 public string TargetVariable{1575 get { return TargetVariable Parameter.Value.Value; }1574 public IEnumerable<string> TargetVariables { 1575 get { return TargetVariablesParameter.Value.CheckedItems.Select(x => x.Value.Value); } 1576 1576 } 1577 1577 … … 1593 1593 1594 1594 public TimeSeriesPrognosisProblemData() 1595 : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable ) {1595 : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariables) { 1596 1596 } 1597 1597 1598 public TimeSeriesPrognosisProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)1598 public TimeSeriesPrognosisProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<string> targetVariables) 1599 1599 : base(dataset, allowedInputVariables) { 1600 1600 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 1601 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First())); 1601 var targetVariablesList = new CheckedItemList<StringValue>(variables); 1602 foreach (var targetVar in targetVariables) { 1603 targetVariablesList.SetItemCheckedState(targetVariablesList.Single(x => x.Value == targetVar), true); 1604 } 1605 Parameters.Add(new FixedValueParameter<CheckedItemList<StringValue>>(TargetVariablesParameterName, targetVariablesList)); 1602 1606 RegisterParameterEvents(); 1603 1607 } 1604 1608 1605 1609 private void RegisterParameterEvents() { 1606 TargetVariable Parameter.ValueChanged += TargetVariableParameter_ValueChanged;1610 TargetVariablesParameter.Value.CheckedItemsChanged += TargetVariableParameter_ValueChanged; 1607 1611 } 1608 1612 … … 1619 1623 dataset.Name = Path.GetFileName(fileName); 1620 1624 1621 TimeSeriesPrognosisProblemData problemData = new TimeSeriesPrognosisProblemData(dataset, dataset.DoubleVariables, dataset.DoubleVariables. First());1625 TimeSeriesPrognosisProblemData problemData = new TimeSeriesPrognosisProblemData(dataset, dataset.DoubleVariables, dataset.DoubleVariables.Take(1)); 1622 1626 problemData.Name = "Data imported from " + Path.GetFileName(fileName); 1623 1627 return problemData; -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolution.cs
r6802 r7100 47 47 } 48 48 49 public override IEnumerable<double> PrognosedValues { 50 get { return GetPrognosedValues(Enumerable.Range(0, ProblemData.Dataset.Rows)); } 49 public override IEnumerable<IEnumerable<double>> PrognosedTrainingValues { 50 get { 51 return GetPrognosedValues(Enumerable.Range(ProblemData.TrainingPartition.Start, 1), 52 ProblemData.TrainingPartition.End - ProblemData.TrainingPartition.Start) 53 .First(); 54 } 51 55 } 52 public override IEnumerable<double> PrognosedTrainingValues { 53 get { return GetPrognosedValues(ProblemData.TrainingIndizes); } 56 public override IEnumerable<IEnumerable<double>> PrognosedTestValues { 57 get { 58 return GetPrognosedValues(Enumerable.Range(ProblemData.TestPartition.Start, 1), 59 ProblemData.TestPartition.End - ProblemData.TestPartition.Start) 60 .First(); 61 } 54 62 } 55 public override IEnumerable<double> PrognosedTestValues { 56 get { return GetPrognosedValues(ProblemData.TestIndizes); } 57 } 58 public override IEnumerable<double> GetPrognosedValues(IEnumerable<int> rows) { 59 return Model.GetPrognosedValues(ProblemData.Dataset, rows); 63 public override IEnumerable<IEnumerable<IEnumerable<double>>> GetPrognosedValues(IEnumerable<int> rows, int horizon) { 64 return Model.GetPrognosedValues(ProblemData.Dataset, rows, horizon); 60 65 } 61 66 -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
r7099 r7100 20 20 #endregion 21 21 22 using System.Collections.Concurrent; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 57 58 } 58 59 59 public abstract IEnumerable<double> PrognosedValues { get; } 60 public abstract IEnumerable<double> PrognosedTrainingValues { get; } 61 public abstract IEnumerable<double> PrognosedTestValues { get; } 62 public abstract IEnumerable<double> GetPrognosedValues(IEnumerable<int> rows); 60 public abstract IEnumerable<IEnumerable<double>> PrognosedTrainingValues { get; } 61 public abstract IEnumerable<IEnumerable<double>> PrognosedTestValues { get; } 62 public abstract IEnumerable<IEnumerable<IEnumerable<double>>> GetPrognosedValues(IEnumerable<int> rows, int horizon); 63 63 64 64 #region Results 65 public double TrainingMeanSquaredError {66 get { return ((Double Value)this[TrainingMeanSquaredErrorResultName].Value).Value; }67 private set { ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value = value; }68 } 69 public double TestMeanSquaredError {70 get { return ((Double Value)this[TestMeanSquaredErrorResultName].Value).Value; }71 private set { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; }72 } 73 public double TrainingMeanAbsoluteError {74 get { return ((Double Value)this[TrainingMeanAbsoluteErrorResultName].Value).Value; }75 private set { ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value = value; }76 } 77 public double TestMeanAbsoluteError {78 get { return ((Double Value)this[TestMeanAbsoluteErrorResultName].Value).Value; }79 private set { ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value = value; }80 } 81 public double TrainingRSquared {82 get { return ((Double Value)this[TrainingSquaredCorrelationResultName].Value).Value; }83 private set { ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value = value; }84 } 85 public double TestRSquared {86 get { return ((Double Value)this[TestSquaredCorrelationResultName].Value).Value; }87 private set { ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value = value; }88 } 89 public double TrainingRelativeError {90 get { return ((Double Value)this[TrainingRelativeErrorResultName].Value).Value; }91 private set { ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value = value; }92 } 93 public double TestRelativeError {94 get { return ((Double Value)this[TestRelativeErrorResultName].Value).Value; }95 private set { ((DoubleValue)this[TestRelativeErrorResultName].Value).Value = value; }96 } 97 public double TrainingNormalizedMeanSquaredError {98 get { return ((Double Value)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value; }99 private set { ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value = value; }100 } 101 public double TestNormalizedMeanSquaredError {102 get { return ((Double Value)this[TestNormalizedMeanSquaredErrorResultName].Value).Value; }103 private set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; }104 } 105 public double TrainingDirectionalSymmetry {106 get { return ((Double Value)this[TrainingDirectionalSymmetryResultName].Value).Value; }107 private set { ((DoubleValue)this[TrainingDirectionalSymmetryResultName].Value).Value = value; }108 } 109 public double TestDirectionalSymmetry {110 get { return ((Double Value)this[TestDirectionalSymmetryResultName].Value).Value; }111 private set { ((DoubleValue)this[TestDirectionalSymmetryResultName].Value).Value = value; }112 } 113 public double TrainingWeightedDirectionalSymmetry {114 get { return ((Double Value)this[TrainingWeightedDirectionalSymmetryResultName].Value).Value; }115 private set { ((DoubleValue)this[TrainingWeightedDirectionalSymmetryResultName].Value).Value = value; }116 } 117 public double TestWeightedDirectionalSymmetry {118 get { return ((Double Value)this[TestWeightedDirectionalSymmetryResultName].Value).Value; }119 private set { ((DoubleValue)this[TestWeightedDirectionalSymmetryResultName].Value).Value = value; }120 } 121 public double TrainingTheilsUStatistic {122 get { return ((Double Value)this[TrainingTheilsUStatisticResultName].Value).Value; }123 private set { ((DoubleValue)this[TrainingTheilsUStatisticResultName].Value).Value = value; }124 } 125 public double TestTheilsUStatistic {126 get { return ((Double Value)this[TestTheilsUStatisticResultName].Value).Value; }127 private set { ((DoubleValue)this[TestTheilsUStatisticResultName].Value).Value = value; }65 public double[] TrainingMeanSquaredError { 66 get { return ((DoubleArray)this[TrainingMeanSquaredErrorResultName].Value).ToArray(); } 67 private set { this[TrainingMeanSquaredErrorResultName].Value = new DoubleArray(value); } 68 } 69 public double[] TestMeanSquaredError { 70 get { return ((DoubleArray)this[TestMeanSquaredErrorResultName].Value).ToArray(); } 71 private set { this[TestMeanSquaredErrorResultName].Value = new DoubleArray(value); } 72 } 73 public double[] TrainingMeanAbsoluteError { 74 get { return ((DoubleArray)this[TrainingMeanAbsoluteErrorResultName].Value).ToArray(); } 75 private set { this[TrainingMeanAbsoluteErrorResultName].Value = new DoubleArray(value); } 76 } 77 public double[] TestMeanAbsoluteError { 78 get { return ((DoubleArray)this[TestMeanAbsoluteErrorResultName].Value).ToArray(); } 79 private set { this[TestMeanAbsoluteErrorResultName].Value = new DoubleArray(value); } 80 } 81 public double[] TrainingRSquared { 82 get { return ((DoubleArray)this[TrainingSquaredCorrelationResultName].Value).ToArray(); } 83 private set { this[TrainingSquaredCorrelationResultName].Value = new DoubleArray(value); } 84 } 85 public double[] TestRSquared { 86 get { return ((DoubleArray)this[TestSquaredCorrelationResultName].Value).ToArray(); } 87 private set { this[TestSquaredCorrelationResultName].Value = new DoubleArray(value); } 88 } 89 public double[] TrainingRelativeError { 90 get { return ((DoubleArray)this[TrainingRelativeErrorResultName].Value).ToArray(); } 91 private set { this[TrainingRelativeErrorResultName].Value = new DoubleArray(value); } 92 } 93 public double[] TestRelativeError { 94 get { return ((DoubleArray)this[TestRelativeErrorResultName].Value).ToArray(); } 95 private set { this[TestRelativeErrorResultName].Value = new DoubleArray(value); } 96 } 97 public double[] TrainingNormalizedMeanSquaredError { 98 get { return ((DoubleArray)this[TrainingNormalizedMeanSquaredErrorResultName].Value).ToArray(); } 99 private set { this[TrainingNormalizedMeanSquaredErrorResultName].Value = new DoubleArray(value); } 100 } 101 public double[] TestNormalizedMeanSquaredError { 102 get { return ((DoubleArray)this[TestNormalizedMeanSquaredErrorResultName].Value).ToArray(); } 103 private set { this[TestNormalizedMeanSquaredErrorResultName].Value = new DoubleArray(value); } 104 } 105 public double[] TrainingDirectionalSymmetry { 106 get { return ((DoubleArray)this[TrainingDirectionalSymmetryResultName].Value).ToArray(); } 107 private set { this[TrainingDirectionalSymmetryResultName].Value = new DoubleArray(value); } 108 } 109 public double[] TestDirectionalSymmetry { 110 get { return ((DoubleArray)this[TestDirectionalSymmetryResultName].Value).ToArray(); } 111 private set { this[TestDirectionalSymmetryResultName].Value = new DoubleArray(value); } 112 } 113 public double[] TrainingWeightedDirectionalSymmetry { 114 get { return ((DoubleArray)this[TrainingWeightedDirectionalSymmetryResultName].Value).ToArray(); } 115 private set { this[TrainingWeightedDirectionalSymmetryResultName].Value = new DoubleArray(value); } 116 } 117 public double[] TestWeightedDirectionalSymmetry { 118 get { return ((DoubleArray)this[TestWeightedDirectionalSymmetryResultName].Value).ToArray(); } 119 private set { this[TestWeightedDirectionalSymmetryResultName].Value = new DoubleArray(value); } 120 } 121 public double[] TrainingTheilsUStatistic { 122 get { return ((DoubleArray)this[TrainingTheilsUStatisticResultName].Value).ToArray(); } 123 private set { this[TrainingTheilsUStatisticResultName].Value = new DoubleArray(value); } 124 } 125 public double[] TestTheilsUStatistic { 126 get { return ((DoubleArray)this[TestTheilsUStatisticResultName].Value).ToArray(); } 127 private set { this[TestTheilsUStatisticResultName].Value = new DoubleArray(value); } 128 128 } 129 129 #endregion … … 136 136 protected TimeSeriesPrognosisSolutionBase(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) 137 137 : base(model, problemData) { 138 Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new Double Value()));139 Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new Double Value()));140 Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new Double Value()));141 Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new Double Value()));142 Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new Double Value()));143 Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new Double Value()));144 Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue()));145 Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue()));146 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new Double Value()));147 Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new Double Value()));148 Add(new Result(TrainingDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the training partition", new PercentValue()));149 Add(new Result(TestDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the test partition", new PercentValue()));150 Add(new Result(TrainingWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the training partition", new Double Value()));151 Add(new Result(TestWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the test partition", new Double Value()));152 Add(new Result(TrainingTheilsUStatisticResultName, "The average Theil's U statistic of the forecasts of the model on the training partition", new Double Value()));153 Add(new Result(TestTheilsUStatisticResultName, "The average Theil's U statistic of the forecasts of the model on the test partition", new Double Value()));138 Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleArray())); 139 Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleArray())); 140 Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleArray())); 141 Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleArray())); 142 Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleArray())); 143 Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleArray())); 144 Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new DoubleArray())); 145 Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new DoubleArray())); 146 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleArray())); 147 Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleArray())); 148 Add(new Result(TrainingDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the training partition", new DoubleArray())); 149 Add(new Result(TestDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the test partition", new DoubleArray())); 150 Add(new Result(TrainingWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the training partition", new DoubleArray())); 151 Add(new Result(TestWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the test partition", new DoubleArray())); 152 Add(new Result(TrainingTheilsUStatisticResultName, "The average Theil's U statistic of the forecasts of the model on the training partition", new DoubleArray())); 153 Add(new Result(TestTheilsUStatisticResultName, "The average Theil's U statistic of the forecasts of the model on the test partition", new DoubleArray())); 154 154 } 155 155 … … 160 160 161 161 protected void CalculateResults() { 162 OnlineCalculatorError errorState; 163 /* 162 164 double[] estimatedTrainingValues = PrognosedTrainingValues.ToArray(); // cache values 163 165 double[] originalTrainingValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).ToArray(); … … 165 167 double[] originalTestValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndizes).ToArray(); 166 168 167 OnlineCalculatorError errorState;168 169 double trainingMse = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 169 170 TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMse : double.NaN; … … 190 191 double testNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 191 192 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNmse : double.NaN; 192 193 var startTrainingValues = originalTrainingValues; 194 // each continuation is only one element long 195 var actualContinuationsTraining = from x in originalTrainingValues.Skip(1) 196 select Enumerable.Repeat(x, 1); 197 // each forecast is only one elemnt long 198 // disregards the first estimated value (we could include this again by extending the list of original values by one step to the left 199 // this is the easier way 200 var predictedContinuationsTraining = from x in estimatedTrainingValues.Skip(1) 201 select Enumerable.Repeat(x, 1); 202 203 var startTestValues = originalTestValues; 204 var actualContinuationsTest = from x in originalTestValues.Skip(1) 205 select Enumerable.Repeat(x, 1); 206 var predictedContinuationsTest = from x in estimatedTestValues.Skip(1) 207 select Enumerable.Repeat(x, 1); 208 209 double trainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState); 210 TrainingDirectionalSymmetry = errorState == OnlineCalculatorError.None ? trainingDirectionalSymmetry : double.NaN; 211 double testDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState); 212 TestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? testDirectionalSymmetry : double.NaN; 213 214 double trainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState); 215 TrainingWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? trainingWeightedDirectionalSymmetry : double.NaN; 216 double testWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState); 217 TestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? testWeightedDirectionalSymmetry : double.NaN; 218 219 double trainingTheilsU = OnlineTheilsUStatisticCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState); 220 TrainingTheilsUStatistic = errorState == OnlineCalculatorError.None ? trainingTheilsU : double.NaN; 221 double testTheilsU = OnlineTheilsUStatisticCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState); 222 TestTheilsUStatistic = errorState == OnlineCalculatorError.None ? testTheilsU : double.NaN; 193 */ 194 195 double[] trainingDs = new double[ProblemData.TargetVariables.Count()]; 196 double[] testDs = new double[ProblemData.TargetVariables.Count()]; 197 198 double[] trainingWds = new double[ProblemData.TargetVariables.Count()]; 199 double[] testWds = new double[ProblemData.TargetVariables.Count()]; 200 201 double[] trainingTheilsU = new double[ProblemData.TargetVariables.Count()]; 202 double[] testTheilsU = new double[ProblemData.TargetVariables.Count()]; 203 int i = 0; 204 var predictedContinuationTraining = PrognosedTrainingValues.ToArray(); 205 var predictedContinuationTest = PrognosedTestValues.ToArray(); 206 207 foreach (var targetVariable in ProblemData.TargetVariables) { 208 var actualTrainingValues = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TrainingIndizes).ToArray(); 209 var startTrainingValues = actualTrainingValues.Take(1); 210 // only one continuation (but the full training set) 211 var actualContinuationTraining = actualTrainingValues.Skip(1); 212 213 var actualTestValues = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TestIndizes).ToArray(); 214 var startTestValues = actualTestValues.Take(1); 215 // only one continuation (but the full training set) 216 var actualContinuationTest = actualTestValues.Skip(1); 217 218 219 trainingDs[i] = OnlineDirectionalSymmetryCalculator.Calculate(startTrainingValues, 220 Enumerable.Repeat(actualContinuationTraining, 1), 221 Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState); 222 if (errorState != OnlineCalculatorError.None) trainingDs[i] = double.NaN; 223 224 testDs[i] = OnlineDirectionalSymmetryCalculator.Calculate(startTestValues, 225 Enumerable.Repeat(actualContinuationTest, 1), 226 Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState); 227 if (errorState != OnlineCalculatorError.None) testDs[i] = double.NaN; 228 229 trainingWds[i] = 230 OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTrainingValues, 231 Enumerable.Repeat(actualContinuationTraining, 1), 232 Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState); 233 if (errorState != OnlineCalculatorError.None) trainingWds[i] = double.NaN; 234 235 testWds[i] = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTestValues, 236 Enumerable.Repeat(actualContinuationTest, 1), 237 Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState); 238 if (errorState != OnlineCalculatorError.None) testWds[i] = double.NaN; 239 240 trainingTheilsU[i] = OnlineTheilsUStatisticCalculator.Calculate(startTrainingValues, 241 Enumerable.Repeat(actualContinuationTraining, 1), 242 Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState); 243 if (errorState != OnlineCalculatorError.None) trainingTheilsU[i] = double.NaN; 244 245 testTheilsU[i] = OnlineTheilsUStatisticCalculator.Calculate(startTestValues, 246 Enumerable.Repeat(actualContinuationTest, 1), 247 Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState); 248 if (errorState != OnlineCalculatorError.None) testTheilsU[i] = double.NaN; 249 i++; 250 } 251 252 TrainingDirectionalSymmetry = trainingDs; 253 TestDirectionalSymmetry = testDs; 254 TrainingWeightedDirectionalSymmetry = trainingWds; 255 TestWeightedDirectionalSymmetry = testWds; 256 TrainingTheilsUStatistic = trainingTheilsU; 257 TestTheilsUStatistic = testTheilsU; 223 258 } 224 259 }
Note: See TracChangeset
for help on using the changeset viewer.