| Libgretl Reference Manual |
|---|
bhhh_maxbhhh_max — |
enum BHHH_opts; model_info; int (*LL_FUNC) (double*, const double**, double**, model_info*, ...); void model_info_free (model_info *minfo); model_info* model_info_new (int k, int t1, int t2, int bign, double tol); MODEL* model_info_capture_OPG_model (model_info *minfo); gretl_matrix* model_info_get_VCV (model_info *minfo); double* model_info_get_theta (model_info *minfo); int model_info_get_t1 (const model_info *minfo); int model_info_get_t2 (const model_info *minfo); int model_info_get_n (const model_info *minfo); int model_info_get_iters (const model_info *minfo); void* model_info_get_extra_info (model_info *minfo); double model_info_get_ll (const model_info *minfo); double** model_info_get_series (const model_info *minfo); void model_info_set_extra_info (model_info *minfo, void *extra); void model_info_set_n_series (model_info *minfo, int n); int model_info_get_k (model_info *minfo); void model_info_set_opts (model_info *minfo, unsigned char opts); void model_info_set_ll (model_info *minfo, double ll, int do_score); int bhhh_max (LL_FUNC loglik, const double **X, const double *init_coeff, model_info *minfo, PRN *prn);
int (*LL_FUNC) (double*,
const double**,
double**,
model_info*,
...);
Param1 : |
|
Param2 : |
|
Param3 : |
|
Param4 : |
|
... : |
|
| Returns : |
void model_info_free (model_info *minfo);
Frees the dynamically allocated members of minfo, then
frees minfo itself.
minfo : |
model info pointer. |
model_info* model_info_new (int k, int t1, int t2, int bign, double tol);
Creates the basic information structure required by
bhhh_max(). Within that function, iteration is terminated
when the difference in the log-likelihood from one round to
the next falls below tol. Note that t1 and t2 are
zero-based.
k : |
number of parameters to be estimated. |
t1 : |
starting observation of estimation range. |
t2 : |
ending observation of estimation range. |
bign : |
total obserations in current dataset. |
tol : |
tolerance for assessing convergence. |
| Returns : | pointer to newly allocated model_info, or NULL
on failure.
|
MODEL* model_info_capture_OPG_model (model_info *minfo);
minfo : |
model info pointer. |
| Returns : | pointer to a gretl MODEL, which contains the
results of the OPG (Outer Product of the Gradient) regression
associated with minfo, if the preservation of this model
has been flagged by use of the option PRESERVE_OPG_MODEL:
see see model_info_set_opts(). Otherwise returns NULL.
|
gretl_matrix* model_info_get_VCV (model_info *minfo);
minfo : |
model info pointer. |
| Returns : | pointer to the covariance matrix of minfo, if
the creation of this matrix has been flagged by use of the
option FULL_VCV_MATRIX: see model_info_set_opts().
Otherwise returns NULL.
|
double* model_info_get_theta (model_info *minfo);
minfo : |
model info pointer. |
| Returns : | the parameter vector theta from minfo.
This array is freed when minfo is freed, so if the
results are wanted by the caller, they should be
copied.
|
int model_info_get_t1 (const model_info *minfo);
minfo : |
model info pointer. |
| Returns : | the (zero-based) start of the sample range for
minfo.
|
int model_info_get_t2 (const model_info *minfo);
minfo : |
model info pointer. |
| Returns : | the end of the sample range for minfo.
|
int model_info_get_n (const model_info *minfo);
minfo : |
model info pointer. |
| Returns : | the length of the data series used in minfo.
|
int model_info_get_iters (const model_info *minfo);
minfo : |
model info pointer. |
| Returns : | the number of iterations taken in estimating
the model in minfo.
|
void* model_info_get_extra_info (model_info *minfo);
Retrieves the content of the "extra" pointer member of minfo.
minfo : |
model info pointer. |
| Returns : | the pointer that was set with model_info_set_extra_info(),
or NULL if none was set.
|
double model_info_get_ll (const model_info *minfo);
minfo : |
model info pointer. |
| Returns : | the log-likelihood for minfo.
|
double** model_info_get_series (const model_info *minfo);
minfo : |
model info pointer. |
| Returns : | the allocated two-dimensional array set on
minfo using model_info_set_n_series(). This array
is freed when minfo is freed, so the returned pointer
itself should not be modified.
|
void model_info_set_extra_info (model_info *minfo, void *extra);
Set the content of the "extra" pointer member of minfo.
This pointer is not used within bhhh_max(), it is intended
for use within the log-likelihood callback. Setting this
pointer is therefore optional.
minfo : |
model info pointer. |
extra : |
pointer to set on minfo.
|
void model_info_set_n_series (model_info *minfo, int n);
Sets the number of auxiliary data series needed for the
calculations associated with minfo. These series are
allocated within the bhhh_max() function, and are freed
when minfo is freed; see model_info_free(). The length
of each series is given by the n member of minfo, which
is set implicitly when the start and end of the sample
range are set, using model_info_new(), and which
can be retrieved using model_info_get_n(). This length
is in fact t2 (zero-based ending observation of sample range)
plus one.
These series (if any) are not actually used within bhhh_max()
itself: they are intended for use within the log-likelihood
callback (serving as persistent storage, and saving the
callback function from having to allocate and deallocate
storage on each call). The series may be written to in that
context, but the pointers themselves should not be altered
in any way.
minfo : |
model info pointer. |
n : |
number of auxiliary data series. |
int model_info_get_k (model_info *minfo);
minfo : |
model info pointer. |
| Returns : | the number of regressors in minfo.
|
void model_info_set_opts (model_info *minfo, unsigned char opts);
Sets the option flags for minfo. If the option PRESERVE_OPG_MODEL
is set, a pointer to the MODEL struct used internally by bhhh_max()
is available on exit via model_info_capture_OPG_model(); otherwise
this is freed on exit. If FULL_VCV_MATRIX is set, a pointer to
the full covariance matrix from the last iteration of the OPG
model is available on exit using model_info_get_VCV().
minfo : |
model info pointer. |
opts : |
option flags to set, from BHHH_opts. |
void model_info_set_ll (model_info *minfo, double ll, int do_score);
Sets the log-likelihood for minfo. If do_score is non-zero,
sets the primary ll value, otherwise sets the secondary value,
which is used for comparison (to see if we have succeeded in
increasing the likelihood by following the estimated gradient).
minfo : |
model info pointer. |
ll : |
log-likehood. |
do_score : |
int bhhh_max (LL_FUNC loglik, const double **X, const double *init_coeff, model_info *minfo, PRN *prn);
Maximize likelihood using the BHHH conditional ML method, implemented via iteration of the Outer Product of the Gradient (OPG) regression with line search.
The minfo pointer is obtained using model_info_new().
Optional settings may be applied using model_info_set_opts(),
model_info_set_n_series() and model_info_set_extra_info().
loglik is called to calculate the log-likelihood for the model
in question. The parameters passed to this function are:
(1) the array of estimated coefficients; (2) the primary data
array X; (3) a further data array Z; (4) minfo; and (5) an
integer that is 1 if the score matrix should be calculated in
Z, otherwise 0. The Z array is allocated within bhhh_max
and is freed on exit; it is a two-dimensional array with k + 1
members, each of length n (where k and n may be obtained
using model_info_get_k() and model_info_get_n()). The first
member, Z[0], represents the constant or intercept, and should
not be modified.
For an example of the use of this function, see arma.c in the
plugin directory of the gretl source.
loglik : |
pointer to function for calculating log-likelihood and score matrix; see below. |
X : |
primary data set (not used within this function, but passed
on for use by loglik).
|
init_coeff : |
starting values for coefficients. |
minfo : |
model info struct; see below. |
prn : |
printing struct for iteration info (or NULL).
|
| Returns : | 0 on successful completion, non-zero error code otherwise. |
| << var | forecast >> |