Changeset 6860
- Timestamp:
- 10/03/11 17:28:53 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r6849 r6860 132 132 133 133 public const byte VariableCondition = 27; 134 135 public const byte UncheckedVariable = 28;136 public const byte UncheckedVariableCondition = 29;137 134 } 138 135 #endregion 139 136 140 private Dictionary<Type, byte> symbolToUncheckedOpcode = new Dictionary<Type, byte>() {141 { typeof(HeuristicLab.Problems.DataAnalysis.Symbolic.Variable), OpCodes.UncheckedVariable },142 { typeof(VariableCondition),OpCodes.UncheckedVariableCondition}143 };144 137 private Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { 145 138 { typeof(Addition), OpCodes.Add }, … … 213 206 for (int i = 0; i < code.Length; i++) { 214 207 Instruction instr = code[i]; 215 if (instr.opCode == OpCodes.Variable || instr.opCode == OpCodes.UncheckedVariable) {208 if (instr.opCode == OpCodes.Variable) { 216 209 var variableTreeNode = instr.dynamicNode as VariableTreeNode; 217 210 instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName); … … 221 214 instr.iArg0 = dataset.GetReadOnlyDoubleValues(laggedVariableTreeNode.VariableName); 222 215 code[i] = instr; 223 } else if (instr.opCode == OpCodes.VariableCondition || instr.opCode == OpCodes.UncheckedVariableCondition) {216 } else if (instr.opCode == OpCodes.VariableCondition) { 224 217 var variableConditionTreeNode = instr.dynamicNode as VariableConditionTreeNode; 225 218 instr.iArg0 = dataset.GetReadOnlyDoubleValues(variableConditionTreeNode.VariableName); … … 417 410 return ((IList<double>)currentInstr.iArg0)[row] * variableTreeNode.Weight; 418 411 } 419 case OpCodes.UncheckedVariable: {420 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode;421 return ((IList<double>)currentInstr.iArg0)[row] * variableTreeNode.Weight;422 }423 412 case OpCodes.LagVariable: { 424 413 var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode; … … 448 437 return trueBranch * p + falseBranch * (1 - p); 449 438 } 450 case OpCodes.UncheckedVariableCondition: {451 var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode;452 double variableValue = ((IList<double>)currentInstr.iArg0)[row];453 double x = variableValue - variableConditionTreeNode.Threshold;454 double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));455 456 double trueBranch = Evaluate(dataset, ref row, state);457 double falseBranch = Evaluate(dataset, ref row, state);458 459 return trueBranch * p + falseBranch * (1 - p);460 }461 439 default: throw new NotSupportedException(); 462 440 } … … 464 442 465 443 private byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) { 466 if ((treeNode.Symbol.GetType() == typeof(Variable) || treeNode.Symbol.GetType() == typeof(VariableCondition)) && !InLaggedContext(treeNode)) { 467 return symbolToUncheckedOpcode[treeNode.Symbol.GetType()]; 468 } else { 469 if (symbolToOpcode.ContainsKey(treeNode.Symbol.GetType())) 470 return symbolToOpcode[treeNode.Symbol.GetType()]; 471 else 472 throw new NotSupportedException("Symbol: " + treeNode.Symbol); 473 } 474 } 475 476 private bool InLaggedContext(ISymbolicExpressionTreeNode treeNode) { 477 if (treeNode.Parent == null) return false; 478 if (treeNode.Parent is ILaggedTreeNode) return true; 479 if (treeNode.Parent.Symbol is Derivative) return true; 480 return InLaggedContext(treeNode.Parent); 444 if (symbolToOpcode.ContainsKey(treeNode.Symbol.GetType())) 445 return symbolToOpcode[treeNode.Symbol.GetType()]; 446 else 447 throw new NotSupportedException("Symbol: " + treeNode.Symbol); 481 448 } 482 449
Note: See TracChangeset
for help on using the changeset viewer.