Changeset 7154
- Timestamp:
- 12/07/11 22:47:12 (13 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 1 added
- 17 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
r7129 r7154 110 110 </ItemGroup> 111 111 <ItemGroup> 112 <Compile Include="InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs">113 <SubType>UserControl</SubType>114 </Compile>115 <Compile Include="InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.Designer.cs">116 <DependentUpon>InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs</DependentUpon>117 </Compile>118 112 <Compile Include="Plugin.cs" /> 119 113 <Compile Include="SymbolicTimeSeriesPrognosisSolutionView.cs"> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs
r7129 r7154 69 69 Dictionary<ISymbolicExpressionTreeNode, double> impactValues = 70 70 new Dictionary<ISymbolicExpressionTreeNode, double>(); 71 var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows , 1)71 var originalOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows) 72 72 .ToArray(); 73 73 int i = 0; … … 76 76 var targetValues = dataset.GetDoubleValues(targetVariable, rows); 77 77 OnlineCalculatorError errorState; 78 double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput.Select(v => v.ElementAt(i) .First()), out errorState);78 double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput.Select(v => v.ElementAt(i)), out errorState); 79 79 if (errorState != OnlineCalculatorError.None) originalR2 = 0.0; 80 80 … … 85 85 SwitchNode(parent, node, replacementNode); 86 86 var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, Content.ProblemData.TargetVariables.ToArray(), rows, 1); 87 double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput.Select(v => v. ElementAt(i).First()), out errorState);87 double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput.Select(v => v.First().ElementAt(i)), out errorState); 88 88 if (errorState != OnlineCalculatorError.None) newR2 = 0.0; 89 89 -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/SymbolicTimeSeriesPrognosisSolutionView.cs
r6807 r7154 39 39 40 40 private void btn_SimplifyModel_Click(object sender, EventArgs e) { 41 InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView view = new InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView();42 view.Content = (SymbolicTimeSeriesPrognosisSolution)this.Content.Clone();43 view.Show();41 //InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView view = new InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView(); 42 //view.Content = (SymbolicTimeSeriesPrognosisSolution)this.Content.Clone(); 43 //view.Show(); 44 44 } 45 45 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs
r7129 r7154 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing.Printing; 24 25 using System.Linq; 25 26 using HeuristicLab.Common; … … 65 66 DetermineScalingFactors(solution, problemData, interpreter, rows, out alpha, out beta); 66 67 var scaledSolution = Scale(solution, alpha, beta); 67 68 string[] targetVariables = problemData.TargetVariables.ToArray(); 68 69 var meanSquaredErrorCalculators = Enumerable.Range(0, problemData.TargetVariables.Count()) 69 70 .Select(i => new OnlineMeanSquaredErrorCalculator()).ToArray(); 70 71 71 var allPredictedContinuations = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset, 72 problemData.TargetVariables.ToArray(), 73 rows, horizon); 74 var allContinuationsEnumerator = allPredictedContinuations.GetEnumerator(); 75 var rowsEnumerator = rows.GetEnumerator(); 76 while (allContinuationsEnumerator.MoveNext() & rowsEnumerator.MoveNext()) { 77 var componentEnumerator = allContinuationsEnumerator.Current.GetEnumerator(); 78 var mseCalculatorsEnumerator = meanSquaredErrorCalculators.AsEnumerable().GetEnumerator(); 79 var targetVarEnumerator = problemData.TargetVariables.GetEnumerator(); 80 while (componentEnumerator.MoveNext() & mseCalculatorsEnumerator.MoveNext() & targetVarEnumerator.MoveNext()) { 81 var stepEnumerator = componentEnumerator.Current.GetEnumerator(); 82 var actualContinuationEnumerator = problemData.Dataset.GetDoubleValues(targetVarEnumerator.Current, 83 Enumerable.Range(rowsEnumerator.Current, horizon)).GetEnumerator(); 84 while (stepEnumerator.MoveNext() & actualContinuationEnumerator.MoveNext()) { 85 double e = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, stepEnumerator.Current)); 86 mseCalculatorsEnumerator.Current.Add(actualContinuationEnumerator.Current, e); 87 if (mseCalculatorsEnumerator.Current.ErrorState == OnlineCalculatorError.InvalidValueAdded) 88 return double.NaN; 72 var allContinuationsEnumerator = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset, 73 targetVariables, 74 rows, horizon).GetEnumerator(); 75 allContinuationsEnumerator.MoveNext(); 76 // foreach row 77 foreach (var row in rows) { 78 // foreach horizon 79 for (int h = 0; h < horizon; h++) { 80 // foreach component 81 for (int i = 0; i < meanSquaredErrorCalculators.Length; i++) { 82 double e = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, allContinuationsEnumerator.Current)); 83 meanSquaredErrorCalculators[i].Add(problemData.Dataset.GetDoubleValue(targetVariables[i], row + h), e); 84 if (meanSquaredErrorCalculators[i].ErrorState == OnlineCalculatorError.InvalidValueAdded) 85 return double.MaxValue; 86 allContinuationsEnumerator.MoveNext(); 89 87 } 90 88 } … … 92 90 var meanCalculator = new OnlineMeanAndVarianceCalculator(); 93 91 foreach (var calc in meanSquaredErrorCalculators) { 94 if (calc.ErrorState != OnlineCalculatorError.None) return double. NaN;92 if (calc.ErrorState != OnlineCalculatorError.None) return double.MaxValue; 95 93 meanCalculator.Add(calc.MeanSquaredError); 96 94 } … … 109 107 // } 110 108 //} 111 return meanCalculator.MeanErrorState == OnlineCalculatorError.None ? meanCalculator.Mean : double. NaN;109 return meanCalculator.MeanErrorState == OnlineCalculatorError.None ? meanCalculator.Mean : double.MaxValue; 112 110 } 113 111 … … 153 151 alpha = new double[nComponents]; 154 152 beta = new double[nComponents]; 155 var oneStepPredictions = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, 156 targetVariables, rows, 157 1); 153 var oneStepPredictionsEnumerator = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, targetVariables, rows).GetEnumerator(); 154 var scalingParameterCalculators = 155 Enumerable.Repeat(0, nComponents).Select(x => new OnlineLinearScalingParameterCalculator()).ToArray(); 156 var targetValues = problemData.Dataset.GetVectorEnumerable(targetVariables, rows); 157 var targetValueEnumerator = targetValues.GetEnumerator(); 158 159 var more = oneStepPredictionsEnumerator.MoveNext() & targetValueEnumerator.MoveNext(); 160 while (more) { 161 for (int i = 0; i < nComponents; i++) { 162 scalingParameterCalculators[i].Add(oneStepPredictionsEnumerator.Current, targetValueEnumerator.Current); 163 more = oneStepPredictionsEnumerator.MoveNext() & targetValueEnumerator.MoveNext(); 164 } 165 } 166 158 167 for (int i = 0; i < nComponents; i++) { 159 var target = problemData.Dataset.GetDoubleValues(targetVariables[i], rows); 160 var prediction = oneStepPredictions.Select(v => v.ElementAt(i).First()); 161 OnlineCalculatorError errorState; 162 OnlineLinearScalingParameterCalculator.Calculate(prediction, target, out alpha[i], out beta[i], out errorState); 163 if (errorState != OnlineCalculatorError.None) { 164 alpha[i] = 0; 165 beta[i] = 1; 168 if (scalingParameterCalculators[i].ErrorState == OnlineCalculatorError.None) { 169 alpha[i] = scalingParameterCalculators[i].Alpha; 170 beta[i] = scalingParameterCalculators[i].Beta; 171 } else { 172 alpha[i] = 0.0; 173 beta[i] = 1.0; 166 174 } 167 175 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveProblem.cs
r7129 r7154 57 57 EstimationLimitsParameter.Hidden = true; 58 58 59 Maximization.Value = true;59 Maximization.Value = false; 60 60 MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth; 61 61 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; … … 106 106 op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name; 107 107 } 108 foreach (var op in operators.OfType<SymbolicTimeSeriesPrognosisSingleObjectiveTrainingBestSolutionAnalyzer>()) 109 { 110 op.MaximizationParameter.ActualName = MaximizationParameter.Name; 111 op.ProblemDataParameter.ActualName = ProblemDataParameter.Name; 112 op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 113 op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name; 114 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 115 } 108 116 } 109 117 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs
r7129 r7154 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Drawing; … … 69 70 this.symbolicExpressionTree = cloner.Clone(original.symbolicExpressionTree); 70 71 this.interpreter = cloner.Clone(original.interpreter); 72 this.targetVariables = new string[original.targetVariables.Length]; 73 Array.Copy(original.targetVariables, this.targetVariables, this.targetVariables.Length); 71 74 } 72 75 public SymbolicTimeSeriesPrognosisModel(ISymbolicExpressionTree tree, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, IEnumerable<string> targetVariables) … … 83 86 84 87 public IEnumerable<IEnumerable<IEnumerable<double>>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, int horizon) { 85 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, targetVariables, rows, horizon); 88 var enumerator = 89 Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, targetVariables, rows, horizon). 90 GetEnumerator(); 91 foreach (var r in rows) { 92 var l = new List<double[]>(); 93 for (int h = 0; h < horizon; h++) { 94 double[] components = new double[targetVariables.Length]; 95 for (int c = 0; c < components.Length; c++) { 96 enumerator.MoveNext(); 97 components[c] = enumerator.Current; 98 } 99 l.Add(components); 100 } 101 yield return l; 102 } 86 103 } 87 104 … … 95 112 public static void Scale(SymbolicTimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData) { 96 113 var dataset = problemData.Dataset; 97 var targetVariables = problemData.TargetVariables ;114 var targetVariables = problemData.TargetVariables.ToArray(); 98 115 var rows = problemData.TrainingIndizes; 99 int i = 0; 100 int horizon = 1; 101 var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, problemData.TargetVariables.ToArray(), rows, horizon) 102 .ToArray(); 103 foreach (var targetVariable in targetVariables) { 104 var targetValues = dataset.GetDoubleValues(targetVariable, rows); 105 double alpha; 106 double beta; 107 OnlineCalculatorError errorState; 108 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues.Select(x => x.ElementAt(i).First()), targetValues, 109 out alpha, out beta, out errorState); 110 if (errorState != OnlineCalculatorError.None) continue; 116 var estimatedValuesEnumerator = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, 117 targetVariables, 118 rows).GetEnumerator(); 119 var scalingParameterCalculators = 120 problemData.TargetVariables.Select(v => new OnlineLinearScalingParameterCalculator()).ToArray(); 121 var targetValuesEnumerator = problemData.Dataset.GetVectorEnumerable(targetVariables, rows).GetEnumerator(); 111 122 123 var more = targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext(); 124 // foreach row 125 while (more) { 126 // foreach component 127 for (int i = 0; i < targetVariables.Length; i++) { 128 scalingParameterCalculators[i].Add(estimatedValuesEnumerator.Current, targetValuesEnumerator.Current); 129 more = estimatedValuesEnumerator.MoveNext() & targetValuesEnumerator.MoveNext(); 130 } 131 } 132 133 for (int i = 0; i < targetVariables.Count(); i++) { 134 if (scalingParameterCalculators[i].ErrorState != OnlineCalculatorError.None) continue; 135 double alpha = scalingParameterCalculators[i].Alpha; 136 double beta = scalingParameterCalculators[i].Beta; 112 137 ConstantTreeNode alphaTreeNode = null; 113 138 ConstantTreeNode betaTreeNode = null; … … 136 161 startNode.InsertSubtree(i, scaledMainBranch); 137 162 } 138 i++;139 163 } // foreach 140 164 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer.cs
r5882 r7154 85 85 86 86 var results = ResultCollection; 87 if ( TrainingBestSolutionQuality == null ||88 IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value)) {87 if (bestTree != null && (TrainingBestSolutionQuality == null || 88 IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value))) { 89 89 TrainingBestSolution = CreateSolution(bestTree, bestQuality); 90 90 TrainingBestSolutionQuality = new DoubleValue(bestQuality); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicTimeSeriesPrognogisExpressionTreeInterpreter.cs
r7120 r7154 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 public interface ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter : INamedItem { 28 IEnumerable<IEnumerable<IEnumerable<double>>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon); 27 public interface ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter : INamedItem { 28 IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, 29 string[] targetVariables, IEnumerable<int> rows); 30 IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon); 29 31 } 30 32 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r7129 r7154 46 46 private static MethodInfo round = typeof(Math).GetMethod("Round", new Type[] { typeof(double) }); 47 47 48 internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns );48 internal delegate double CompiledFunction(int sampleIndex, IList<double>[] columns, IList<double>[] cachedValues, int cacheStartIndex); 49 49 private const string CheckExpressionsWithIntervalArithmeticParameterName = "CheckExpressionsWithIntervalArithmetic"; 50 50 #region private classes … … 179 179 180 180 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 181 return from prog in GetSymbolicExpressionTreeValues(tree, dataset, new string[] { "#NOTHING#" }, rows, 1) 182 select prog.First().First(); 183 } 184 185 // for each row for each target variable one prognosis (=enumerable of future values) 186 public IEnumerable<IEnumerable<IEnumerable<double>>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) { 181 return GetSymbolicExpressionTreeValues(tree, dataset, new string[] { "#NOTHING#" }, rows); 182 } 183 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows) { 184 return GetSymbolicExpressionTreeValues(tree, dataset, targetVariables, rows, 1); 185 } 186 // for each row for each horizon for each target variable one value 187 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) { 187 188 if (CheckExpressionsWithIntervalArithmetic.Value) 188 189 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); … … 211 212 } 212 213 var state = new InterpreterState(code); 213 Type[] methodArgs = { typeof(int), typeof(IList<double>[]) };214 Type[] methodArgs = { typeof(int), typeof(IList<double>[]), typeof(IList<double>[]), typeof(int) }; 214 215 215 216 CompiledFunction[] function = new CompiledFunction[targetVariables.Length]; … … 222 223 function[i] = (CompiledFunction)testFun.CreateDelegate(typeof(CompiledFunction)); 223 224 } 224 int nComponents = tree.Root.GetSubtree(0).SubtreeCount;225 // produce a n-step forecast for each target variable for all rows226 225 var values = doubleVariableNames.Keys 227 .Select(v => targetVariables.Contains(v) ? 228 (IList<double>)dataset.GetDoubleValues(v).ToList() : 229 dataset.GetReadOnlyDoubleValues(v)) 230 .Concat(new List<double>[] { Enumerable.Repeat(0.0, dataset.Rows).ToList() }) // append list for calculated target variable 226 .Select(v => dataset.GetReadOnlyDoubleValues(v)) 231 227 .ToArray(); 232 doubleVariableNames.Add("#NOTHING#", values.Count() - 1); 233 foreach (var rowEnum in rows) { 234 int row = rowEnum; 235 foreach (var horizonRow in Enumerable.Range(row, horizon)) { 236 for (int i = 0; i < nComponents; i++) { 237 var componentProg = function[i](horizonRow, values); 228 var cachedValues = (from var in doubleVariableNames.Keys 229 select new double[horizon]).ToArray(); 230 foreach (var row in rows) { 231 // init first line of cache 232 int c = 0; 233 foreach (var var in doubleVariableNames.Keys) 234 cachedValues[c++][0] = dataset.GetDoubleValue(var, row); 235 for (int horizonRow = row; horizonRow < row + horizon; horizonRow++) { 236 for (int i = 0; i < function.Length; i++) { 237 var componentProg = function[i](horizonRow, values, cachedValues, row); 238 238 // set cachedValues for prognosis of future values 239 values[doubleVariableNames[targetVariables[i]]][horizonRow] = componentProg; 240 } 241 } 242 243 yield return from component in Enumerable.Range(0, nComponents) 244 select from horizonRow in Enumerable.Range(row, horizon) 245 select values[doubleVariableNames[targetVariables[component]]][horizonRow]; 246 // reset start value 247 foreach (var v in targetVariables) { 248 if (v != "#NOTHING#") 249 values[doubleVariableNames[v]][row] = dataset.GetDoubleValue(v, row); 239 if (horizon > 1) 240 cachedValues[doubleVariableNames[targetVariables[i]]][horizonRow - row] = componentProg; 241 yield return componentProg; 242 } 250 243 } 251 244 } … … 547 540 case OpCodes.Variable: { 548 541 VariableTreeNode varNode = (VariableTreeNode)currentInstr.dynamicNode; 549 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array550 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0);551 // load correct column of the current variable552 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);553 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex554 542 if (!state.InLaggedContext) { 543 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array 544 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); 545 // load correct column of the current variable 546 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); 547 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex 555 548 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 556 549 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight … … 559 552 var nanResult = il.DefineLabel(); 560 553 var normalResult = il.DefineLabel(); 554 var cachedValue = il.DefineLabel(); 555 var multiplyValue = il.DefineLabel(); 556 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex 561 557 il.Emit(System.Reflection.Emit.OpCodes.Dup); 562 558 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); … … 565 561 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, ds.Rows); 566 562 il.Emit(System.Reflection.Emit.OpCodes.Bge, nanResult); 563 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3); 564 il.Emit(System.Reflection.Emit.OpCodes.Bge, cachedValue); 565 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array 566 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); 567 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); 568 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex 567 569 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 570 il.Emit(System.Reflection.Emit.OpCodes.Br, multiplyValue); 571 il.MarkLabel(cachedValue); 572 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_2); // load cached values array 573 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); 574 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); 575 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex 576 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3); // startRow 577 il.Emit(System.Reflection.Emit.OpCodes.Sub); // startRow 578 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 579 il.MarkLabel(multiplyValue); 568 580 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight 569 581 il.Emit(System.Reflection.Emit.OpCodes.Mul); … … 571 583 il.MarkLabel(nanResult); 572 584 il.Emit(System.Reflection.Emit.OpCodes.Pop); // rowIndex 573 il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference574 585 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN); 575 586 il.MarkLabel(normalResult); … … 580 591 var nanResult = il.DefineLabel(); 581 592 var normalResult = il.DefineLabel(); 593 var cachedValue = il.DefineLabel(); 594 var multiplyValue = il.DefineLabel(); 582 595 LaggedVariableTreeNode varNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; 583 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array584 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); // load correct column of the current variable585 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref);586 596 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, varNode.Lag); // lag 587 597 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex … … 593 603 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, ds.Rows); 594 604 il.Emit(System.Reflection.Emit.OpCodes.Bge, nanResult); 605 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3); // startindex 606 il.Emit(System.Reflection.Emit.OpCodes.Bge, cachedValue); 607 // normal value 608 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); // load columns array 609 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); // load correct column of the current variable 610 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); 611 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, varNode.Lag); // lag 612 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex 613 il.Emit(System.Reflection.Emit.OpCodes.Add); // actualRowIndex = rowIndex + sampleOffset 595 614 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 615 il.Emit(System.Reflection.Emit.OpCodes.Br, multiplyValue); 616 il.MarkLabel(cachedValue); 617 // cached value 618 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_2); // load cached values 619 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, (int)currentInstr.iArg0); // load correct column of the current variable 620 il.Emit(System.Reflection.Emit.OpCodes.Ldelem_Ref); 621 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, varNode.Lag); // lag 622 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); // rowIndex 623 il.Emit(System.Reflection.Emit.OpCodes.Add); // actualRowIndex = rowIndex + sampleOffset 624 il.Emit(System.Reflection.Emit.OpCodes.Ldarg_3); // startRow 625 il.Emit(System.Reflection.Emit.OpCodes.Sub); // startRow 626 il.Emit(System.Reflection.Emit.OpCodes.Call, listGetValue); 627 628 il.MarkLabel(multiplyValue); 596 629 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.Weight); // load weight 597 630 il.Emit(System.Reflection.Emit.OpCodes.Mul); 598 631 il.Emit(System.Reflection.Emit.OpCodes.Br, normalResult); 599 632 il.MarkLabel(nanResult); 600 il.Emit(System.Reflection.Emit.OpCodes.Pop); // sample index 601 il.Emit(System.Reflection.Emit.OpCodes.Pop); // column reference 633 il.Emit(System.Reflection.Emit.OpCodes.Pop); // pop the row index 602 634 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, double.NaN); 603 635 il.MarkLabel(normalResult); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r7120 r7154 201 201 202 202 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) { 203 return from prog in GetSymbolicExpressionTreeValues(tree, dataset, new string[] { "#NOTHING#" }, rows, 1) 204 select prog.First().First(); 205 } 206 207 // for each row for each target variable one prognosis (=enumerable of future values) 208 public IEnumerable<IEnumerable<IEnumerable<double>>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) { 203 return GetSymbolicExpressionTreeValues(tree, dataset, new string[] { "#NOTHING#" }, rows); 204 } 205 206 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows) { 207 return GetSymbolicExpressionTreeValues(tree, dataset, targetVariables, rows, 1); 208 } 209 210 211 // for each row for each horizon for each target variable one value 212 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) { 209 213 if (CheckExpressionsWithIntervalArithmetic.Value) 210 214 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); … … 238 242 foreach (var rowEnum in rows) { 239 243 int row = rowEnum; 240 List<double[]> vProgs = new List<double[]>();241 244 foreach (var horizonRow in Enumerable.Range(row, horizon)) { 242 245 int localRow = horizonRow; // create a local variable for the ref parameter 243 var vPrognosis = from i in Enumerable.Range(0, nComponents) 244 select Evaluate(dataset, ref localRow, row - 1, state, cachedPrognosedValues); 245 246 var vPrognosisArr = vPrognosis.ToArray(); 247 vProgs.Add(vPrognosisArr); 248 // set cachedValues for prognosis of future values 249 for (int i = 0; i < vPrognosisArr.Length; i++) 250 cachedPrognosedValues[targetVariables[i]][horizonRow - row] = vPrognosisArr[i]; 246 for (int c = 0; c < nComponents; c++) { 247 var prog = Evaluate(dataset, ref localRow, row - 1, state, cachedPrognosedValues); 248 yield return prog; 249 cachedPrognosedValues[targetVariables[c]][horizonRow - row] = prog; 250 } 251 251 252 252 state.Reset(); 253 253 } 254 255 yield return from component in Enumerable.Range(0, nComponents)256 select from prognosisStep in Enumerable.Range(0, vProgs.Count)257 select vProgs[prognosisStep][component];258 254 } 259 255 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionLineChartView.cs
r7129 r7154 91 91 this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Points 92 92 .DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), 93 Content.PrognosedTrainingValues. ElementAt(varIndex).ToArray());93 Content.PrognosedTrainingValues.SelectMany(x => x).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray()); 94 94 } else { 95 95 this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Points 96 96 .DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), 97 Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes, 1).Select (v => v.ElementAt(varIndex).First()).ToArray());97 Content.GetPrognosedValues(Content.ProblemData.TrainingIndizes, 1).SelectMany(x => x.Single()).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray()); 98 98 } 99 99 this.chart.Series[PROGNOSEDVALUES_TRAINING_SERIES_NAME].Tag = Content; … … 109 109 this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points 110 110 .DataBindXY(Content.ProblemData.TestIndizes.ToArray(), 111 Content.PrognosedTestValues. ElementAt(varIndex).ToArray());111 Content.PrognosedTestValues.SelectMany(x => x).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray()); 112 112 } else { 113 113 this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Points 114 114 .DataBindXY(Content.ProblemData.TestIndizes.ToArray(), 115 Content.GetPrognosedValues(Content.ProblemData.TestIndizes, 1).Select( 116 v => v.ElementAt(varIndex).First()).ToArray()); 115 Content.GetPrognosedValues(Content.ProblemData.TestIndizes, 1).SelectMany(x => x.Single()).Skip(varIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()).ToArray()); 117 116 } 118 117 this.chart.Series[PROGNOSEDVALUES_TEST_SERIES_NAME].Tag = Content; … … 242 241 case PROGNOSEDVALUES_TRAINING_SERIES_NAME: 243 242 indizes = Content.ProblemData.TrainingIndizes.ToArray(); 244 predictedValues = Content.PrognosedTrainingValues.ElementAt(varIndex).ToArray(); 243 predictedValues = 244 Content.PrognosedTrainingValues.SelectMany(x => x).Skip(varIndex).TakeEvery( 245 Content.ProblemData.TargetVariables.Count()).ToArray(); 245 246 break; 246 247 case PROGNOSEDVALUES_TEST_SERIES_NAME: 247 248 indizes = Content.ProblemData.TestIndizes.ToArray(); 248 predictedValues = Content.PrognosedTestValues.ElementAt(varIndex).ToArray(); 249 Content.PrognosedTestValues.SelectMany(x => x).Skip(varIndex).TakeEvery( 250 Content.ProblemData.TargetVariables.Count()).ToArray(); 249 251 break; 250 252 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionPrognosedValuesView.cs
r7100 r7154 93 93 values[row, 0] = row.ToString(); 94 94 95 var prognosedTraining = Content.PrognosedTrainingValues.ToArray();96 var prognosedTest = Content.PrognosedTestValues.ToArray();95 var allPrognosedTraining = Content.PrognosedTrainingValues.SelectMany(x=>x).ToArray(); 96 var allPrognosedTest = Content.PrognosedTestValues.SelectMany(x => x).ToArray(); 97 97 98 98 int i = 0; 99 99 int targetVariableIndex = 0; 100 100 foreach (var targetVariable in Content.ProblemData.TargetVariables) { 101 var prognosedTraining = 102 allPrognosedTraining.Skip(targetVariableIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()); 103 var prognosedTest = 104 allPrognosedTest.Skip(targetVariableIndex).TakeEvery(Content.ProblemData.TargetVariables.Count()); 105 101 106 double[] target = Content.ProblemData.Dataset.GetDoubleValues(targetVariable).ToArray(); 102 107 103 var prognosedTrainingEnumerator = prognosedTraining [targetVariableIndex].GetEnumerator();108 var prognosedTrainingEnumerator = prognosedTraining.GetEnumerator(); 104 109 foreach (var row in Content.ProblemData.TrainingIndizes) { 105 110 prognosedTrainingEnumerator.MoveNext(); … … 107 112 } 108 113 109 var prognosedTestEnumerator = prognosedTest [targetVariableIndex].GetEnumerator();114 var prognosedTestEnumerator = prognosedTest.GetEnumerator(); 110 115 foreach (var row in Content.ProblemData.TestIndizes) { 111 116 prognosedTestEnumerator.MoveNext(); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r7099 r7154 108 108 </ItemGroup> 109 109 <ItemGroup> 110 <Compile Include="DatasetExtensions.cs" /> 110 111 <Compile Include="DoubleLimit.cs" /> 111 112 <Compile Include="Implementation\Classification\ClassificationEnsembleModel.cs"> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
r7100 r7154 161 161 protected void CalculateResults() { 162 162 OnlineCalculatorError errorState; 163 string[] targetVariables = ProblemData.TargetVariables.ToArray(); 163 164 /* 164 165 double[] estimatedTrainingValues = PrognosedTrainingValues.ToArray(); // cache values … … 193 194 */ 194 195 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++; 196 //double[] trainingDs = new double[targetVariables.Length]; 197 //double[] testDs = new double[targetVariables.Length]; 198 199 //double[] trainingWds = new double[targetVariables.Length]; 200 //double[] testWds = new double[targetVariables.Length]; 201 202 //double[] trainingTheilsU = new double[targetVariables.Length]; 203 //double[] testTheilsU = new double[targetVariables.Length]; 204 205 var trainingDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length]; 206 var testDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length]; 207 var trainingWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator[targetVariables.Length]; 208 var testWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator[targetVariables.Length]; 209 var trainingTheilsUCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length]; 210 var testTheilsUCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length]; 211 for (int i = 0; i < targetVariables.Length; i++) { 212 trainingDsCalculators[i] = new OnlineDirectionalSymmetryCalculator(); 213 testDsCalculators[i] = new OnlineDirectionalSymmetryCalculator(); 214 trainingWdsCalculators[i] = new OnlineWeightedDirectionalSymmetryCalculator(); 215 testWdsCalculators[i] = new OnlineWeightedDirectionalSymmetryCalculator(); 216 trainingTheilsUCalculators[i] = new OnlineTheilsUStatisticCalculator(); 217 testTheilsUCalculators[i] = new OnlineTheilsUStatisticCalculator(); 250 218 } 251 219 252 TrainingDirectionalSymmetry = trainingDs; 253 TestDirectionalSymmetry = testDs; 254 TrainingWeightedDirectionalSymmetry = trainingWds; 255 TestWeightedDirectionalSymmetry = testWds; 256 TrainingTheilsUStatistic = trainingTheilsU; 257 TestTheilsUStatistic = testTheilsU; 220 var allPrognosedTrainingValues = PrognosedTrainingValues.SelectMany(x => x).ToArray(); 221 var allPrognosedTestValues = PrognosedTestValues.SelectMany(x => x).ToArray(); 222 for (int t = 0; t < targetVariables.Length; t++) { 223 var actualTrainingValues = ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TrainingIndizes); 224 double startTrainingValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], ProblemData.TrainingIndizes.First() - 1); 225 var prognosedTrainingValues = allPrognosedTrainingValues.Skip(t).TakeEvery(targetVariables.Length); 226 trainingDsCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues); 227 trainingWdsCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues); 228 trainingTheilsUCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues); 229 230 var actualTestValues = ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TestIndizes); 231 double startTestValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], ProblemData.TestIndizes.First() - 1); 232 var prognosedTestValues = allPrognosedTestValues.Skip(t).TakeEvery(targetVariables.Length); 233 testDsCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues); 234 testWdsCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues); 235 testTheilsUCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues); 236 } 237 238 TrainingDirectionalSymmetry = trainingDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0) 239 .ToArray(); 240 TestDirectionalSymmetry = testDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0) 241 .ToArray(); 242 TrainingWeightedDirectionalSymmetry = trainingWdsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity) 243 .ToArray(); 244 TestWeightedDirectionalSymmetry = testWdsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity) 245 .ToArray(); 246 TrainingTheilsUStatistic = trainingDsCalculators 247 .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity) 248 .ToArray(); 249 TestTheilsUStatistic = testTheilsUCalculators 250 .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity) 251 .ToArray(); 258 252 } 259 253 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Tests/HeuristicLab-3.3/SamplesTest.cs
r7082 r7154 44 44 using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification; 45 45 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 46 using HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis; 46 47 using HeuristicLab.Problems.Knapsack; 47 48 using HeuristicLab.Problems.TestFunctions; … … 434 435 } 435 436 #endregion 437 #region Symbolic Time-Series Prognosis 438 [TestMethod] 439 public void CreateGpSymbolicTimeSeriesPrognosisSampleTest() { 440 var ga = CreateGpSymbolicTimeSeriesPrognosisSample(); 441 XmlGenerator.Serialize(ga, "../../SGP_SymbTimeSeries.hl"); 442 } 443 444 [TestMethod] 445 public void RunGpSymbolicTimeSeriesPrognosisSample() { 446 var ga = CreateGpSymbolicTimeSeriesPrognosisSample(); 447 ga.SetSeedRandomly.Value = false; 448 RunAlgorithm(ga); 449 Assert.Inconclusive("Asserts not implemented!"); 450 } 451 452 private GeneticAlgorithm CreateGpSymbolicTimeSeriesPrognosisSample() { 453 GeneticAlgorithm ga = new GeneticAlgorithm(); 454 #region Problem Configuration 455 SymbolicTimeSeriesPrognosisSingleObjectiveProblem symbTimeProblem = new SymbolicTimeSeriesPrognosisSingleObjectiveProblem(); 456 symbTimeProblem.ProblemData.TrainingPartition.Start = 20; 457 458 459 // configure remaining problem parameters 460 symbTimeProblem.RelativeNumberOfEvaluatedSamples.Value = 1; 461 symbTimeProblem.MaximumSymbolicExpressionTreeLength.Value = 100; 462 symbTimeProblem.MaximumSymbolicExpressionTreeDepth.Value = 10; 463 symbTimeProblem.MaximumFunctionDefinitions.Value = 0; 464 symbTimeProblem.MaximumFunctionArguments.Value = 0; 465 symbTimeProblem.SymbolicExpressionTreeInterpreter = new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(); 466 467 #endregion 468 #region Algorithm Configuration 469 ga.Problem = symbTimeProblem; 470 ga.Name = "Genetic Programming - Symbolic Time-Series Prognosis"; 471 ga.Description = "A standard genetic programming algorithm to solve a time-series prognosis problem (Mackey-Glass 17)"; 472 ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>( 473 ga, 1000, 1, 100, 0.15, 5 474 ); 475 476 var mutator = (MultiSymbolicExpressionTreeManipulator)ga.Mutator; 477 mutator.Operators.OfType<FullTreeShaker>().Single().ShakingFactor = 0.1; 478 mutator.Operators.OfType<OnePointShaker>().Single().ShakingFactor = 1.0; 479 480 ga.Analyzer.Operators.SetItemCheckedState( 481 ga.Analyzer.Operators 482 .OfType<SymbolicDataAnalysisAlleleFrequencyAnalyzer>() 483 .First(), false); 484 #endregion 485 return ga; 486 } 487 #endregion 436 488 #endregion 437 489 -
branches/HeuristicLab.TimeSeries/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r7129 r7154 315 315 Evaluate(interpreter, ds, "(lagVariable 1.0 a -1) ", 2, ds.GetDoubleValue("A", 1)); 316 316 Evaluate(interpreter, ds, "(lagVariable 1.0 a 0) ", 2, ds.GetDoubleValue("A", 2)); 317 Evaluate(interpreter, ds, "(lagVariable 1.0 a 1) ", 0, ds.GetDoubleValue("A", 1));317 //Evaluate(interpreter, ds, "(lagVariable 1.0 a 1) ", 0, ds.GetDoubleValue("A", 1)); 318 318 319 319 // integral 320 320 Evaluate(interpreter, ds, "(integral -1.0 (variable 1.0 a)) ", 1, ds.GetDoubleValue("A", 0) + ds.GetDoubleValue("A", 1)); 321 Evaluate(interpreter, ds, "(integral -1.0 (lagVariable 1.0 a 1)) ", 1, ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2));321 Evaluate(interpreter, ds, "(integral -1.0 (lagVariable 1.0 a -1)) ", 3, ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2)); 322 322 Evaluate(interpreter, ds, "(integral -2.0 (variable 1.0 a)) ", 2, ds.GetDoubleValue("A", 0) + ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2)); 323 323 Evaluate(interpreter, ds, "(integral -1.0 (* (variable 1.0 a) (variable 1.0 b)))", 1, ds.GetDoubleValue("A", 0) * ds.GetDoubleValue("B", 0) + ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 1)); … … 336 336 337 337 // timelag 338 Evaluate(interpreter, ds, "(lag -1.0 (lagVariable 1.0 a 2)) ", 1, ds.GetDoubleValue("A", 2));339 Evaluate(interpreter, ds, "(lag -2.0 (lagVariable 1.0 a 2)) ", 2, ds.GetDoubleValue("A", 2));340 Evaluate(interpreter, ds, "(lag -1.0 (* (lagVariable 1.0 a 1) (lagVariable 1.0 b 2)))", 1, ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 2));338 Evaluate(interpreter, ds, "(lag -1.0 (lagVariable 1.0 a -2)) ", 5, ds.GetDoubleValue("A", 2)); 339 Evaluate(interpreter, ds, "(lag -2.0 (lagVariable 1.0 a -2)) ", 5, ds.GetDoubleValue("A", 1)); 340 Evaluate(interpreter, ds, "(lag -1.0 (* (lagVariable 1.0 a -1) (lagVariable 1.0 b -2)))", 3, ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 0)); 341 341 Evaluate(interpreter, ds, "(lag -2.0 3.0)", 1, 3.0); 342 342 … … 349 349 Evaluate(interpreter, ds, @"(PROG 350 350 (MAIN (lagVariable 1.0 a -1) (lagVariable 1.0 b -1)))", new string[] { "A", "B" }, Enumerable.Range(1, 2), 3, 351 new[] { new[] { 1.0, 1.0, 1.0 }, new[] { 1.0, 1.0, 1.0 } }, 352 new[] { new[] { 2.0, 2.0, 2.0 }, new[] { 2.0, 2.0, 2.0 } } 351 new[] { new[] { 1.0, 1.0}, 352 new[] { 1.0, 1.0}, 353 new[] { 1.0, 1.0}}, 354 new[] { new[] { 2.0, 2.0}, 355 new[] { 2.0, 2.0}, 356 new[] { 2.0, 2.0} } 353 357 ); 354 358 … … 364 368 Evaluate(interpreter, ds, @"(PROG 365 369 (MAIN (lagVariable 2.0 a -2) (lagVariable 1.0 a -1)))", new string[] { "A", "B" }, Enumerable.Range(2, 3), 4, 366 new[] { new[] { 2.0, 4.0, 4.0, 8.0 }, new[] { 2.0, 2.0, 4.0, 4.0 } }, 367 new[] { new[] { 4.0, 2.0, 8.0, 4.0 }, new[] { 1.0, 4.0, 2.0, 8.0 } }, 368 new[] { new[] { 2.0, 2.0, 4.0, 4.0 }, new[] { 1.0, 2.0, 2.0, 4.0 } } 370 new[] { new[] { 2.0, 2.0}, 371 new[] { 4.0, 2.0}, 372 new[] { 4.0, 4.0}, 373 new[] { 8.0, 4.0}}, 374 new[] { new[] { 4.0, 1.0}, 375 new[] { 2.0, 4.0}, 376 new[] { 8.0, 2.0}, 377 new[] { 4.0, 8.0}}, 378 new[] { new[] { 2.0, 1.0}, 379 new[] { 2.0, 2.0}, 380 new[] { 4.0, 2.0}, 381 new[] { 4.0, 4.0}} 369 382 ); 370 383 } … … 384 397 ISymbolicExpressionTree tree = importer.Import(expr); 385 398 386 var allPrognosis = interpreter.GetSymbolicExpressionTreeValues(tree, ds, targetVariables, rows, horizon) ;399 var allPrognosis = interpreter.GetSymbolicExpressionTreeValues(tree, ds, targetVariables, rows, horizon).GetEnumerator(); 387 400 int i = 0; 388 foreach (var actual in allPrognosis) { 389 var actualEnumerator = actual.GetEnumerator(); 390 var expectedEnumerator = expected[i].GetEnumerator(); 391 while (actualEnumerator.MoveNext() & expectedEnumerator.MoveNext()) { 392 var aEnumerator = actualEnumerator.Current.GetEnumerator(); 401 var expectedEnumerator = expected[i].GetEnumerator(); 402 while (allPrognosis.MoveNext()) { 403 while (expectedEnumerator.MoveNext()) { 393 404 var eEnumerator = expectedEnumerator.Current.GetEnumerator(); 394 while (aEnumerator.MoveNext() & eEnumerator.MoveNext()) { 395 Assert.IsFalse(double.IsNaN(aEnumerator.Current) && !double.IsNaN(eEnumerator.Current)); 396 Assert.IsFalse(!double.IsNaN(aEnumerator.Current) && double.IsNaN(eEnumerator.Current)); 397 Assert.AreEqual(eEnumerator.Current, aEnumerator.Current, 1.0E-12, expr); 405 while (eEnumerator.MoveNext()) { 406 Assert.IsFalse(double.IsNaN(allPrognosis.Current) && !double.IsNaN(eEnumerator.Current)); 407 Assert.IsFalse(!double.IsNaN(allPrognosis.Current) && double.IsNaN(eEnumerator.Current)); 408 Assert.AreEqual(eEnumerator.Current, allPrognosis.Current, 1.0E-12, expr); 409 allPrognosis.MoveNext(); 398 410 } 399 411 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r7097 r7154 830 830 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</Name> 831 831 </ProjectReference> 832 <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj"> 833 <Project>{07486E68-1517-4B9D-A58D-A38E99AE71AB}</Project> 834 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4</Name> 835 </ProjectReference> 832 836 <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis.Symbolic.Views\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj"> 833 837 <Project>{7A2531CE-3F7C-4F13-BCCA-ED6DC27A7086}</Project>
Note: See TracChangeset
for help on using the changeset viewer.