home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2398 / nlmdl.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  3.1 KB  |  130 lines

  1. /* ----------------------------------------------------------------------------
  2.  
  3. nlmdl: nlmdl.cc
  4.  
  5. nlmdl is a C++ implementation of the statistical methods in A. Ronald 
  6. Gallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, 
  7. 1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed 
  8. with it.  The header files nlmdl.h and realmat.h describe the use of the 
  9. program and matrix class, respectively.  
  10.  
  11. Copyright (C) 1990.
  12.  
  13. A. Ronald Gallant
  14. P.O. Box 5513 
  15. Raleigh NC 27650-5513 
  16. USA   
  17.  
  18. Permission to use, copy, modify, and distribute this software and its 
  19. documentation for any purpose and without fee is hereby granted, provided 
  20. that the above copyright notice appear in all copies and that both that 
  21. copyright notice and this permission notice appear in supporting 
  22. documentation.  
  23.  
  24. This software is provided "as is" without any expressed or implied warranty.
  25.  
  26. ---------------------------------------------------------------------------- */
  27. #include "nlmdl.h"
  28.  
  29. typedef void (*ZERO_ARGUMENT_NL_OPR)();
  30. typedef void (*ONE_ARGUMENT_NL_OPR)(int);
  31.  
  32. status s; 
  33. model  m;
  34.  
  35. ZERO_ARGUMENT_NL_OPR opr_mgn;
  36. ZERO_ARGUMENT_NL_OPR opr_obj;
  37. ONE_ARGUMENT_NL_OPR  opr_var;
  38. ZERO_ARGUMENT_NL_OPR opr_V;
  39.  
  40. #include "nlopr.cc"
  41.  
  42. int main()
  43. {
  44.   char msg[MAX_STATUS_LINE];
  45.  
  46.   s.from(s.starting); 
  47.  
  48.   repeat:
  49.  
  50.     if(m.initialize()==0) exit(0);
  51.  
  52.     s.from(s.starting);
  53.  
  54.     if(strcmp(s.detail,"none") != 0) s.display(START_UP);
  55.     
  56.     if(strcmp(s.detail,"none") != 0) 
  57.       cout << starbox("/Starting theta//_") << s.theta; 
  58.  
  59.     if(strcmp(s.method,"SUR") == 0) {
  60.       opr_mgn = &SUR_mgn; 
  61.       opr_obj = &SUR_obj; 
  62.       opr_var = &SUR_var; 
  63.       opr_V   = &SUR_V;
  64.     }
  65.     else if(strcmp(s.method,"TSLS") == 0) {
  66.  
  67.       if ( strcmp(s.vartype,"heterogeneous") == 0 || s.MA>0 ) {
  68.         cerr << "\nError, nlmdl, Use GMM for this case, not TSLS.\n\n";
  69.         exit(1);
  70.       }
  71.  
  72.       opr_mgn = &TSLS_mgn; 
  73.       opr_obj = &TSLS_obj; 
  74.       opr_var = &SUR_var; 
  75.       opr_V   = &TSLS_V;
  76.     }
  77.     else if(strcmp(s.method,"GMM") == 0) {
  78.       opr_mgn = &GMM_mgn;
  79.       opr_obj = &GMM_obj; 
  80.       opr_var = &GMM_var; 
  81.       opr_V   = &GMM_V;
  82.     }
  83.     else {
  84.       cerr << "Error, nlmdl, s.method set wrong.\n";
  85.       exit(1);
  86.     }
  87.  
  88.     s.V.resize(s.p, s.p, (REAL)0 );
  89.  
  90.     for (INTEGER i = 0; i <= s.p; i++) s.V.elem(i,i) = 1.0;
  91.  
  92.     s.D.resize(s.p, 1, (REAL)0 );
  93.  
  94.     for (INTEGER var_loop = 0; var_loop <= s.ivar; var_loop++) {
  95.  
  96.       (*opr_var)(var_loop);
  97.  
  98.       if(strcmp(s.detail,"full") == 0) {
  99.         cout << "\nvar_loop " << var_loop << "\n";
  100.         s.display(VAR_ITERATE);
  101.       }
  102.  
  103.       for (INTEGER theta_loop = 0; theta_loop <= s.itheta; theta_loop++) {
  104.  
  105.         (*opr_mgn)();
  106.  
  107.         if(strcmp(s.detail,"full") == 0) {
  108.           cout << "\ntheta_loop " << theta_loop << "\n";
  109.           s.display(THETA_ITERATE);
  110.         }
  111.         
  112.         int rv = line_search(&msg[0]);
  113.  
  114.         if(strcmp(s.detail,"full") == 0) cout << msg;
  115.         if(rv != 0) break;
  116.       }
  117.     }
  118.  
  119.   (*opr_mgn)();
  120.   (*opr_V)();
  121.  
  122.   s.to(s.ending);
  123.  
  124.   if (strcmp(s.detail,"none") != 0) s.display(TERMINATION);
  125.  
  126.   if(m.terminate() != 0) goto repeat;
  127.  
  128.   exit(0);
  129. }
  130.