Changeset 16692 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
- Timestamp:
- 03/18/19 17:24:30 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r13268 r16692 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.