Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2445


Ignore:
Timestamp:
10/22/09 10:31:19 (15 years ago)
Author:
gkronber
Message:

Fixed #787 (LinearRegressionOperator uses leastsquares function of ALGLIB instead of linearregression function)

Location:
trunk/sources
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/ALGLIB/ALGLIB.csproj

    r2435 r2445  
    8888      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    8989    </Compile>
     90    <Compile Include="descriptivestatistics.cs" />
     91    <Compile Include="gammaf.cs" />
     92    <Compile Include="igammaf.cs" />
    9093    <Compile Include="leastsquares.cs" />
     94    <Compile Include="linreg.cs" />
    9195    <Compile Include="lq.cs" />
     96    <Compile Include="normaldistr.cs" />
    9297    <Compile Include="Properties\AssemblyInfo.cs" />
    9398    <Compile Include="qr.cs" />
  • trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegressionOperator.cs

    r2440 r2445  
    101101
    102102    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);
    108118
     119      double[] coefficients = new double[p];
     120      for (int i = 0; i < p; i++) {
     121        coefficients[i] = lm.w[i+4];
     122      }
    109123      return coefficients;
    110124    }
Note: See TracChangeset for help on using the changeset viewer.