Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
- Timestamp:
- 06/28/18 11:13:37 (7 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure ¶
- Property svn:ignore
-
TabularUnified
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic ¶
- Property svn:mergeinfo changed
-
TabularUnified branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/InterpreterState.cs ¶
r12012 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
TabularUnified branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs ¶
r12012 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 83 83 public const byte Erf = 43; 84 84 public const byte Bessel = 44; 85 public const byte FactorVariable = 46; 86 public const byte BinaryFactorVariable = 47; 87 85 88 86 89 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { … … 130 133 { typeof(Norm), OpCodes.Norm}, 131 134 { typeof(Erf), OpCodes.Erf}, 132 { typeof(Bessel), OpCodes.Bessel} 135 { typeof(Bessel), OpCodes.Bessel}, 136 { typeof(FactorVariable), OpCodes.FactorVariable }, 137 { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable } 133 138 }; 134 139 -
TabularUnified branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs ¶
r13313 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 614 614 case OpCodes.VariableCondition: { 615 615 var variableConditionTreeNode = (VariableConditionTreeNode)node; 616 if (variableConditionTreeNode.Symbol.IgnoreSlope) throw new NotSupportedException("Strict variable conditionals are not supported"); 616 617 var variableName = variableConditionTreeNode.VariableName; 617 618 var indexExpr = Expression.Constant(variableIndices[variableName]); -
TabularUnified branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs ¶
r13251 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 66 66 private static MethodInfo erf = thisType.GetMethod("Erf", new Type[] { typeof(double) }); 67 67 private static MethodInfo bessel = thisType.GetMethod("Bessel", new Type[] { typeof(double) }); 68 private static MethodInfo string_eq = typeof(string).GetMethod("Equals", new Type[] { typeof(string) }); 68 69 #endregion 69 70 … … 259 260 il.Emit(System.Reflection.Emit.OpCodes.Add); 260 261 } 261 il.Emit(System.Reflection.Emit.OpCodes.Ldc_ I4,nArgs);262 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, (double)nArgs); 262 263 il.Emit(System.Reflection.Emit.OpCodes.Div); 263 264 return; … … 457 458 il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0 458 459 il.Emit(System.Reflection.Emit.OpCodes.Cgt); 460 il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64 459 461 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2 460 462 il.Emit(System.Reflection.Emit.OpCodes.Mul); … … 475 477 il.Emit(System.Reflection.Emit.OpCodes.Xor); 476 478 } 479 il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64 480 477 481 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2 478 482 il.Emit(System.Reflection.Emit.OpCodes.Mul); … … 486 490 487 491 il.Emit(System.Reflection.Emit.OpCodes.Cgt); // 1 (>) / 0 (otherwise) 492 il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64 488 493 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2 489 494 il.Emit(System.Reflection.Emit.OpCodes.Mul); … … 496 501 CompileInstructions(il, state, ds); 497 502 il.Emit(System.Reflection.Emit.OpCodes.Clt); 503 il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64 498 504 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2 499 505 il.Emit(System.Reflection.Emit.OpCodes.Mul); -
TabularUnified branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs ¶
r13251 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 143 144 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 144 145 instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName); 146 } else if (instr.opCode == OpCodes.FactorVariable) { 147 var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode; 148 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 149 } else if (instr.opCode == OpCodes.BinaryFactorVariable) { 150 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 151 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 145 152 } else if (instr.opCode == OpCodes.LagVariable) { 146 153 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; … … 455 462 return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight; 456 463 } 464 case OpCodes.BinaryFactorVariable: { 465 if (row < 0 || row >= dataset.Rows) return double.NaN; 466 var factorVarTreeNode = currentInstr.dynamicNode as BinaryFactorVariableTreeNode; 467 return ((IList<string>)currentInstr.data)[row] == factorVarTreeNode.VariableValue ? factorVarTreeNode.Weight : 0; 468 } 469 case OpCodes.FactorVariable: { 470 if (row < 0 || row >= dataset.Rows) return double.NaN; 471 var factorVarTreeNode = currentInstr.dynamicNode as FactorVariableTreeNode; 472 return factorVarTreeNode.GetValue(((IList<string>)currentInstr.data)[row]); 473 } 457 474 case OpCodes.LagVariable: { 458 475 var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; … … 471 488 if (row < 0 || row >= dataset.Rows) return double.NaN; 472 489 var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode; 473 double variableValue = ((IList<double>)currentInstr.data)[row]; 474 double x = variableValue - variableConditionTreeNode.Threshold; 475 double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x)); 476 477 double trueBranch = Evaluate(dataset, ref row, state); 478 double falseBranch = Evaluate(dataset, ref row, state); 479 480 return trueBranch * p + falseBranch * (1 - p); 490 if (!variableConditionTreeNode.Symbol.IgnoreSlope) { 491 double variableValue = ((IList<double>)currentInstr.data)[row]; 492 double x = variableValue - variableConditionTreeNode.Threshold; 493 double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x)); 494 495 double trueBranch = Evaluate(dataset, ref row, state); 496 double falseBranch = Evaluate(dataset, ref row, state); 497 498 return trueBranch * p + falseBranch * (1 - p); 499 } else { 500 // strict threshold 501 double variableValue = ((IList<double>)currentInstr.data)[row]; 502 if (variableValue <= variableConditionTreeNode.Threshold) { 503 var left = Evaluate(dataset, ref row, state); 504 state.SkipInstructions(); 505 return left; 506 } else { 507 state.SkipInstructions(); 508 return Evaluate(dataset, ref row, state); 509 } 510 } 481 511 } 482 512 default: -
TabularUnified branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs ¶
r13268 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 38 38 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 39 39 40 private SymbolicDataAnalysisExpressionTreeInterpreter interpreter;40 private readonly SymbolicDataAnalysisExpressionTreeInterpreter interpreter; 41 41 42 42 public override bool CanChangeName { … … 72 72 private SymbolicDataAnalysisExpressionTreeLinearInterpreter(bool deserializing) 73 73 : base(deserializing) { 74 interpreter = new SymbolicDataAnalysisExpressionTreeInterpreter(); 74 75 } 75 76 … … 125 126 private readonly object syncRoot = new object(); 126 127 public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) { 128 if (!rows.Any()) return Enumerable.Empty<double>(); 127 129 if (CheckExpressionsWithIntervalArithmetic) 128 130 throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter."); … … 147 149 var variableTreeNode = (VariableTreeNode)instr.dynamicNode; 148 150 instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight; 151 } 152 } else if (instr.opCode == OpCodes.BinaryFactorVariable) { 153 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 154 else { 155 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 156 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? factorTreeNode.Weight : 0; 157 } 158 } else if (instr.opCode == OpCodes.FactorVariable) { 159 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 160 else { 161 var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode; 162 instr.value = factorTreeNode.GetValue(((IList<string>)instr.data)[row]); 149 163 } 150 164 } else if (instr.opCode == OpCodes.LagVariable) { … … 158 172 if (row < 0 || row >= dataset.Rows) instr.value = double.NaN; 159 173 var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode; 160 double variableValue = ((IList<double>)instr.data)[row]; 161 double x = variableValue - variableConditionTreeNode.Threshold; 162 double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x)); 163 164 double trueBranch = code[instr.childIndex].value; 165 double falseBranch = code[instr.childIndex + 1].value; 166 167 instr.value = trueBranch * p + falseBranch * (1 - p); 174 if (!variableConditionTreeNode.Symbol.IgnoreSlope) { 175 double variableValue = ((IList<double>)instr.data)[row]; 176 double x = variableValue - variableConditionTreeNode.Threshold; 177 double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x)); 178 179 double trueBranch = code[instr.childIndex].value; 180 double falseBranch = code[instr.childIndex + 1].value; 181 182 instr.value = trueBranch * p + falseBranch * (1 - p); 183 } else { 184 double variableValue = ((IList<double>)instr.data)[row]; 185 if (variableValue <= variableConditionTreeNode.Threshold) { 186 instr.value = code[instr.childIndex].value; 187 } else { 188 instr.value = code[instr.childIndex + 1].value; 189 } 190 } 168 191 } else if (instr.opCode == OpCodes.Add) { 169 192 double s = code[instr.childIndex].value; … … 392 415 } 393 416 break; 417 case OpCodes.BinaryFactorVariable: { 418 var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 419 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 420 } 421 break; 422 case OpCodes.FactorVariable: { 423 var factorVariableTreeNode = instr.dynamicNode as FactorVariableTreeNode; 424 instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName); 425 } 426 break; 394 427 case OpCodes.LagVariable: { 395 428 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; … … 410 443 for (int j = 1; j != seq.Length; ++j) 411 444 seq[j].skip = true; 412 }413 break;445 break; 446 } 414 447 } 415 448 #endregion
Note: See TracChangeset
for help on using the changeset viewer.