Changeset 14391
 Timestamp:
 11/15/16 20:23:12 (3 years ago)
 Location:
 trunk/sources
 Files:

 3 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs
r14185 r14391 114 114 alglib.lrunpack(lm, out coefficients, out nFeatures); 115 115 116 117 ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 118 ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode(); 119 tree.Root.AddSubtree(startNode); 120 ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode(); 121 startNode.AddSubtree(addition); 122 123 for (int i = 0; i < timeOffset; i++) { 124 LaggedVariableTreeNode node = (LaggedVariableTreeNode)new LaggedVariable().CreateTreeNode(); 125 node.VariableName = targetVariable; 126 node.Weight = coefficients[i]; 127 node.Lag = (i + 1) * 1; 128 addition.AddSubtree(node); 129 } 130 131 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode(); 132 cNode.Value = coefficients[coefficients.Length  1]; 133 addition.AddSubtree(cNode); 116 var tree = LinearModelToTreeConverter.CreateTree( 117 variableNames: Enumerable.Repeat(problemData.TargetVariable, nFeatures).ToArray(), 118 lags: Enumerable.Range(0, timeOffset).Select(i => (i + 1) * 1).ToArray(), 119 coefficients: coefficients.Take(nFeatures).ToArray(), 120 @const: coefficients[nFeatures] 121 ); 134 122 135 123 var interpreter = new SymbolicTimeSeriesPrognosisExpressionTreeInterpreter(problemData.TargetVariable); 
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/Convert.cs
r14390 r14391 48 48 return LinearModelToTreeConverter.CreateTree(variableNames, coefficients, @const); 49 49 } 50 public static ISymbolicExpressionTree CreateLinearModel(string[] variableNames, int[] lags, double[] coefficients, 51 double @const = 0) { 52 return LinearModelToTreeConverter.CreateTree(variableNames, coefficients, @const); 53 } 50 54 } 51 55 } 
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs
r14390 r14391 28 28 public static ISymbolicExpressionTree CreateTree(string[] variableNames, double[] coefficients, 29 29 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) { 30 35 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 33 40 ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 34 41 ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode(); … … 38 45 39 46 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 } 44 59 } 45 60
Note: See TracChangeset
for help on using the changeset viewer.