Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/17/16 16:20:08 (8 years ago)
Author:
gkronber
Message:

#2650: added support for factor variables to Excel formatter and Excel exporter as well as to the Latex formatter and consequently the mathematical representation view.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r14185 r14259  
    2828using HeuristicLab.Core;
    2929using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     30using HeuristicLab.Optimization.Operators;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132
     
    7172    }
    7273
     74
    7375    public string Format(ISymbolicExpressionTree symbolicExpressionTree, IDataset dataset) {
    7476      var stringBuilder = new StringBuilder();
     
    8890      int columnIndex = 0;
    8991      int inputIndex = 0;
    90       var usedVariables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(v => v.VariableName).Distinct();
     92      var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct();
    9193      foreach (var variable in dataset.VariableNames) {
    9294        columnIndex++;
     
    190192        stringBuilder.Append(variableTreeNode.Weight.ToString(CultureInfo.InvariantCulture));
    191193        stringBuilder.Append("*");
    192         stringBuilder.Append(GetColumnToVariableName(variableTreeNode.VariableName));// + LagToString(currentLag));
     194        stringBuilder.Append(GetColumnToVariableName(variableTreeNode.VariableName)); // + LagToString(currentLag));
     195      } else if (symbol is BinaryFactorVariable) {
     196        var binFactorNode = node as BinaryFactorVariableTreeNode;
     197        stringBuilder.AppendFormat("IF({0}=\"{1}\", {2}, 0)",
     198          GetColumnToVariableName(binFactorNode.VariableName),
     199          binFactorNode.VariableValue,
     200          binFactorNode.Weight.ToString(CultureInfo.InvariantCulture)
     201          );
     202      } else if (symbol is FactorVariable) {
     203        var factorNode = node as FactorVariableTreeNode;
     204        var values = factorNode.Symbol.GetVariableValues(factorNode.VariableName).ToArray();
     205        var w = factorNode.Weights;
     206        // create nested if
     207        for (int i = 0; i < values.Length; i++) {
     208          stringBuilder.AppendFormat("IF({0}=\"{1}\", {2}, ",
     209            GetColumnToVariableName(factorNode.VariableName),
     210            values[i],
     211            w[i].ToString(CultureInfo.InvariantCulture));
     212        }
     213        stringBuilder.Append("\"\""); // return empty string on unknown value
     214        stringBuilder.Append(')', values.Length); // add closing parenthesis
    193215      } else if (symbol is Power) {
    194216        stringBuilder.Append("POWER(");
Note: See TracChangeset for help on using the changeset viewer.