Changeset 8486 for branches/HeuristicLab.TimeSeries
- Timestamp:
- 08/14/12 13:59:47 (12 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator.cs
r7989 r8486 23 23 using System; 24 24 using System.Collections.Generic; 25 using System.Linq; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 61 62 [ThreadStatic] 62 63 private static double[] cache; 63 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, IOnlineCalculator calculator, int maxRows) { 64 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, 65 double lowerEstimationLimit, double upperEstimationLimit, 66 IOnlineCalculator calculator, int maxRows) { 64 67 if (cache == null || cache.GetLength(0) < maxRows) { 65 68 cache = new double[maxRows]; … … 76 79 double target = targetValuesEnumerator.Current; 77 80 double estimated = estimatedValuesEnumerator.Current; 81 cache[i] = estimated; 78 82 linearScalingCalculator.Add(estimated, target); 79 cache[i] = estimated;80 83 i++; 81 84 } … … 85 88 //calculate the quality by using the passed online calculator 86 89 targetValuesEnumerator = targetValues.GetEnumerator(); 87 i = 0; 88 while (targetValuesEnumerator.MoveNext()) { 89 double target = targetValuesEnumerator.Current; 90 double estimated = cache[i] * beta + alpha; 91 calculator.Add(target, estimated); 92 i++; 90 var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha) 91 .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator(); 92 93 while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) { 94 calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current); 93 95 } 94 96 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs
r8458 r8486 35 35 [StorableConstructor] 36 36 protected SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { } 37 protected SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator original, Cloner cloner) 38 : base(original, cloner) { 39 } 37 protected SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator original, Cloner cloner) : base(original, cloner) { } 40 38 public override IDeepCloneable Clone(Cloner cloner) { 41 39 return new SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(this, cloner); … … 65 63 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows.Zip(horizions, Enumerable.Range).SelectMany(r => r)); 66 64 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows, horizions).SelectMany(x => x); 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);68 65 OnlineCalculatorError errorState; 69 66 … … 71 68 if (applyLinearScaling && horizon == 1) { //perform normal evaluation and afterwards scale the solution and calculate the fitness value 72 69 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 73 CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows * horizon);70 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows * horizon); 74 71 errorState = mseCalculator.ErrorState; 75 72 mse = mseCalculator.MeanSquaredError; … … 79 76 var scaledSolution = model.SymbolicExpressionTree; 80 77 estimatedValues = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset, rows, horizions).SelectMany(x => x); 81 boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);78 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 82 79 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 83 } else 80 } else { 81 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 84 82 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 83 } 85 84 86 85 if (errorState != OnlineCalculatorError.None) return Double.NaN; 87 86 else return mse; 88 89 87 } 90 88 -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r8436 r8486 419 419 } 420 420 case OpCodes.Variable: { 421 if (row < 0 || row >= dataset.Rows) 422 return double.NaN; 421 if (row < 0 || row >= dataset.Rows) return double.NaN; 423 422 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 424 423 return ((IList<double>)currentInstr.iArg0)[row] * variableTreeNode.Weight; … … 427 426 var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; 428 427 int actualRow = row + laggedVariableTreeNode.Lag; 429 if (actualRow < 0 || actualRow >= dataset.Rows) 430 return double.NaN; 428 if (actualRow < 0 || actualRow >= dataset.Rows) return double.NaN; 431 429 return ((IList<double>)currentInstr.iArg0)[actualRow] * laggedVariableTreeNode.Weight; 432 430 } … … 439 437 //to determine the relative amounts of the true and false branch see http://en.wikipedia.org/wiki/Logistic_function 440 438 case OpCodes.VariableCondition: { 441 if (row < 0 || row >= dataset.Rows) 442 return double.NaN; 439 if (row < 0 || row >= dataset.Rows) return double.NaN; 443 440 var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode; 444 441 double variableValue = ((IList<double>)currentInstr.iArg0)[row]; -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r7989 r8486 278 278 <DependentUpon>RegressionSolutionView.cs</DependentUpon> 279 279 </Compile> 280 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionLineChartView.cs">281 <SubType>UserControl</SubType>282 </Compile>283 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionLineChartView.Designer.cs">284 <DependentUpon>TimeSeriesPrognosisSolutionLineChartView.cs</DependentUpon>285 </Compile>286 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionPrognosedValuesView.cs">287 <SubType>UserControl</SubType>288 </Compile>289 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionPrognosedValuesView.Designer.cs">290 <DependentUpon>TimeSeriesPrognosisSolutionPrognosedValuesView.cs</DependentUpon>291 </Compile>292 280 <None Include="HeuristicLab.snk" /> 293 281 <None Include="Plugin.cs.frame" /> … … 312 300 </BootstrapperPackage> 313 301 </ItemGroup> 314 <ItemGroup /> 302 <ItemGroup> 303 <Folder Include="TimeSeriesPrognosis\" /> 304 </ItemGroup> 315 305 <ItemGroup> 316 306 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj"> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r8468 r8486 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 65 66 int row = rowsEnumerator.Current; 66 67 int horizon = horizonsEnumerator.Current; 68 if (row - TimeOffset < 0) { 69 yield return Enumerable.Repeat(double.NaN, horizon); 70 continue; 71 } 72 67 73 double[] prognosis = new double[horizon]; 68 69 74 for (int h = 0; h < horizon; h++) { 70 75 double estimatedValue = 0.0; 71 for (int i = 1; i < TimeOffset; i++) {76 for (int i = 1; i <= TimeOffset; i++) { 72 77 int offset = h - i; 73 78 if (offset >= 0) estimatedValue += prognosis[offset] * Phi[i - 1]; … … 90 95 foreach (int row in rows) { 91 96 double estimatedValue = 0.0; 97 if (row - TimeOffset < 0) { 98 yield return double.NaN; 99 continue; 100 } 101 92 102 for (int i = 1; i <= TimeOffset; i++) { 93 103 estimatedValue += targetVariables[row - i] * Phi[i - 1]; -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisMovingAverageModel.cs
r8468 r8486 60 60 int horizon = horizonsEnumerator.Current; 61 61 int startIndex = row - WindowSize; 62 if (startIndex < 0) { 63 yield return Enumerable.Repeat(double.NaN, horizon); 64 continue; 65 } 62 66 63 if (startIndex < 0) startIndex = 0; 64 int count = row - startIndex - 1; 65 66 List<double> targetValues = dataset.GetDoubleValues(TargetVariable, Enumerable.Range(startIndex, count)).ToList(); 67 List<double> targetValues = dataset.GetDoubleValues(TargetVariable, Enumerable.Range(startIndex, WindowSize)).ToList(); 67 68 int position = 0; 68 69 for (int i = 0; i < horizon; i++) { 69 double prognosis = targetValues.GetRange(position, count).Average();70 double prognosis = targetValues.GetRange(position, WindowSize).Average(); 70 71 targetValues.Add(prognosis); 71 if (count < WindowSize) count++; 72 else position++; 72 position++; 73 73 } 74 74 yield return targetValues.GetRange(targetValues.Count - horizon, horizon); … … 80 80 81 81 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) { 82 return GetPrognosedValues(dataset, rows, rows.Select(r => 1)).SelectMany(e => e);83 }84 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows, int x) {85 82 var targetValues = dataset.GetReadOnlyDoubleValues(TargetVariable).ToList(); 86 83 foreach (int row in rows) { 87 yield return targetValues.GetRange(row - WindowSize, WindowSize).Average(); 84 if (row - WindowSize < 0) yield return double.NaN; 85 else yield return targetValues.GetRange(row - WindowSize, WindowSize).Average(); 88 86 } 89 87 } 90 91 88 92 89 public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) { -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs
r8477 r8486 1578 1578 } 1579 1579 1580 public TimeSeriesPrognosisProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { } 1580 public TimeSeriesPrognosisProblemData() 1581 : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { 1582 TrainingPartition.Start = 50; 1583 } 1581 1584 public TimeSeriesPrognosisProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable) 1582 1585 : base(dataset, allowedInputVariables, targetVariable) { … … 1587 1590 TestHorizonParameter.Hidden = true; 1588 1591 1592 TrainingPartition.Start = Math.Min((int)(TrainingPartition.Size * 0.2), 50); 1593 1589 1594 RegisterParameterEventHandlers(); 1590 1595 }
Note: See TracChangeset
for help on using the changeset viewer.