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 #ifndef GRETL_BFGS_H
21 #define GRETL_BFGS_H
22 
23 typedef enum {
24     BHHH_MAX,
25     BFGS_MAX,
26     LBFGS_MAX,
27     SIMANN_MAX,
28     NM_MAX,
29     GSS_MAX,
30     ROOT_FIND
31 } MaxMethod;
32 
33 typedef double (*BFGS_CRIT_FUNC) (const double *, void *);
34 typedef int (*BFGS_GRAD_FUNC) (double *, double *, int,
35 			       BFGS_CRIT_FUNC, void *);
36 typedef double (*BFGS_COMBO_FUNC) (double *, double *, int, void *);
37 typedef const double *(*BFGS_LLT_FUNC) (const double *, int, void *);
38 typedef int (*HESS_FUNC) (double *, gretl_matrix *, void *);
39 typedef double (*ZFUNC) (double, void *);
40 
41 int BFGS_max (double *b, int n, int maxit, double reltol,
42 	      int *fncount, int *grcount, BFGS_CRIT_FUNC cfunc,
43 	      int crittype, BFGS_GRAD_FUNC gradfunc, void *data,
44 	      const gretl_matrix *A0, gretlopt opt, PRN *prn);
45 
46 int LBFGS_max (double *b, int n, int maxit, double reltol,
47 	       int *fncount, int *grcount, BFGS_CRIT_FUNC cfunc,
48 	       int crittype, BFGS_GRAD_FUNC gradfunc,
49 	       BFGS_COMBO_FUNC combo_func, void *data,
50 	       const gretl_matrix *bounds, gretlopt opt, PRN *prn);
51 
52 int newton_raphson_max (double *b, int n, int maxit,
53 			double crittol, double gradtol,
54 			int *itercount, int crittype,
55 			BFGS_CRIT_FUNC cfunc,
56 			BFGS_GRAD_FUNC gradfunc,
57 			HESS_FUNC hessfunc,
58 			void *data, gretlopt opt, PRN *prn);
59 
60 int BFGS_numeric_gradient (double *b, double *g, int n,
61 			   BFGS_CRIT_FUNC func, void *data);
62 
63 gretl_matrix *numerical_score_matrix (double *b, int T, int k,
64 				      BFGS_LLT_FUNC lltfun,
65 				      void *data, int *err);
66 
67 int hessian_from_score (double *b, gretl_matrix *H,
68 			BFGS_GRAD_FUNC gradfunc,
69 			BFGS_CRIT_FUNC cfunc,
70 			void *data);
71 
72 gretl_matrix *hessian_inverse_from_score (double *b, int n,
73 					  BFGS_GRAD_FUNC gradfunc,
74 					  BFGS_CRIT_FUNC cfunc,
75 					  void *data, int *err);
76 
77 int numerical_hessian (double *b, gretl_matrix *H,
78 		       BFGS_CRIT_FUNC func, void *data,
79 		       int neg, double d);
80 
81 gretl_matrix *numerical_hessian_inverse (const double *b, int n,
82 					 BFGS_CRIT_FUNC func,
83 					 void *data, double d,
84 					 int *err);
85 
86 double user_BFGS (gretl_matrix *b,
87 		  const char *fncall,
88 		  const char *gradcall,
89 		  DATASET *dset,
90 		  const gretl_matrix *bounds,
91 		  int minimize, PRN *prn,
92 		  int *err);
93 
94 double user_NR (gretl_matrix *b,
95 		const char *fncall,
96 		const char *gradcall,
97 		const char *hesscall,
98 		DATASET *dset,
99 		int minimize, PRN *prn,
100 		int *err);
101 
102 double deriv_free_optimize (MaxMethod method,
103 			    gretl_matrix *b,
104 			    const char *fncall,
105 			    int maxit,
106 			    double tol,
107 			    int minimize,
108 			    DATASET *dset,
109 			    PRN *prn,
110 			    int *err);
111 
112 gretl_matrix *user_fdjac (gretl_matrix *theta, const char *fncall,
113 			  double eps, DATASET *dset, int *err);
114 
115 gretl_matrix *user_numhess (gretl_matrix *b, const char *fncall,
116 			    double d, DATASET *dset, int *err);
117 
118 int gretl_simann (double *theta, int n, int maxit,
119 		  BFGS_CRIT_FUNC cfunc, void *data,
120 		  gretlopt opt, PRN *prn);
121 
122 int gretl_amoeba (double *theta, int n, int maxit,
123 		  BFGS_CRIT_FUNC cfunc, void *data,
124 		  gretlopt opt, PRN *prn);
125 
126 int gretl_fzero (double *bracket, double tol,
127 		 ZFUNC zfunc, void *data, double *px,
128 		 gretlopt opt, PRN *prn);
129 
130 int gretl_gss (double *theta, double tol, int *ic,
131 	       BFGS_CRIT_FUNC cfunc, void *data,
132 	       gretlopt opt, PRN *prn);
133 
134 void BFGS_defaults (int *maxit, double *tol, int ci);
135 
136 int optimizer_get_matrix_name (const char *fncall, char *name);
137 
138 int hess_score_on (void);
139 
140 #endif /* GRETL_BFGS_H */
141