Changeset 8458
- Timestamp:
- 08/09/12 13:48:43 (12 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views-3.4.csproj
r7989 r8458 106 106 <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 107 107 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 108 <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 108 109 <Reference Include="HeuristicLab.Visualization.ChartControlsExtensions-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 109 110 <Reference Include="System" /> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
r8430 r8458 51 51 protected override void UpdateModel(ISymbolicExpressionTree tree) { 52 52 var model = new SymbolicTimeSeriesPrognosisModel(tree, Content.Model.Interpreter); 53 SymbolicTimeSeriesPrognosisModel.Scale(model, Content.ProblemData , Content.ProblemData.TrainingIndices);53 SymbolicTimeSeriesPrognosisModel.Scale(model, Content.ProblemData); 54 54 Content.Model = model; 55 55 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj
r7989 r8458 107 107 <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 108 108 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 109 <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 109 110 <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 110 111 <Reference Include="System" /> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs
r8114 r8458 76 76 } else if (applyLinearScaling) { //first create model to perform linear scaling and afterwards calculate fitness for the scaled model 77 77 var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)solution.Clone(), interpreter, lowerEstimationLimit, upperEstimationLimit); 78 SymbolicTimeSeriesPrognosisModel.Scale(model, problemData , rows);78 SymbolicTimeSeriesPrognosisModel.Scale(model, problemData); 79 79 var scaledSolution = model.SymbolicExpressionTree; 80 80 estimatedValues = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset, rows, horizions).SelectMany(x => x); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveTrainingBestSolutionAnalyzer.cs
r8430 r8458 76 76 protected override ISymbolicTimeSeriesPrognosisSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 77 77 var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 78 if (ApplyLinearScaling.Value) 79 SymbolicTimeSeriesPrognosisModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); 78 if (ApplyLinearScaling.Value) SymbolicTimeSeriesPrognosisModel.Scale(model, ProblemDataParameter.ActualValue); 80 79 return new SymbolicTimeSeriesPrognosisSolution(model, (ITimeSeriesPrognosisProblemData)ProblemDataParameter.ActualValue.Clone()); 81 80 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveValidationBestSolutionAnalyzer.cs
r8430 r8458 65 65 protected override ISymbolicTimeSeriesPrognosisSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) { 66 66 var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue as ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 67 if (ApplyLinearScaling.Value) 68 SymbolicTimeSeriesPrognosisModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); 67 if (ApplyLinearScaling.Value) SymbolicTimeSeriesPrognosisModel.Scale(model, ProblemDataParameter.ActualValue); 68 69 69 return new SymbolicTimeSeriesPrognosisSolution(model, (ITimeSeriesPrognosisProblemData)ProblemDataParameter.ActualValue.Clone()); 70 70 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs
r8114 r8458 21 21 22 22 using System.Collections.Generic; 23 using System.Drawing;24 23 using System.Linq; 25 24 using HeuristicLab.Common; … … 27 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis { … … 34 34 [StorableClass] 35 35 [Item(Name = "Symbolic Time-Series Prognosis Model", Description = "Represents a symbolic time series prognosis model.")] 36 public class SymbolicTimeSeriesPrognosisModel : NamedItem, ISymbolicTimeSeriesPrognosisModel { 37 public override Image ItemImage { 38 get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; } 36 public class SymbolicTimeSeriesPrognosisModel : SymbolicRegressionModel, ISymbolicTimeSeriesPrognosisModel { 37 38 public new ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter Interpreter { 39 get { return (ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter)base.Interpreter; } 39 40 } 40 [Storable(DefaultValue = double.MinValue)]41 private double lowerEstimationLimit;42 [Storable(DefaultValue = double.MaxValue)]43 private double upperEstimationLimit;44 45 #region properties46 47 [Storable]48 private ISymbolicExpressionTree symbolicExpressionTree;49 public ISymbolicExpressionTree SymbolicExpressionTree {50 get { return symbolicExpressionTree; }51 }52 53 [Storable]54 private ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter;55 public ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter Interpreter {56 get { return interpreter; }57 }58 59 ISymbolicDataAnalysisExpressionTreeInterpreter ISymbolicDataAnalysisModel.Interpreter {60 get { return (ISymbolicDataAnalysisExpressionTreeInterpreter)interpreter; }61 }62 63 #endregion64 41 65 42 [StorableConstructor] 66 43 protected SymbolicTimeSeriesPrognosisModel(bool deserializing) : base(deserializing) { } 67 protected SymbolicTimeSeriesPrognosisModel(SymbolicTimeSeriesPrognosisModel original, Cloner cloner) 68 : base(original, cloner) { 69 this.symbolicExpressionTree = cloner.Clone(original.symbolicExpressionTree); 70 this.interpreter = cloner.Clone(original.interpreter); 71 this.lowerEstimationLimit = original.lowerEstimationLimit; 72 this.upperEstimationLimit = original.upperEstimationLimit; 73 } 74 public SymbolicTimeSeriesPrognosisModel(ISymbolicExpressionTree tree, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, double lowerLimit = double.MinValue, double upperLimit = double.MaxValue) 75 : base() { 76 this.name = ItemName; 77 this.description = ItemDescription; 78 this.symbolicExpressionTree = tree; 79 this.interpreter = interpreter; 80 this.lowerEstimationLimit = lowerLimit; 81 this.upperEstimationLimit = upperLimit; 82 } 83 44 protected SymbolicTimeSeriesPrognosisModel(SymbolicTimeSeriesPrognosisModel original, Cloner cloner) : base(original, cloner) { } 84 45 public override IDeepCloneable Clone(Cloner cloner) { 85 46 return new SymbolicTimeSeriesPrognosisModel(this, cloner); 86 47 } 87 48 49 public SymbolicTimeSeriesPrognosisModel(ISymbolicExpressionTree tree, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, double lowerLimit = double.MinValue, double upperLimit = double.MaxValue) : base(tree, interpreter, lowerLimit, upperLimit) { } 50 51 52 88 53 public IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { 89 54 var estimatedValues = Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows, horizons); 90 return estimatedValues.Select(predictionPerRow => predictionPerRow.LimitToRange( lowerEstimationLimit, upperEstimationLimit));55 return estimatedValues.Select(predictionPerRow => predictionPerRow.LimitToRange(LowerEstimationLimit, UpperEstimationLimit)); 91 56 } 92 57 … … 98 63 } 99 64 100 public static void Scale(SymbolicTimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows) {101 var dataset = problemData.Dataset;102 var targetVariable = problemData.TargetVariable;103 var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows);104 var boundedEstimatedValues = estimatedValues.LimitToRange(model.lowerEstimationLimit, model.upperEstimationLimit);105 var targetValues = problemData.Dataset.GetDoubleValues(targetVariable, rows);65 //public static void Scale(SymbolicTimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows) { 66 // var dataset = problemData.Dataset; 67 // var targetVariable = problemData.TargetVariable; 68 // var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows); 69 // var boundedEstimatedValues = estimatedValues.LimitToRange(model.lowerEstimationLimit, model.upperEstimationLimit); 70 // var targetValues = problemData.Dataset.GetDoubleValues(targetVariable, rows); 106 71 107 double alpha, beta;108 OnlineCalculatorError error;109 OnlineLinearScalingParameterCalculator.Calculate(boundedEstimatedValues, targetValues, out alpha, out beta, out error);110 if (error != OnlineCalculatorError.None) return;72 // double alpha, beta; 73 // OnlineCalculatorError error; 74 // OnlineLinearScalingParameterCalculator.Calculate(boundedEstimatedValues, targetValues, out alpha, out beta, out error); 75 // if (error != OnlineCalculatorError.None) return; 111 76 112 ConstantTreeNode alphaTreeNode = null;113 ConstantTreeNode betaTreeNode = null;114 // check if model has been scaled previously by analyzing the structure of the tree115 var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0);116 if (startNode.GetSubtree(0).Symbol is Addition) {117 var addNode = startNode.GetSubtree(0);118 if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {119 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode;120 var mulNode = addNode.GetSubtree(0);121 if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {122 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode;123 }124 }125 }126 // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes127 if (alphaTreeNode != null && betaTreeNode != null) {128 betaTreeNode.Value *= beta;129 alphaTreeNode.Value *= beta;130 alphaTreeNode.Value += alpha;131 } else {132 var mainBranch = startNode.GetSubtree(0);133 startNode.RemoveSubtree(0);134 var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha);135 startNode.AddSubtree(scaledMainBranch);136 }137 }77 // ConstantTreeNode alphaTreeNode = null; 78 // ConstantTreeNode betaTreeNode = null; 79 // // check if model has been scaled previously by analyzing the structure of the tree 80 // var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0); 81 // if (startNode.GetSubtree(0).Symbol is Addition) { 82 // var addNode = startNode.GetSubtree(0); 83 // if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) { 84 // alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode; 85 // var mulNode = addNode.GetSubtree(0); 86 // if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) { 87 // betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode; 88 // } 89 // } 90 // } 91 // // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes 92 // if (alphaTreeNode != null && betaTreeNode != null) { 93 // betaTreeNode.Value *= beta; 94 // alphaTreeNode.Value *= beta; 95 // alphaTreeNode.Value += alpha; 96 // } else { 97 // var mainBranch = startNode.GetSubtree(0); 98 // startNode.RemoveSubtree(0); 99 // var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha); 100 // startNode.AddSubtree(scaledMainBranch); 101 // } 102 //} 138 103 139 private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) {140 if (alpha.IsAlmost(0.0)) {141 return treeNode;142 } else {143 var addition = new Addition();144 var node = addition.CreateTreeNode();145 var alphaConst = MakeConstant(alpha);146 node.AddSubtree(treeNode);147 node.AddSubtree(alphaConst);148 return node;149 }150 }104 //private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) { 105 // if (alpha.IsAlmost(0.0)) { 106 // return treeNode; 107 // } else { 108 // var addition = new Addition(); 109 // var node = addition.CreateTreeNode(); 110 // var alphaConst = MakeConstant(alpha); 111 // node.AddSubtree(treeNode); 112 // node.AddSubtree(alphaConst); 113 // return node; 114 // } 115 //} 151 116 152 private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {153 if (beta.IsAlmost(1.0)) {154 return treeNode;155 } else {156 var multipliciation = new Multiplication();157 var node = multipliciation.CreateTreeNode();158 var betaConst = MakeConstant(beta);159 node.AddSubtree(treeNode);160 node.AddSubtree(betaConst);161 return node;162 }163 }117 //private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) { 118 // if (beta.IsAlmost(1.0)) { 119 // return treeNode; 120 // } else { 121 // var multipliciation = new Multiplication(); 122 // var node = multipliciation.CreateTreeNode(); 123 // var betaConst = MakeConstant(beta); 124 // node.AddSubtree(treeNode); 125 // node.AddSubtree(betaConst); 126 // return node; 127 // } 128 //} 164 129 165 private static ISymbolicExpressionTreeNode MakeConstant(double c) {166 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();167 node.Value = c;168 return node;169 }130 //private static ISymbolicExpressionTreeNode MakeConstant(double c) { 131 // var node = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 132 // node.Value = c; 133 // return node; 134 //} 170 135 } 171 136 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblem.cs
r7842 r8458 66 66 } 67 67 68 protected DataAnalysisProblem(T problemData) 69 : this() { 70 ProblemData = problemData; 71 } 72 68 73 [StorableHook(HookType.AfterDeserialization)] 69 74 private void AfterDeserialization() { -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r7268 r8458 30 30 public class ConstantRegressionModel : NamedItem, IRegressionModel { 31 31 [Storable] 32 pr ivatedouble constant;32 protected double constant; 33 33 public double Constant { 34 34 get { return constant; } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r8430 r8458 155 155 } 156 156 157 protected override void RecalculateResults() {158 CalculateResults();159 }160 161 157 #region Evaluation 162 158 public override IEnumerable<double> EstimatedTrainingValues { -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs
r7842 r8458 36 36 public override IDeepCloneable Clone(Cloner cloner) { return new RegressionProblem(this, cloner); } 37 37 38 public RegressionProblem() 39 : base() { 40 ProblemData = new RegressionProblemData(); 41 } 38 public RegressionProblem() : base(new RegressionProblemData()) { } 39 42 40 } 43 41 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs
r8430 r8458 47 47 } 48 48 49 protected override void RecalculateResults() {50 CalculateResults();51 }52 53 49 public override IEnumerable<double> EstimatedValues { 54 50 get { return GetEstimatedValues(Enumerable.Range(0, ProblemData.Dataset.Rows)); } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs
r8430 r8458 164 164 } 165 165 166 protected void CalculateResults() { 166 protected override void RecalculateResults() { 167 CalculateResults(); 168 } 169 170 private void CalculateResults() { 167 171 IEnumerable<double> estimatedTrainingValues = EstimatedTrainingValues; // cache values 168 172 IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/ConstantTimeSeriesPrognosisModel.cs
r8430 r8458 29 29 [StorableClass] 30 30 [Item("Constant TimeSeries Model", "A time series model that returns for all prediciton the same constant value.")] 31 public class ConstantTimeSeriesPrognosisModel : NamedItem, ITimeSeriesPrognosisModel { 32 [Storable] 33 public double Constant { get; private set; } 34 31 public class ConstantTimeSeriesPrognosisModel : ConstantRegressionModel, ITimeSeriesPrognosisModel { 35 32 [StorableConstructor] 36 33 protected ConstantTimeSeriesPrognosisModel(bool deserializing) : base(deserializing) { } 37 protected ConstantTimeSeriesPrognosisModel(ConstantTimeSeriesPrognosisModel original, Cloner cloner) 38 : base(original, cloner) { 39 Constant = original.Constant; 40 } 34 protected ConstantTimeSeriesPrognosisModel(ConstantTimeSeriesPrognosisModel original, Cloner cloner) : base(original, cloner) { } 41 35 public override IDeepCloneable Clone(Cloner cloner) { 42 36 return new ConstantTimeSeriesPrognosisModel(this, cloner); 43 37 } 44 38 45 public ConstantTimeSeriesPrognosisModel(double constant) { 46 Constant = constant; 47 } 39 public ConstantTimeSeriesPrognosisModel(double constant) : base(constant) { } 48 40 49 41 public IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r8430 r8458 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 62 63 var rowsEnumerator = rows.GetEnumerator(); 63 64 var horizonsEnumerator = horizons.GetEnumerator(); 65 var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable); 64 66 // produce a n-step forecast for all rows 65 67 while (rowsEnumerator.MoveNext() & horizonsEnumerator.MoveNext()) { … … 67 69 int horizon = horizonsEnumerator.Current; 68 70 double[] prognosis = new double[horizon]; 69 70 prognosis[0] = dataset.GetDoubleValue(TargetVariable, row - TimeOffset); 71 for (int i = 1; i < horizon; i++) { 72 //prognosis[i] = Beta * prognosis[i - 1] + Alpha; 73 } 71 for (int i = 0; i < horizon; i++) 72 prognosis[i] = targetVariables[row - TimeOffset]; 74 73 yield return prognosis; 75 74 } … … 79 78 } 80 79 80 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) { 81 return GetPrognosedValues(dataset, rows, rows.Select(r => 1)).SelectMany(e => e); 82 } 83 81 84 public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) { 82 85 return new TimeSeriesPrognosisSolution(this, problemData); 86 } 87 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 88 throw new NotSupportedException(); 83 89 } 84 90 -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisMovingAverageModel.cs
r8430 r8458 79 79 } 80 80 81 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) { 82 return GetPrognosedValues(dataset, rows, rows.Select(r => 1)).SelectMany(e => e); 83 } 84 81 85 public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) { 82 86 return new TimeSeriesPrognosisSolution(this, problemData); 87 } 88 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 89 throw new NotSupportedException(); 83 90 } 84 91 -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblem.cs
r7843 r8458 34 34 public override IDeepCloneable Clone(Cloner cloner) { return new TimeSeriesPrognosisProblem(this, cloner); } 35 35 36 public TimeSeriesPrognosisProblem() 37 : base() { 38 ProblemData = new TimeSeriesPrognosisProblemData(); 39 } 40 36 public TimeSeriesPrognosisProblem() : base(new TimeSeriesPrognosisProblemData()) { } 41 37 } 42 38 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolution.cs
r8010 r8458 35 35 protected internal TimeSeriesPrognosisSolution(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) : base(model, problemData) { } 36 36 37 protected override void RecalculateResults() {38 CalculateResults();39 }40 41 37 public override IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizons) { 42 38 return Model.GetPrognosedValues(ProblemData.Dataset, rows, horizons); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
r8430 r8458 30 30 namespace HeuristicLab.Problems.DataAnalysis { 31 31 [StorableClass] 32 public abstract class TimeSeriesPrognosisSolutionBase : DataAnalysisSolution, ITimeSeriesPrognosisSolution { 33 private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)"; 34 private const string TestMeanSquaredErrorResultName = "Mean squared error (test)"; 35 private const string TrainingMeanAbsoluteErrorResultName = "Mean absolute error (training)"; 36 private const string TestMeanAbsoluteErrorResultName = "Mean absolute error (test)"; 37 private const string TrainingSquaredCorrelationResultName = "Pearson's R² (training)"; 38 private const string TestSquaredCorrelationResultName = "Pearson's R² (test)"; 39 private const string TrainingRelativeErrorResultName = "Average relative error (training)"; 40 private const string TestRelativeErrorResultName = "Average relative error (test)"; 41 private const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)"; 42 private const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)"; 32 public abstract class TimeSeriesPrognosisSolutionBase : RegressionSolutionBase, ITimeSeriesPrognosisSolution { 43 33 private const string TrainingDirectionalSymmetryResultName = "Average directional symmetry (training)"; 44 34 private const string TestDirectionalSymmetryResultName = "Average directional symmetry (test)"; … … 77 67 78 68 #region Results 79 public double TrainingMeanSquaredError {80 get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; }81 private set { ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value = value; }82 }83 public double TestMeanSquaredError {84 get { return ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value; }85 private set { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; }86 }87 public double TrainingMeanAbsoluteError {88 get { return ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value; }89 private set { ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value = value; }90 }91 public double TestMeanAbsoluteError {92 get { return ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value; }93 private set { ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value = value; }94 }95 public double TrainingRSquared {96 get { return ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value; }97 private set { ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value = value; }98 }99 public double TestRSquared {100 get { return ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value; }101 private set { ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value = value; }102 }103 public double TrainingRelativeError {104 get { return ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value; }105 private set { ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value = value; }106 }107 public double TestRelativeError {108 get { return ((DoubleValue)this[TestRelativeErrorResultName].Value).Value; }109 private set { ((DoubleValue)this[TestRelativeErrorResultName].Value).Value = value; }110 }111 public double TrainingNormalizedMeanSquaredError {112 get { return ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value; }113 private set { ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value = value; }114 }115 public double TestNormalizedMeanSquaredError {116 get { return ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value; }117 private set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; }118 }119 69 public double TrainingDirectionalSymmetry { 120 70 get { return ((DoubleValue)this[TrainingDirectionalSymmetryResultName].Value).Value; } … … 158 108 } 159 109 #endregion 110 111 public override IEnumerable<double> EstimatedValues { 112 get { return GetEstimatedValues(Enumerable.Range(0, ProblemData.Dataset.Rows)); } 113 } 114 public override IEnumerable<double> EstimatedTrainingValues { 115 get { return GetEstimatedValues(ProblemData.TrainingIndices); } 116 } 117 public override IEnumerable<double> EstimatedTestValues { 118 get { return GetEstimatedValues(ProblemData.TestIndices); } 119 } 120 public override IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 121 return Model.GetEstimatedValues(ProblemData.Dataset, rows); 122 } 160 123 161 124 [StorableConstructor] … … 167 130 protected TimeSeriesPrognosisSolutionBase(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) 168 131 : base(model, problemData) { 169 Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue()));170 Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue()));171 Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue()));172 Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue()));173 Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));174 Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));175 Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new DoubleValue()));176 Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new DoubleValue()));177 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue()));178 Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue()));179 132 Add(new Result(TrainingDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the training partition", new DoubleValue())); 180 133 Add(new Result(TestDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the test partition", new DoubleValue())); … … 190 143 } 191 144 192 193 protected void CalculateResults() { 145 protected override void RecalculateResults() { 146 base.RecalculateResults(); 147 CalculateTimeSeriesResults(); 148 } 149 150 private void CalculateTimeSeriesResults() { 194 151 OnlineCalculatorError errorState; 195 152 //mean model … … 211 168 IEnumerable<IEnumerable<double>> trainingTargetValues = ProblemData.TrainingIndices.Zip(trainingHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList(); 212 169 IEnumerable<IEnumerable<double>> trainingEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, 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 170 IEnumerable<IEnumerable<double>> trainingMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions); 226 171 IEnumerable<IEnumerable<double>> trainingAR1ModelPredictions = AR1model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TrainingIndices, trainingHorizions); … … 243 188 IEnumerable<IEnumerable<double>> testTargetValues = ProblemData.TestIndices.Zip(testHorizions, Enumerable.Range).Select(r => ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, r)).ToList(); 244 189 IEnumerable<IEnumerable<double>> testEstimatedValues = Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, 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 190 IEnumerable<double> testStartValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices.Select(r => r - 1).Where(r => r > 0)).ToList(); 258 191 IEnumerable<IEnumerable<double>> testMeanModelPredictions = meanModel.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices, testHorizions); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisModel.cs
r8010 r8458 22 22 using System.Collections.Generic; 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 public interface ITimeSeriesPrognosisModel : I DataAnalysisModel {24 public interface ITimeSeriesPrognosisModel : IRegressionModel { 25 25 IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons); 26 26 ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisProblemData.cs
r7989 r8458 21 21 22 22 namespace HeuristicLab.Problems.DataAnalysis { 23 public interface ITimeSeriesPrognosisProblemData : IDataAnalysisProblemData { 24 string TargetVariable { get; } 23 public interface ITimeSeriesPrognosisProblemData : IRegressionProblemData { 25 24 } 26 25 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisSolution.cs
r8010 r8458 22 22 using System.Collections.Generic; 23 23 namespace HeuristicLab.Problems.DataAnalysis { 24 public interface ITimeSeriesPrognosisSolution : I DataAnalysisSolution {24 public interface ITimeSeriesPrognosisSolution : IRegressionSolution { 25 25 int Horizon { get; set; } 26 26 new ITimeSeriesPrognosisModel Model { get; } … … 29 29 IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizon); 30 30 31 double TrainingMeanSquaredError { get; }32 double TestMeanSquaredError { get; }33 double TrainingMeanAbsoluteError { get; }34 double TestMeanAbsoluteError { get; }35 double TrainingRSquared { get; }36 double TestRSquared { get; }37 double TrainingRelativeError { get; }38 double TestRelativeError { get; }39 double TrainingNormalizedMeanSquaredError { get; }40 double TestNormalizedMeanSquaredError { get; }41 31 double TrainingTheilsUStatisticLast { get; } 42 32 double TestTheilsUStatisticLast { get; }
Note: See TracChangeset
for help on using the changeset viewer.