nlmdl.cc

来自「一个统计模块的C++源程序!应该能用到的!」· CC 代码 · 共 130 行

CC
130
字号
/* ----------------------------------------------------------------------------

nlmdl: nlmdl.cc

nlmdl is a C++ implementation of the statistical methods in A. Ronald 
Gallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, 
1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed 
with it.  The header files nlmdl.h and realmat.h describe the use of the 
program and matrix class, respectively.  

Copyright (C) 1990.

A. Ronald Gallant
P.O. Box 5513 
Raleigh NC 27650-5513 
USA   

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, provided 
that the above copyright notice appear in all copies and that both that 
copyright notice and this permission notice appear in supporting 
documentation.  

This software is provided "as is" without any expressed or implied warranty.

---------------------------------------------------------------------------- */
#include "nlmdl.h"

typedef void (*ZERO_ARGUMENT_NL_OPR)();
typedef void (*ONE_ARGUMENT_NL_OPR)(int);

status s; 
model  m;

ZERO_ARGUMENT_NL_OPR opr_mgn;
ZERO_ARGUMENT_NL_OPR opr_obj;
ONE_ARGUMENT_NL_OPR  opr_var;
ZERO_ARGUMENT_NL_OPR opr_V;

#include "nlopr.cc"

int main()
{
  char msg[MAX_STATUS_LINE];

  s.from(s.starting); 

  repeat:

    if(m.initialize()==0) exit(0);

    s.from(s.starting);

    if(strcmp(s.detail,"none") != 0) s.display(START_UP);
    
    if(strcmp(s.detail,"none") != 0) 
      cout << starbox("/Starting theta//_") << s.theta; 

    if(strcmp(s.method,"SUR") == 0) {
      opr_mgn = &SUR_mgn; 
      opr_obj = &SUR_obj; 
      opr_var = &SUR_var; 
      opr_V   = &SUR_V;
    }
    else if(strcmp(s.method,"TSLS") == 0) {

      if ( strcmp(s.vartype,"heterogeneous") == 0 || s.MA>0 ) {
        cerr << "\nError, nlmdl, Use GMM for this case, not TSLS.\n\n";
        exit(1);
      }

      opr_mgn = &TSLS_mgn; 
      opr_obj = &TSLS_obj; 
      opr_var = &SUR_var; 
      opr_V   = &TSLS_V;
    }
    else if(strcmp(s.method,"GMM") == 0) {
      opr_mgn = &GMM_mgn;
      opr_obj = &GMM_obj; 
      opr_var = &GMM_var; 
      opr_V   = &GMM_V;
    }
    else {
      cerr << "Error, nlmdl, s.method set wrong.\n";
      exit(1);
    }

    s.V.resize(s.p, s.p, (REAL)0 );

    for (INTEGER i = 0; i <= s.p; i++) s.V.elem(i,i) = 1.0;

    s.D.resize(s.p, 1, (REAL)0 );

    for (INTEGER var_loop = 0; var_loop <= s.ivar; var_loop++) {

      (*opr_var)(var_loop);

      if(strcmp(s.detail,"full") == 0) {
        cout << "\nvar_loop " << var_loop << "\n";
        s.display(VAR_ITERATE);
      }

      for (INTEGER theta_loop = 0; theta_loop <= s.itheta; theta_loop++) {

        (*opr_mgn)();

        if(strcmp(s.detail,"full") == 0) {
          cout << "\ntheta_loop " << theta_loop << "\n";
          s.display(THETA_ITERATE);
        }
        
        int rv = line_search(&msg[0]);

        if(strcmp(s.detail,"full") == 0) cout << msg;
        if(rv != 0) break;
      }
    }

  (*opr_mgn)();
  (*opr_V)();

  s.to(s.ending);

  if (strcmp(s.detail,"none") != 0) s.display(TERMINATION);

  if(m.terminate() != 0) goto repeat;

  exit(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?