Changeset 2445 for trunk/sources/HeuristicLab.LinearRegression
- Timestamp:
- 10/22/09 10:31:19 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegressionOperator.cs
r2440 r2445 101 101 102 102 private double[] CalculateCoefficients(double[,] inputMatrix, double[] targetVector) { 103 double[] weights = new double[targetVector.Length]; 104 double[] coefficients = new double[inputMatrix.GetLength(1)]; 105 for (int i = 0; i < weights.Length; i++) weights[i] = 1.0; 106 // call external ALGLIB solver 107 alglib.leastsquares.buildgeneralleastsquares(ref targetVector, ref weights, ref inputMatrix, inputMatrix.GetLength(0), inputMatrix.GetLength(1), ref coefficients); 103 int retVal = 0; 104 alglib.linreg.linearmodel lm = new alglib.linreg.linearmodel(); 105 alglib.linreg.lrreport ar = new alglib.linreg.lrreport(); 106 int n = targetVector.Length; 107 int p = inputMatrix.GetLength(1); 108 double[,] dataset = new double[n, p]; 109 for (int row = 0; row < n; row++) { 110 for (int column = 0; column < p-1; column++) { 111 dataset[row, column] = inputMatrix[row, column]; 112 } 113 dataset[row, p-1] = targetVector[row]; 114 } 115 alglib.linreg.lrbuild(ref dataset, n, p-1, ref retVal, ref lm, ref ar); 116 if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression model"); 117 Console.Out.WriteLine("ALGLIB Linear Regression: Estimated generalization RMS = {0}", ar.cvrmserror); 108 118 119 double[] coefficients = new double[p]; 120 for (int i = 0; i < p; i++) { 121 coefficients[i] = lm.w[i+4]; 122 } 109 123 return coefficients; 110 124 }
Note: See TracChangeset
for help on using the changeset viewer.