Changeset 2445
- Timestamp:
- 10/22/09 10:31:19 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/ALGLIB/ALGLIB.csproj
r2435 r2445 88 88 <CopyToOutputDirectory>Always</CopyToOutputDirectory> 89 89 </Compile> 90 <Compile Include="descriptivestatistics.cs" /> 91 <Compile Include="gammaf.cs" /> 92 <Compile Include="igammaf.cs" /> 90 93 <Compile Include="leastsquares.cs" /> 94 <Compile Include="linreg.cs" /> 91 95 <Compile Include="lq.cs" /> 96 <Compile Include="normaldistr.cs" /> 92 97 <Compile Include="Properties\AssemblyInfo.cs" /> 93 98 <Compile Include="qr.cs" /> -
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.