- Timestamp:
- 12/05/11 20:17:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r7120 r7129 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 187 if (CheckExpressionsWithIntervalArithmetic.Value) 182 188 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); … … 186 192 187 193 Dictionary<string, int> doubleVariableNames = dataset.DoubleVariables.Select((x, i) => new { x, i }).ToDictionary(e => e.x, e => e.i); 188 IList<double>[] columns = (from v in doubleVariableNames.Keys189 select dataset.GetReadOnlyDoubleValues(v))190 .ToArray();191 194 192 195 for (int i = 0; i < code.Length; i++) { … … 208 211 } 209 212 var state = new InterpreterState(code); 210 211 213 Type[] methodArgs = { typeof(int), typeof(IList<double>[]) }; 212 DynamicMethod testFun = new DynamicMethod("TestFun", typeof(double), methodArgs, typeof(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter).Module); 213 214 ILGenerator il = testFun.GetILGenerator(); 215 CompileInstructions(il, state, dataset); 216 il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); 217 il.Emit(System.Reflection.Emit.OpCodes.Ret); 218 var function = (CompiledFunction)testFun.CreateDelegate(typeof(CompiledFunction)); 219 220 foreach (var row in rows) { 221 yield return function(row, columns); 222 } 223 } 224 public IEnumerable<IEnumerable<IEnumerable<double>>> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, Dataset dataset, string[] targetVariables, IEnumerable<int> rows, int horizon) { 225 throw new NotImplementedException(); 214 215 CompiledFunction[] function = new CompiledFunction[targetVariables.Length]; 216 for (int i = 0; i < function.Length; i++) { 217 DynamicMethod testFun = new DynamicMethod("TestFun", typeof(double), methodArgs, typeof(SymbolicDataAnalysisExpressionTreeILEmittingInterpreter).Module); 218 ILGenerator il = testFun.GetILGenerator(); 219 CompileInstructions(il, state, dataset); 220 il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); 221 il.Emit(System.Reflection.Emit.OpCodes.Ret); 222 function[i] = (CompiledFunction)testFun.CreateDelegate(typeof(CompiledFunction)); 223 } 224 int nComponents = tree.Root.GetSubtree(0).SubtreeCount; 225 // produce a n-step forecast for each target variable for all rows 226 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 231 .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); 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); 250 } 251 } 226 252 } 227 253
Note: See TracChangeset
for help on using the changeset viewer.