Changeset 2538 for trunk/sources
- Timestamp:
- 12/03/09 12:53:07 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegressionOperator.cs
r2445 r2538 71 71 private IFunctionTree CreateModel(double[] coefficients, List<string> allowedVariables, int minTimeOffset, int maxTimeOffset) { 72 72 IFunctionTree root = new Addition().GetTreeNode(); 73 IFunctionTree actNode = root; 73 74 74 int timeOffsetRange = (maxTimeOffset - minTimeOffset + 1); 75 75 76 Queue<IFunctionTree> nodes = new Queue<IFunctionTree>();77 76 for (int i = 0; i < allowedVariables.Count; i++) { 78 77 for (int timeOffset = minTimeOffset; timeOffset <= maxTimeOffset; timeOffset++) { … … 81 80 vNode.Weight = coefficients[(i * timeOffsetRange) + (timeOffset - minTimeOffset)]; 82 81 vNode.SampleOffset = timeOffset; 83 nodes.Enqueue(vNode);82 root.AddSubTree(vNode); 84 83 } 85 84 } … … 87 86 88 87 cNode.Value = coefficients[coefficients.Length - 1]; 89 nodes.Enqueue(cNode); 90 91 IFunctionTree newTree; 92 while (nodes.Count != 1) { 93 newTree = new Addition().GetTreeNode(); 94 newTree.AddSubTree(nodes.Dequeue()); 95 newTree.AddSubTree(nodes.Dequeue()); 96 nodes.Enqueue(newTree); 97 } 98 99 return nodes.Dequeue(); 88 root.AddSubTree(cNode); 89 return root; 100 90 } 101 91 … … 108 98 double[,] dataset = new double[n, p]; 109 99 for (int row = 0; row < n; row++) { 110 for (int column = 0; column < p -1; column++) {100 for (int column = 0; column < p - 1; column++) { 111 101 dataset[row, column] = inputMatrix[row, column]; 112 102 } 113 dataset[row, p -1] = targetVector[row];103 dataset[row, p - 1] = targetVector[row]; 114 104 } 115 alglib.linreg.lrbuild(ref dataset, n, p -1, ref retVal, ref lm, ref ar);105 alglib.linreg.lrbuild(ref dataset, n, p - 1, ref retVal, ref lm, ref ar); 116 106 if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression model"); 117 107 Console.Out.WriteLine("ALGLIB Linear Regression: Estimated generalization RMS = {0}", ar.cvrmserror); … … 119 109 double[] coefficients = new double[p]; 120 110 for (int i = 0; i < p; i++) { 121 coefficients[i] = lm.w[i +4];111 coefficients[i] = lm.w[i + 4]; 122 112 } 123 113 return coefficients;
Note: See TracChangeset
for help on using the changeset viewer.