maxlik.src
来自「没有说明」· SRC 代码 · 共 962 行 · 第 1/3 页
SRC
962 行
** _max_GradCheckTol - scalar, if nonzero and if proc's exist for
** computing the gradient or Hessian, their calculations
** will be compared with numerical gradients and Hessians
** in order to determine their correctness.
**
** ----- Convergence Criteria -----
**
** _max_GradTol - scalar, convergence tolerance for gradient of estimated
** coefficients. Default = 1e-5. When this criterion has been
** satisifed OPTMUM will exit the iterations.
**
** _max_MaxIters - scalar, maximum number of iterations.
**
** _max_MaxTime - scalar, maximum time in iterations in minutes.
** Default = 1e+5, about 10 weeks.
**
** ----- Data -----
**
** _max_Active - vector, 0 = fixed coefficient, 1 = active coefficient.
** By default all coefficients are active.
**
** __weight - vector, frequency of observations. By default all
** observations have a frequency of 1. zero frequencies
** are allowed. It is assumed that the elements of __weight
** sum to the number of observations.
**
** _max_Lag - scalar, if the function includes lagged values of the
** variables _max_Lag may be set to the number of lags. When
** _max_Lag is set to a nonzero value then __row is set to 1
** (that is, the function must evaluated one observation at a
** time), and MAXLIK will pass a matrix to the user-provided
** function and gradient procedures. The first row in this
** matrix will be (i - _max_Lag)-th observation and the last
** row will be the i-th observation. The read loop will begin
** with the (_max_Lag+1)-th observation. Default = 0.
**
** _max_NumObs - scalar, number of cases in the data set that was analyzed.
**
** _max_ParNames - Kx1 character vector, parameter labels.
**
** __row - determines the number of rows in the data set to be passed
** to the user-provided procedures. Default = 0.
**
** __rowfac - If MAXLIK fails due to insufficient memory while attempting
** to read a GAUSS data set, then __rowfac may be set to some
** value between 0 and 1 to read a proportion of the original
** number of rows of the GAUSS data set.
**
** ----- Miscellaneous -----
**
** __title - title of run
**
** _max_Diagnostic - scalar. If 1, current estimates ("coeffs"),
** gradient ("gradient"), direction ("direct"),
** function value ("function"), Hessian ("Hessian"),
** and step length computed in the line search ("step")
** are printed to the screen. If 2, they are
** stored in _max_Diagnostic using VPUT. Use
** VREAD to extract. If 3, both 1 and 2 occur.
**
** _max_IterData - 3x1 vector, contains information about the iterations.
** The first element contains the # of iterations , the second
** element contains the elapsed time in minutes of the iterations,
** and the third element contains a character variable indicating
** the type of covariance matrix of the parameters.
**
** _max_Key - scalar, controls keyboard capture. Useful for recursively
** nested version of MAXLIK. Setting _max_key = 0 for the
** nested versions will turn off their key board captures
** permitting the outside version to retain control of the
** keyboard.
**
**-------------------**------------------**-------------------**-----------**
**-------------------**------------------**-------------------**-----------**
**
** Procedure For Computing Likelihood Function
**
** The user must provide a procedure for computing the
** log-likelihood for either one observation, or for a matrix of
** observations. The procedure must have two input arguments,
** first, a vector of parameter values, and second, one or more rows
** of the data matrix. The output argument is the log-likelihood
** for the observation or observations in the second argument
** evaluated at the parameters values in the first argument.
** Suppose that the function procedure has been named fct,
** the following considerations apply:
**
** FORMAT
** logl=fct(x,y)
**
** INPUT
** x - vector of parameters of model
**
** y - one or more rows of the data set (if the data set has
** been transformed, or if vars /= 0, i.e., there is
** selection, then y is a transformed, selected observation)
** if __row == 1, one row of the data set
** if __row >= 2, if data set is stored in memory then
** all of the data set will be passed to FCT;
** if data set is stored in GAUSS data file
** then __row will be passed to passed to
** FCT.
** if __row <= 0, For data set is stored in memory same as
** __row >= 2,
** for GAUSS data file the maximum number of
** rows that will fit in memory will be
** computed by MAXLIK.
** if _max_Lag >= 1, a matrix of observations, the first is
** the i-_max_Lag row, and the final row is
** the i-th row.
**
** OUTPUT
** logl - the log-likelihood
** if __row == 1 or _max_Lag >= 1, a scalar value for
** a given observation, otherwise a vector of
** log-likelihoods.
**
**
** REMARKS
**
** If you have written the procedure such that it must compute
** the log-likelihood of one observation at a time then you
** must set __row = 1. But if you are able to write the procedure
** so that a vector of log-likelihoods may be returned then set
** __row=0; If you are getting "insufficient memory" messages when the
** data are being read from a GAUSS data file then either set __row ==1
** or to some positive value.
** Also, if the data set is stored in a GAUSS data set and the
** selected data set will fit into memory, then MAXLIK will read
** it in and store it before beginning the iterations. In this
** case the setting of __row will follow the rules of a data set
** stored in memory.
** Significant reduction in computation time may be achieved
** when the data set can be stored in memory and procedure is
** written to compute vectors of log-probabilities.
**
**-------------------**------------------**-------------------**-----------**
**-------------------**------------------**-------------------**-----------**
**
** Calling MAXLIK Recursively
**
** The procedure that computes the log-likelihood may itself call
** MAXLIK. When calling MAXLIK recursively the following
** considerations apply:
**
** If a data set is being analyzed and it is to be transformed
** or deleted for missing data or cases are to be selected, then
** this can be done only on the outermost version of MAXLIK, i.e.,
** the version called in the original command file. Variable
** selection (as opposed to case selection) can be done on any
** level through the second argument in the call to each version
** of MAXLIK. Data sets can be opened by nested versions of MAXLIK.
** If a nested version of MAXLIK is going to use the data set
** opened by the outer version of MAXLIK then pass a null string
** (i.e., "") in the first argument in the call. If it is going
** to analyze a different data set from the outer version then
** pass it the data set name in a string. You may also load and
** store a data set in memory in the command file and pass it as
** the first argument in the nested call to MAXLIK.
**
** Before the call to the nested version of MAXLIK, the global
** variables may be re-set by calling MAXCLR. You must not use
** MAXSET because that will clear information about the data sets
** opened and processed in the outer version. The only differences
** between MAXSET and MAXCLR are references to these globals.
**
** You may also want to disable the keyboard control of the
** nested versions. This is done by setting the global _max_key = 0
** after the call to MAXCLR and before the call to the nested MAXLIK.
**
*/
/*-------------------**------------------**-------------------**-----------**
**-------------------**------------------**-------------------**-----------*/
/* SOURCE CODE */
#include gauss.ext
#include maxlik.ext
external proc indices;
proc (5) = maxlik(dataset,var,lfct,start);
local x,f,g,h,retcode;
local Lmlcpvcp, Lmlhsvcp, Lmlfhess, Lmlitdta, Lmldiag;
if _max_GradMethod == 0;
_max_eps2 = __macheps^(1/3);
else;
_max_eps2 = __macheps^(1/2);
endif;
_max_eps3 = __macheps^(1/3);
{ x,f,g,h,retcode,Lmlfhess,Lmlitdta,Lmlcpvcp,Lmlhsvcp,_max_dat,
_max_NumObs,_max_row,_max_dsn,Lmldiag } = _max(dataset,var,lfct,start,
_max_Algorithm,
_max_Diagnostic,
_max_GradCheckTol,
_max_LineSearch,
_max_CovPar,
_max_GradMethod,
_max_GradStep,
_max_Delta,
_max_Extrap,
_max_GradProc,
_max_GradTol,
_max_HessProc,
_max_Interp,
_max_Key,
_max_Lag,
_max_MaxIters,
_max_MaxTime,
_max_MaxTry,
_max_NumObs,
_max_ParNames,
_max_RandRadius,
_max_Options,
_max_UserSearch,
_max_UserNumGrad,
_max_UserNumHess,
_max_Active,
_max_dat,
_max_dsn,
_max_row,
__altnam,
__output,
__row,
__title,
__weight
);
_max_FinalHess = Lmlfhess;
_max_IterData = Lmlitdta;
_max_XprodCov = Lmlcpvcp;
_max_HessCov = Lmlhsvcp;
_max_Diagnostic = Lmldiag;
retp(x,f,g,h,retcode);
endp;
proc(0) = maxset;
gausset;
_max_Options = 0;
_max_Algorithm = 2;
_max_LineSearch = 2;
_max_CovPar = 1;
_max_GradMethod = 1;
_max_ParNames = 0; /* parameter names */
_max_GradTol = 1e-5; /* convergence tolerance for gradient */
_max_HessProc = 0; /* procedure to compute hessian */
_max_GradProc = 0; /* procedure to compute gradient */
_max_MaxIters = 1e+5; /* maximum number of iterations */
_max_IterData = {0,0,0}; /* elapsed time, # of iters, cov method */
_max_RandRadius = .01; /* random line search */
_max_UserSearch = 0; /* interactive line search */
_max_UserNumGrad = 0;
_max_UserNumHess = 0;
_max_Extrap = 2.0; /* extrapolation constant */
_max_interp = 0.25; /* interpolation constant */
_max_Delta = .1;
_max_MaxTry = 100;
_max_Lag = 0; /* number of lags in model */
_max_FinalHess = 0;
_max_NumObs = 0; /* number of observations */
_max_HessCov = {.}; /* info matrix v-c matrix of par's */
_max_XprodCov = {.}; /* cross proc matrix v-c matrix of par's */
_max_key = 1;
_max_MaxTime = 1e5; /* maximum time for bootstrapping */
_max_Active = 1;
_max_GradStep = {.}; /* size of increment for computing gradient */
_max_GradCheckTol = 0;
_max_Diagnostic = {.};
_max_Alpha = .05;
_max_Switch = 0;
_max_BayesAlpha = 1.4;
_max_PriorProc = {.};
_max_CrossTab = { . }; /* crosstab of coef's output from cvhist */
_max_CutPoint = { . }; /* cutting points for _max_xtab */
_max_Increment = 0; /* if nonzero, histogram increments */
_max_Center = 0; /* if nonzero, center points for histogram */
_max_Width = 2; /* width of histogram = _max_Width * sd's */
_max_NumSample = 50; /* bootstrap sample size */
_max_NumCat = 16; /* # of cat's for bootstrapped histogram */
_max_Select = {.};
_max_dsn = "";
_max_dat = { . };
_max_row = 0;
endp;
proc(0) = maxclr;
gausset;
_max_Options = 0;
_max_Algorithm = 2;
_max_LineSearch = 2;
_max_CovPar = 1;
_max_GradMethod = 1;
_max_ParNames = 0; /* parameter names */
_max_GradTol = 1e-5; /* convergence tolerance for gradient */
_max_HessProc = 0; /* procedure to compute hessian */
_max_GradProc = 0; /* procedure to compute gradient */
_max_MaxIters = 1e+5; /* maximum number of iterations */
_max_IterData = {0,0,0}; /* elapsed time, # of iters, cov method */
_max_RandRadius = .01; /* random line search */
_max_UserSearch = 0; /* interactive line search */
_max_UserNumGrad = 0;
_max_UserNumHess = 0;
_max_Extrap = 2.0; /* extrapolation constant */
_max_interp = 0.25; /* interpolation constant */
_max_Delta = .1;
_max_MaxTry = 100;
_max_Lag = 0; /* number of lags in model */
_max_FinalHess = 0;
_max_NumObs = 0; /* number of observations */
_max_HessCov = 0; /* info matrix v-c matrix of par's */
_max_XprodCov = 0; /* cross proc matrix v-c matrix of par's */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?