Changeset 9776
- Timestamp:
- 07/26/13 13:15:05 (11 years ago)
- Location:
- branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/LinearInstruction.cs
r9758 r9776 26 26 public double value; 27 27 public byte childIndex; 28 public bool skip; 28 29 } 29 30 } -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r9732 r9776 132 132 133 133 134 p rotectedvirtual double Evaluate(Dataset dataset, ref int row, InterpreterState state) {134 public virtual double Evaluate(Dataset dataset, ref int row, InterpreterState state) { 135 135 Instruction currentInstr = state.NextInstruction(); 136 136 switch (currentInstr.opCode) { -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r9758 r9776 37 37 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 38 38 39 private SymbolicDataAnalysisExpressionTreeInterpreter interpreter; 40 39 41 public override bool CanChangeName { 40 42 get { return false; } … … 74 76 SymbolicDataAnalysisExpressionTreeLinearInterpreter original, Cloner cloner) 75 77 : base(original, cloner) { 78 interpreter = original.interpreter; 76 79 } 77 80 … … 84 87 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 85 88 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 89 interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 86 90 } 87 91 … … 90 94 Parameters.Add(new ValueParameter<BoolValue>(CheckExpressionsWithIntervalArithmeticParameterName, "Switch that determines if the interpreter checks the validity of expressions with interval arithmetic before evaluating the expression.", new BoolValue(false))); 91 95 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 96 interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 92 97 } 93 98 … … 96 101 if (!Parameters.ContainsKey(EvaluatedSolutionsParameterName)) 97 102 Parameters.Add(new ValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 103 if (interpreter == null) interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 98 104 } 99 105 … … 122 128 } 123 129 130 private static LinearInstruction[] GetPrefixSequence(LinearInstruction[] code, int startIndex) { 131 var instr = code[startIndex]; 132 var list = new List<LinearInstruction> { instr }; 133 for (int i = 0; i != instr.nArguments; ++i) { 134 list.AddRange(GetPrefixSequence(code, instr.childIndex + i)); 135 } 136 return list.ToArray(); 137 } 138 124 139 private static void PrepareInstructions(LinearInstruction[] code, Dataset dataset) { 125 for (int i = code.Length - 1; i >= 0; --i) { 140 Action<LinearInstruction> setSkip = null; 141 setSkip = instruction => { 142 instruction.skip = true; 143 for (int j = 0; j != instruction.nArguments; ++j) { 144 setSkip(code[instruction.childIndex + j]); 145 } 146 }; 147 148 for (int i = 0; i != code.Length; ++i) { 126 149 var instr = code[i]; 127 150 #region opcode switch … … 130 153 var constTreeNode = (ConstantTreeNode)instr.dynamicNode; 131 154 instr.value = constTreeNode.Value; 155 instr.skip = true; // the value is already set so this instruction should be skipped in the evaluation phase 132 156 } 133 157 break; … … 147 171 } 148 172 break; 173 case OpCodes.TimeLag: 174 case OpCodes.Integral: 175 case OpCodes.Derivative: { 176 for (int j = 0; j != instr.nArguments; ++j) { 177 setSkip(code[instr.childIndex + j]); 178 } 179 } 180 break; 149 181 } 150 182 #endregion … … 152 184 } 153 185 154 private staticdouble Evaluate(Dataset dataset, ref int row, LinearInstruction[] code) {186 private double Evaluate(Dataset dataset, ref int row, LinearInstruction[] code) { 155 187 for (int i = code.Length - 1; i >= 0; --i) { 156 if (code[i]. opCode == OpCodes.Constant) continue;188 if (code[i].skip) continue; 157 189 #region opcode switch 158 190 var instr = code[i]; … … 304 336 else { 305 337 alglib.sinecosineintegrals(x, out si, out ci); 306 instr.value = si;338 instr.value = ci; 307 339 } 308 340 } … … 431 463 } 432 464 break; 465 case OpCodes.TimeLag: 466 case OpCodes.Integral: 467 case OpCodes.Derivative: { 468 if (instr.iArg0 == null) { 469 instr.iArg0 = GetPrefixSequence(code, i); ; 470 } 471 var interpreterState = new InterpreterState((LinearInstruction[])instr.iArg0, 0); 472 instr.value = interpreter.Evaluate(dataset, ref row, interpreterState); 473 } 474 break; 433 475 default: 434 476 var errorText = string.Format("The {0} symbol is not supported by the linear interpreter. To support this symbol, please use another interpreter.", instr.dynamicNode.Symbol.Name); -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r9758 r9776 173 173 [TestMethod] 174 174 public void SymbolicDataAnalysisExpressionTreeLinearInterpreterEvaluateTest() { 175 var interpreter = new SymbolicDataAnalysisExpressionTree Interpreter();175 var interpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); 176 176 Dataset ds = new Dataset(new string[] { "Y", "A", "B" }, new double[,] { 177 177 { 1.0, 1.0, 1.0 }, … … 191 191 EvaluateTerminals(interpreter, ds); 192 192 EvaluateOperations(interpreter, ds); 193 EvaluateTimeSymbols(interpreter, ds); 193 194 } 194 195 -
branches/HeuristicLab.DataAnalysis.Symbolic.LinearInterpreter/LinearInterpreter.sln
r9738 r9776 58 58 HideSolutionNode = FALSE 59 59 EndGlobalSection 60 GlobalSection(Performance) = preSolution61 HasPerformanceSessions = true62 EndGlobalSection63 60 EndGlobal
Note: See TracChangeset
for help on using the changeset viewer.