Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/21/16 17:59:36 (8 years ago)
Author:
gkronber
Message:

#2690: implemented methods to generate symbolic expression tree solutions for decision tree models (random forest and gradient boosted) as well as views which make it possible to inspect each of the individual trees in a GBT and RF solution

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs

    r14185 r14345  
    614614        case OpCodes.VariableCondition: {
    615615            var variableConditionTreeNode = (VariableConditionTreeNode)node;
     616            if (variableConditionTreeNode.Symbol.IgnoreSlope) throw new NotSupportedException("Strict variable conditionals are not supported");
    616617            var variableName = variableConditionTreeNode.VariableName;
    617618            var indexExpr = Expression.Constant(variableIndices[variableName]);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r14185 r14345  
    471471            if (row < 0 || row >= dataset.Rows) return double.NaN;
    472472            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);
     473            if (!variableConditionTreeNode.Symbol.IgnoreSlope) {
     474              double variableValue = ((IList<double>)currentInstr.data)[row];
     475              double x = variableValue - variableConditionTreeNode.Threshold;
     476              double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));
     477
     478              double trueBranch = Evaluate(dataset, ref row, state);
     479              double falseBranch = Evaluate(dataset, ref row, state);
     480
     481              return trueBranch * p + falseBranch * (1 - p);
     482            } else {
     483              // strict threshold
     484              double variableValue = ((IList<double>)currentInstr.data)[row];
     485              if (variableValue <= variableConditionTreeNode.Threshold) {
     486                var left = Evaluate(dataset, ref row, state);
     487                state.SkipInstructions();
     488                return left;
     489              } else {
     490                state.SkipInstructions();
     491                return Evaluate(dataset, ref row, state);
     492              }
     493            }
    481494          }
    482495        default:
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r14282 r14345  
    126126    private readonly object syncRoot = new object();
    127127    public IEnumerable<double> GetSymbolicExpressionTreeValues(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows) {
     128      if (!rows.Any()) return Enumerable.Empty<double>();
    128129      if (CheckExpressionsWithIntervalArithmetic)
    129130        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
     
    159160          if (row < 0 || row >= dataset.Rows) instr.value = double.NaN;
    160161          var variableConditionTreeNode = (VariableConditionTreeNode)instr.dynamicNode;
    161           double variableValue = ((IList<double>)instr.data)[row];
    162           double x = variableValue - variableConditionTreeNode.Threshold;
    163           double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));
    164 
    165           double trueBranch = code[instr.childIndex].value;
    166           double falseBranch = code[instr.childIndex + 1].value;
    167 
    168           instr.value = trueBranch * p + falseBranch * (1 - p);
     162          if (!variableConditionTreeNode.Symbol.IgnoreSlope) {
     163            double variableValue = ((IList<double>)instr.data)[row];
     164            double x = variableValue - variableConditionTreeNode.Threshold;
     165            double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x));
     166
     167            double trueBranch = code[instr.childIndex].value;
     168            double falseBranch = code[instr.childIndex + 1].value;
     169
     170            instr.value = trueBranch * p + falseBranch * (1 - p);
     171          } else {
     172            double variableValue = ((IList<double>)instr.data)[row];
     173            if (variableValue <= variableConditionTreeNode.Threshold) {
     174              instr.value = code[instr.childIndex].value;
     175            } else {
     176              instr.value = code[instr.childIndex + 1].value;
     177            }
     178          }
    169179        } else if (instr.opCode == OpCodes.Add) {
    170180          double s = code[instr.childIndex].value;
     
    411421              for (int j = 1; j != seq.Length; ++j)
    412422                seq[j].skip = true;
    413             }
    414             break;
     423              break;
     424            }
    415425        }
    416426        #endregion
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableCondition.cs

    r14185 r14345  
    149149        }
    150150      }
     151    }
     152
     153    /// <summary>
     154    /// Flag to indicate if the interpreter should ignore the slope parameter (introduced for representation of expression trees)
     155    /// </summary>
     156    [Storable]
     157    private bool ignoreSlope;
     158    public bool IgnoreSlope {
     159      get { return ignoreSlope; }
     160      set { ignoreSlope = value; }
    151161    }
    152162
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs

    r14185 r14345  
    9696
    9797    public override string ToString() {
    98       if (slope.IsAlmost(0.0))
     98      if (slope.IsAlmost(0.0) || Symbol.IgnoreSlope) {
     99        return variableName + " < " + threshold.ToString("E4");
     100      } else {
    99101        return variableName + " > " + threshold.ToString("E4") + Environment.NewLine +
    100           "slope: " + slope.ToString("E4");
    101       else
    102         return variableName + " > " + threshold.ToString("E4");
     102               "slope: " + slope.ToString("E4");
     103      }
    103104    }
    104105  }
Note: See TracChangeset for help on using the changeset viewer.