home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / LIBMAT.ZIP / OLSCHOL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-16  |  3.3 KB  |  127 lines

  1. /**************************************************/
  2. /*      olschol.c source for olsChol class        */
  3. /**************************************************/
  4.  
  5.  
  6. /**************************************************/
  7. /*            MatClass Source File                */
  8. /*       Copyright of C. R. Birchenhall           */
  9. /*       University of Manchester, UK.            */
  10. /*   MatClass is freeware. This file should be    */
  11. /* made freely available to users of any software */
  12. /* whose creation is wholly or partly dependent   */
  13. /*                on this file.                   */
  14. /**************************************************/
  15.  
  16. #include "olschol.hpp"
  17. #include "matchol.hpp"
  18.  
  19. /*************************************************************/
  20. /*                      olsChol methods                       */
  21. /*************************************************************/
  22.  
  23. void olsChol::setNames( void )
  24. {
  25.    XTX.name( "olsXTX" ) ;
  26.    XTY.name( "olsXTY" ) ;
  27. } // olsChol setNames
  28.  
  29. #ifdef __cplusplus
  30. olsChol::olsChol( void ) : matOls( )
  31. #else
  32. olsChol::olsChol( void ) : ()
  33. #endif
  34. {
  35.    static char *mName = "olsChol" ;
  36.    matFunc func( mName ) ; 
  37.    status = 0 ;
  38.    setNames() ;
  39.    func.trace(TRUE) ;
  40. } // olsChol
  41.  
  42. #ifdef __cplusplus
  43. olsChol::olsChol( olsChol& ols ) : matOls( ols )
  44. #else
  45. olsChol::olsChol( olsChol& ols ) : ( ols )
  46. #endif
  47. {} // olsChol
  48.  
  49. void olsChol::operator = ( olsChol& ols )
  50. {
  51.       matOls::operator = ( ols ) ;
  52. } // olsChol =
  53.  
  54. #ifdef __cplusplus
  55. olsChol::olsChol( const matrix& y, const matrix& x )
  56.      : matOls( y, x )
  57. #else
  58. olsChol::olsChol( const matrix& y, const matrix& x )
  59.      : ( y, x )
  60. #endif
  61. {
  62.    static char *mName = "olsChol(y,x)" ;
  63.    matFunc func( mName ) ; 
  64.    setNames() ;
  65.    func.trace(TRUE) ;
  66. } // olsChol( matrix& )
  67.  
  68. olsChol::~olsChol( void )
  69. {
  70.    static char *mName = "~olsChol" ;
  71.    matFunc func( mName ) ; debugInfo( func ) ;
  72. } // ~olsChol
  73.  
  74. void olsChol::initial( void )
  75. {
  76.    matOls::initial() ;
  77.    XTX.reset( nVars, nVars ) ;
  78.    XTY.reset( nVars, nDep ) ;
  79. } // olsChol::initial
  80.  
  81. void olsChol::clear( void )
  82. {
  83.    matOls::clear() ;
  84.    XTX.clear() ;
  85.    XTY.clear() ;
  86. } // olsChol::clear
  87.  
  88. void olsChol::decompose( void )
  89. {
  90.    static char *mName = "decomp" ;
  91.    matFunc func( mName ) ; debugInfo( func ) ;
  92.    matError error ;
  93.    if ( !( status & ASSIGNED ) )
  94.       errorExit( mName, UNASS ) ;
  95.    if ( !( status & DECOMPOSED ) ) {
  96.       XTX.TMultOf( X, X ) ;
  97.       XTY.TMultOf( X, Y ) ;
  98.       if ( !cholesky( XTX, error ) )
  99.      status |= SINGULAR ;
  100.       else {
  101.          // Copy transposed cholesky factor into R
  102.          R.triuOf( XTX.trans() ) ;
  103.      triuInv( R, Rinv, tol, error ) ;
  104.      beta = XTY ;
  105.      cholSolve( XTX, beta, tol, error ) ;
  106.       } // else
  107.       status |= DECOMPOSED ;
  108.    } // if
  109. } // olsChol::decompose
  110.  
  111. outFile& olsChol::info( outFile& f ) M_CONST
  112. {
  113.    return matOls::olsInfo( f, "olsChol" ) ;
  114. } // olsChol::info
  115.  
  116. REAL olsChol::varAdd( const matrix& z, INDEX i )
  117. /***************************************************
  118.   Return modified RSS when vars z added to nth eq.
  119. ***************************************************/
  120. {
  121.    static char *mName = "addVar" ;
  122.    matFunc func( mName ) ; debugInfo( func ) ;
  123.    z.errorExit( mName, NIMPL ) ;
  124.    return (REAL) i ;
  125. } // olsChol::varAdd
  126.  
  127.