Changeset 8458 for branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis
- Timestamp:
- 08/09/12 13:48:43 (12 years ago)
- Location:
- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.