1 /* 2 * gretl -- Gnu Regression, Econometrics and Time-series Library 3 * Copyright (C) 2001 Allin Cottrell and Riccardo "Jack" Lucchetti 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 /* Private header for sharing info between nls.c and gmm.c */ 21 22 #include "libgretl.h" 23 24 typedef struct parm_ parm; 25 typedef struct ocset_ ocset; 26 27 typedef enum { 28 NL_ANALYTICAL = 1 << 0, 29 NL_AUTOREG = 1 << 1, 30 NL_AHESS = 1 << 2, 31 NL_NEWTON = 1 << 3, 32 NL_SMALLSTEP = 1 << 4, 33 NL_NAMES_ARRAY = 1 << 5 34 } nl_flags; 35 36 struct nlspec_ { 37 int ci; /* NLS, MLE or GMM */ 38 int generr; /* error from genr */ 39 nl_flags flags; /* numeric or analytic derivatives, etc. */ 40 gretlopt opt; /* can include OPT_V for verbose output; if ci = MLE 41 can also include OPT_H (Hessian) or OPT_R (QML) 42 to control the estimator of the variance matrix; 43 can also include OPT_N to force use of 44 numerical derivatives. 45 */ 46 int dv; /* ID number of dependent variable (NLS) */ 47 int lhtype; /* type of the LHS variable */ 48 char lhname[VNAMELEN]; /* name of LHS var in criterion function */ 49 char hname[VNAMELEN]; /* name of Hessian matrix, if present */ 50 char *parnames; /* user-set names for parameters */ 51 int lhv; /* ID number of LHS series in function being 52 minimized or maximized... */ 53 gretl_matrix *lvec; /* or LHS vector */ 54 char *nlfunc; /* string representation of function, 55 expressed in terms of the residuals (NLS, 56 GMM) or the log-likelihood (MLE) 57 */ 58 int nparam; /* number of parameters */ 59 int ncoeff; /* number of coefficients (allows for vector params) */ 60 int nvec; /* number of vector parameters */ 61 int naux; /* number of auxiliary commands */ 62 int ngenrs; /* number of variable-generating formulae */ 63 int iters; /* number of iterations performed */ 64 int fncount; /* number of function evaluations (BFGS) */ 65 int grcount; /* number of gradient evaluations (BFGS) */ 66 int t1; /* starting observation */ 67 int t2; /* ending observation */ 68 int real_t1; /* real starting observation (if sub-sampled) */ 69 int real_t2; /* real ending observation (if sub-sampled) */ 70 int nobs; /* number of observations used */ 71 double crit; /* criterion (minimand or maximand) */ 72 double tol; /* tolerance for stopping iteration */ 73 parm *params; /* array of information on function parameters 74 (see the parm_ struct above) */ 75 double *fvec; /* function vector */ 76 double *coeff; /* coefficient estimates */ 77 gretl_matrix *J; /* Jacobian matrix */ 78 gretl_matrix *Hinv; /* negative inverse of Hessian */ 79 char **aux; /* auxiliary commands */ 80 char *hesscall; /* function call for Hessian */ 81 GENERATOR **genrs; /* variable-generation pointers */ 82 GENERATOR *hgen; /* generator for Hessian */ 83 DATASET *dset; /* pointer to dataset */ 84 PRN *prn; /* printing aparatus */ 85 ocset *oc; /* orthogonality info (GMM) */ 86 char *missmask; /* mask for missing observations */ 87 }; 88 89 void nlspec_destroy_arrays (nlspec *s); 90 91 void oc_set_destroy (ocset *oc); 92 93 int nl_calculate_fvec (nlspec *s); 94 95 int update_coeff_values (const double *x, nlspec *s); 96 97 int check_gmm_requirements (nlspec *spec); 98 99 int nlspec_add_orthcond (nlspec *s, const char *str, 100 const DATASET *dset); 101 102 int nlspec_add_ivreg_oc (nlspec *s, int lhv, const int *rlist, 103 const double **Z); 104 105 int nlspec_add_weights (nlspec *s, const char *str); 106 107 void nlspec_print_gmm_info (const nlspec *spec, PRN *prn); 108 109 void maybe_add_gmm_residual (MODEL *pmod, const nlspec *spec, 110 const DATASET *dset); 111 112 int gmm_add_vcv (MODEL *pmod, nlspec *spec); 113 114 int gmm_calculate (nlspec *s, PRN *prn); 115 116 int gmm_missval_check_etc (nlspec *s); 117