Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/15/16 20:23:12 (8 years ago)
Author:
gkronber
Message:

#2697:

  • extended converter for linear models to support lagged variables and changed AR(k) to use this method
Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/Convert.cs

    r14390 r14391  
    4848      return LinearModelToTreeConverter.CreateTree(variableNames, coefficients, @const);
    4949    }
     50    public static ISymbolicExpressionTree CreateLinearModel(string[] variableNames, int[] lags, double[] coefficients,
     51      double @const = 0) {
     52      return LinearModelToTreeConverter.CreateTree(variableNames, coefficients, @const);
     53    }
    5054  }
    5155}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs

    r14390 r14391  
    2828    public static ISymbolicExpressionTree CreateTree(string[] variableNames, double[] coefficients,
    2929      double @const = 0) {
     30      return CreateTree(variableNames, new int[variableNames.Length], coefficients, @const);
     31    }
     32
     33    public static ISymbolicExpressionTree CreateTree(string[] variableNames, int[] lags, double[] coefficients,
     34      double @const = 0) {
    3035      if (variableNames.Length == 0 ||
    31         variableNames.Length != coefficients.Length)
    32         throw new ArgumentException("The length of the variable names and coefficients vectors must match");
     36        variableNames.Length != coefficients.Length ||
     37        variableNames.Length != lags.Length)
     38        throw new ArgumentException("The length of the variable names, lags, and coefficients vectors must match");
     39
    3340      ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
    3441      ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
     
    3845
    3946      for (int i = 0; i < variableNames.Length; i++) {
    40         VariableTreeNode vNode = (VariableTreeNode)new Variable().CreateTreeNode();
    41         vNode.VariableName = variableNames[i];
    42         vNode.Weight = coefficients[i];
    43         addition.AddSubtree(vNode);
     47        if (lags[i] == 0) {
     48          VariableTreeNode vNode = (VariableTreeNode)new Variable().CreateTreeNode();
     49          vNode.VariableName = variableNames[i];
     50          vNode.Weight = coefficients[i];
     51          addition.AddSubtree(vNode);
     52        } else {
     53          LaggedVariableTreeNode vNode = (LaggedVariableTreeNode)new LaggedVariable().CreateTreeNode();
     54          vNode.VariableName = variableNames[i];
     55          vNode.Weight = coefficients[i];
     56          vNode.Lag = lags[i];
     57          addition.AddSubtree(vNode);
     58        }
    4459      }
    4560
Note: See TracChangeset for help on using the changeset viewer.