Changeset 1567 in Sophya for trunk/SophyaProg/Tests/lpk.cc


Ignore:
Timestamp:
Jul 5, 2001, 5:46:30 PM (24 years ago)
Author:
ansari
Message:

Ajout test de LapackServer<T>::LeastSquareSolve() ds lpk.cc - Reza 5/7/2001

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/Tests/lpk.cc

    r1425 r1567  
    1414int lpk_linsolve_mtx(int n);
    1515int lpk_svd_mtx(int l, int c, int wsf, bool covu=true);
     16int lpk_leastsquare_mtx(int l, int c);
    1617
    1718static double TOLERANCE = 1.e-6;
     
    3132         << "   linsolve:  lpk_linsolve_mtx() LapackServer::LinSolve with TMatrix<r_8> \n"
    3233         << "   svd:  lpk_svd_mtx() LapackServer::SVD(a,s,u,vt) with TMatrix<r_8> \n"
    33          << "   svds:  lpk_svd_mtx() LapackServer::SVD(a,s); with TMatrix<r_8> \n"
     34         << "   svds:  lpk_svd_mtx() LapackServer::SVD(a,s); with TMatrix<r_8> \n"
     35         << "   lss:  lpk_leastsquare_mtx() LapackServer::LeastSquareSolve() r_8 \n"
    3436         << "   rzt:  lpk_rzt_tarr() rztest_lapack with TArray<r_4> \n" << endl;
    3537    exit(0);
     
    5254    else if (opt == "svd") rc = lpk_svd_mtx(l,c,wsf,true);
    5355    else if (opt == "svds") rc = lpk_svd_mtx(l,c,wsf,false);
     56    else if (opt == "lss") rc = lpk_leastsquare_mtx(l,c);
    5457    else if (opt == "rzt") rc = lpk_rzt_arr(l);
    5558    else { cout << " Unknown option " << opt << " ! " << endl; rc = 66; }
     
    160163}
    161164
     165// -----------------------------------------------------------------------
     166/* Nouvelle-Fonction */
     167int lpk_leastsquare_mtx(int m, int n)
     168{
     169  BaseArray::SetDefaultMemoryMapping(BaseArray::FortranMemoryMapping);
     170  cout << " lpk_leastsquare_mtx() - Test of LapackLeastSquareSolve " << endl;
     171 
     172  Matrix a(m , n), aa;
     173  a = RandomSequence(RandomSequence::Gaussian, 0., 4.);
     174  aa = a;
     175  Vector x(n),noise(m),b,bx;
     176  x = RandomSequence(RandomSequence::Gaussian, 2., 1.);
     177  double signoise = 0.1;
     178  noise = RandomSequence(RandomSequence::Gaussian, 0., 0.1);
     179  b = a*x;
     180  bx = b+noise;
     181 
     182  cout << " ---- lpk_leastsquare_tmtx() LapackLeastSquareSolve<r_8> ---- " << endl;
     183  cout << " ------------ Matrix A = \n " << a << "\n" << endl;
     184  cout << " ------------ Vector B = \n " << bx << "\n" << endl;
     185  cout << " ------------ Vector X = \n " << x << "\n" << endl;
     186
     187  cout << "\n   Calling  LapackLeastSquareSolve(a,bx) .... " << endl;
     188  PrtTim(" Calling LapackLeastSquareSolve() ");
     189  LapackLeastSquareSolve(aa, bx);
     190  PrtTim(" End LapackLeastSquareSolve() ");
     191  bx.Share(bx(Range(0,0,n)));
     192  cout << " ------------ Result X  = \n " << bx << "\n" << endl;
     193  cout << " ------------ X-X_Real  = \n " << bx-x << "\n" << endl;
     194  Vector diff = b-a*bx;
     195  PrtTim(" End of Compute(diff)");
     196  cout << " ------------ Matrix diff b-a*x = \n " << diff << "\n" << endl;
     197  double mean,sigma;
     198  MeanSigma(diff, mean, sigma);
     199  cout << " MeanSigma(diff) , Mean= " << mean << " Sigma=" << sigma
     200       << " SigNoise= " << signoise << endl;
     201  if ((fabs(mean) > signoise) || (fabs(sigma-signoise) > signoise)) {
     202    cout << " !!! Difference exceeding tolerance (=" << TOLERANCE << ") !!!"
     203         << endl;
     204    return(99);
     205  }
     206  return(0);
     207
     208}
     209
     210
    162211void rztest_lapack(TArray<r_4>& aa, TArray<r_4>& bb);
    163212
Note: See TracChangeset for help on using the changeset viewer.