Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5021


Ignore:
Timestamp:
12/04/10 13:07:50 (13 years ago)
Author:
swinkler
Message:

Corrected evaluation of logical expressions in MATLAB formatter. (#1314)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.Extensions/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/Formatters/SymbolicExpressionTreeMATLABFormatter.cs

    r5020 r5021  
    7777        }
    7878      } else if (symbol is And) {
    79         stringBuilder.Append("(");
     79        stringBuilder.Append("((");
    8080        for (int i = 0; i < node.SubTrees.Count; i++) {
    8181          if (i > 0) stringBuilder.Append("&");
     
    8484          stringBuilder.Append(")>0)");
    8585        }
    86         stringBuilder.Append(")-0.5"); // MATLAB maps false and true to 0 and 1, resp., so we map this result to -0.5 and +0.5, resp.
     86        stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
    8787      } else if (symbol is Average) {
    8888        stringBuilder.Append("(1/");
     
    121121        stringBuilder.Append(")");
    122122      } else if (symbol is GreaterThan) {
    123         stringBuilder.Append("(");
     123        stringBuilder.Append("((");
    124124        stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
    125125        stringBuilder.Append(">");
    126126        stringBuilder.Append(FormatRecursively(node.SubTrees[1]));
    127         stringBuilder.Append(")-0.5"); // MATLAB maps false and true to 0 and 1, resp., so we map this result to -0.5 and +0.5, resp.
     127        stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
    128128      } else if (symbol is IfThenElse) {
    129129        stringBuilder.Append("(");
     
    134134        stringBuilder.Append("(");
    135135        stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
    136         stringBuilder.Append("<0)*");
     136        stringBuilder.Append("<=0)*");
    137137        stringBuilder.Append(FormatRecursively(node.SubTrees[2]));
    138138      } else if (symbol is LaggedVariable) {
     
    142142        stringBuilder.Append(laggedVariableTreeNode.VariableName + "(i-" + laggedVariableTreeNode.Lag + ")");
    143143      } else if (symbol is LessThan) {
    144         stringBuilder.Append("(");
     144        stringBuilder.Append("((");
    145145        stringBuilder.Append(FormatRecursively(node.SubTrees[0]));
    146146        stringBuilder.Append("<");
    147147        stringBuilder.Append(FormatRecursively(node.SubTrees[1]));
    148         stringBuilder.Append(")-0.5");
     148        stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
    149149      } else if (symbol is Logarithm) {
    150150        stringBuilder.Append("log(");
     
    160160        stringBuilder.Append("*-1");
    161161      } else if (symbol is Or) {
    162         stringBuilder.Append("(");
     162        stringBuilder.Append("((");
    163163        for (int i = 0; i < node.SubTrees.Count; i++) {
    164164          if (i > 0) stringBuilder.Append("|");
     
    167167          stringBuilder.Append(")>0)");
    168168        }
    169         stringBuilder.Append(")-0.5"); // MATLAB maps false and true to 0 and 1, resp., so we map this result to -0.5 and +0.5, resp.
     169        stringBuilder.Append(")-0.5)*2"); // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
    170170      } else if (symbol is Sine) {
    171171        stringBuilder.Append("sin(");
Note: See TracChangeset for help on using the changeset viewer.