Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/17 12:17:13 (8 years ago)
Author:
gkronber
Message:

#2650 infix formatter also produces factor variable weights, infix parser supports reading of factor variable weights

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs

    r14719 r14761  
    224224      foreach(var parent in tree.IterateNodesPrefix().ToArray()) {
    225225        for(int i = 0; i < parent.SubtreeCount; i++) {
    226           var child = parent.GetSubtree(i) as VariableTreeNode;
    227           if(child != null && factorSymbol.VariableNames.Contains(child.VariableName)) {
     226          var varChild = parent.GetSubtree(i) as VariableTreeNode;
     227          var factorVarChild = parent.GetSubtree(i) as FactorVariableTreeNode;
     228          if(varChild != null && factorSymbol.VariableNames.Contains(varChild.VariableName)) {
    228229            parent.RemoveSubtree(i);
    229230            var factorTreeNode = (FactorVariableTreeNode)factorSymbol.CreateTreeNode();
    230             factorTreeNode.VariableName = child.VariableName;
     231            factorTreeNode.VariableName = varChild.VariableName;
    231232            factorTreeNode.Weights =
    232               factorTreeNode.Symbol.GetVariableValues(factorTreeNode.VariableName).Select(_ => 1.0).ToArray(); // weight = 1.0 for each value
     233              factorTreeNode.Symbol.GetVariableValues(factorTreeNode.VariableName).Select(_ => 1.0).ToArray();
     234            // weight = 1.0 for each value
     235            parent.InsertSubtree(i, factorTreeNode);
     236          } else if(factorVarChild != null && factorSymbol.VariableNames.Contains(factorVarChild.VariableName)) {
     237            if(factorSymbol.GetVariableValues(factorVarChild.VariableName).Count() != factorVarChild.Weights.Length)
     238              throw new ArgumentException(
     239                string.Format("Factor variable {0} needs exactly {1} weights",
     240                factorVarChild.VariableName,
     241                factorSymbol.GetVariableValues(factorVarChild.VariableName).Count()));
     242            parent.RemoveSubtree(i);
     243            var factorTreeNode = (FactorVariableTreeNode)factorSymbol.CreateTreeNode();
     244            factorTreeNode.VariableName = factorVarChild.VariableName;
     245            factorTreeNode.Weights = factorVarChild.Weights;
    233246            parent.InsertSubtree(i, factorTreeNode);
    234247          }
Note: See TracChangeset for help on using the changeset viewer.