Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/23/19 20:33:58 (5 years ago)
Author:
gkronber
Message:

#2847: merged r16853, r16855, r16856, r16858, r17078, r17079:17085, r17139 from trunk to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs

    r17097 r17159  
    3838      double @const = 0) {
    3939
    40       if (factorCoefficients.Length == 0 && coefficients.Length == 0) throw new ArgumentException();
     40      if (factorCoefficients.Length == 0 && coefficients.Length == 0 && @const==0) throw new ArgumentException();
     41
     42      // Combine both trees
     43      ISymbolicExpressionTreeNode add = (new Addition()).CreateTreeNode();
    4144
    4245      // Create tree for double variables
    43       ISymbolicExpressionTree tree = null;     
    4446      if (coefficients.Length > 0) {
    45         tree = CreateTree(variableNames, new int[variableNames.Length], coefficients, @const);
    46         if (factorCoefficients.Length == 0) return tree;
     47        var varTree = CreateTree(variableNames, new int[variableNames.Length], coefficients);
     48        foreach (var varNode in varTree.IterateNodesPrefix().OfType<VariableTreeNode>())
     49          add.AddSubtree(varNode);
    4750      }
    4851
    4952      // Create tree for string variables
    50       ISymbolicExpressionTree factorTree = null;     
    5153      if (factorCoefficients.Length > 0) {
    52         factorTree = CreateTree(factors, factorCoefficients, @const);
    53         if (tree == null) return factorTree; 
     54        var factorTree = CreateTree(factors, factorCoefficients);
     55        foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>())
     56          add.AddSubtree(binFactorNode);
    5457      }
    5558
    56       // Combine both trees
    57       ISymbolicExpressionTreeNode add = tree.Root.GetSubtree(0).GetSubtree(0);
    58       foreach (var binFactorNode in factorTree.IterateNodesPrefix().OfType<BinaryFactorVariableTreeNode>())
    59         add.InsertSubtree(add.SubtreeCount - 1, binFactorNode);
     59      if (@const!=0.0) {
     60        ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     61        cNode.Value = @const;
     62        add.AddSubtree(cNode);
     63      }
     64
     65      ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
     66      ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
     67      tree.Root.AddSubtree(startNode);
     68      startNode.AddSubtree(add);
    6069      return tree;
    61 
    62       throw new ArgumentException();
    6370    }
    6471
Note: See TracChangeset for help on using the changeset viewer.