Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15104


Ignore:
Timestamp:
07/01/17 08:48:34 (7 years ago)
Author:
gkronber
Message:

#2690 changed Excel-formatter for VariableCondition symbols to produce a correct output also for GBT and RF models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r14843 r15104  
    7878    }
    7979
    80     public string FormatWithMapping(ISymbolicExpressionTree symbolicExpressionTree, Dictionary<string,string> variableNameMapping)
    81     {
    82       foreach(var kvp in variableNameMapping) this.variableNameMapping.Add(kvp.Key,kvp.Value);
     80    public string FormatWithMapping(ISymbolicExpressionTree symbolicExpressionTree, Dictionary<string, string> variableNameMapping) {
     81      foreach (var kvp in variableNameMapping) this.variableNameMapping.Add(kvp.Key, kvp.Value);
    8382      var stringBuilder = new StringBuilder();
    84      
     83
    8584      stringBuilder.Append("=");
    8685      stringBuilder.Append(FormatRecursively(symbolicExpressionTree.Root));
     
    9392    }
    9493
    95     private Dictionary<string,string> CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
    96       var mapping = new Dictionary<string,string>();
     94    private Dictionary<string, string> CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
     95      var mapping = new Dictionary<string, string>();
    9796      int inputIndex = 0;
    9897      var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct().ToArray();
     
    241240      } else if (symbol is VariableCondition) {
    242241        VariableConditionTreeNode variableConditionTreeNode = node as VariableConditionTreeNode;
    243         double threshold = variableConditionTreeNode.Threshold;
    244         double slope = variableConditionTreeNode.Slope;
    245         string p = "(1 / (1 + EXP(-" + slope.ToString(CultureInfo.InvariantCulture) + " * (" + GetColumnToVariableName(variableConditionTreeNode.VariableName) + "-" + threshold.ToString(CultureInfo.InvariantCulture) + "))))";
    246         stringBuilder.Append("((");
    247         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    248         stringBuilder.Append("*");
    249         stringBuilder.Append(p);
    250         stringBuilder.Append(") + (");
    251         stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
    252         stringBuilder.Append("*(");
    253         stringBuilder.Append("1 - " + p + ")");
    254         stringBuilder.Append("))");
     242        if (!variableConditionTreeNode.Symbol.IgnoreSlope) {
     243          double threshold = variableConditionTreeNode.Threshold;
     244          double slope = variableConditionTreeNode.Slope;
     245          string p = "(1 / (1 + EXP(-" + slope.ToString(CultureInfo.InvariantCulture) + " * (" +
     246                     GetColumnToVariableName(variableConditionTreeNode.VariableName) + "-" +
     247                     threshold.ToString(CultureInfo.InvariantCulture) + "))))";
     248          stringBuilder.Append("((");
     249          stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
     250          stringBuilder.Append("*");
     251          stringBuilder.Append(p);
     252          stringBuilder.Append(") + (");
     253          stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
     254          stringBuilder.Append("*(");
     255          stringBuilder.Append("1 - " + p + ")");
     256          stringBuilder.Append("))");
     257        } else {
     258          stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "(IF({0} <= {1}, {2}, {3}))",
     259            GetColumnToVariableName(variableConditionTreeNode.VariableName),
     260            variableConditionTreeNode.Threshold,
     261            FormatRecursively(node.GetSubtree(0)),
     262            FormatRecursively(node.GetSubtree(1))
     263            );
     264        }
    255265      } else if (symbol is Xor) {
    256266        stringBuilder.Append("IF(");
Note: See TracChangeset for help on using the changeset viewer.