Non-linear Kalman-filter: mode_compute and hessian

Dear All,

I am trying to use gaussian filter for estimating a small-scale DSGE model.
I have tried with several different mode_computes and wanted to share some results:

  • mode_compute=6 :
    The novelty (at least to me) is that often does not manage to deal with the hessian:
    Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
    RCOND = 6.626260e-18.
    Error using chol : Matrix must be positive definite.

  • mode_compute = 7
    It seems to be the most robust and It manages almost always to provide a result.
    The mode_check plots are not smooth but it looks like to always find a maximum - see attachment.
    Is the simplex algorithm a local or global algorithm?

  • mode_compute=5 with optim = (‘Hessian’, 0)"
    Is also robust but It gets stuck in the initialization values.

  • mode_compute = 9
    Seems not to be robust. I read in document on CMAES (I could not find again the file to link it) that this **
    ** algorithm should be robust to the issue of the Hessian. However, I know in Dynare, It is not. Is there any **
    ** specific reason for this?

Unfortunately, when I try to estimate more than 6-7 parameters, the Hessian evaluated at the mode of the posterior distribution is often non-positive. For this reason, I have tried to use the option mcmc_jumping_covariance = identity_matrix, Is the following synthax correct?

%----------------------------
% NON-LINEAR ESTIMATION
%---------------------------

// enable pruning
options_.particle.pruning = 1;
// order 3 estimation is not implemented yet.
options_.particle.perturbation = 2;
// use a first order approximation to initialize the state covariance
options_.particle.initialization = 1;

// skip hessian calculation
options_.cova_compute = 1;

%--------------------------------------------

% Estimation command

%--------------------------------------------

estimation(datafile=‘simulated_trend_2_phi_par1.xls’, order=2, nobs=900,

filter_algorithm=gf,
distribution_approximation=cubature,

mode_compute=0,
mode_file=ASNL_estNL_mode,

mh_replic=30000, mh_nblocks=4, mh_jscale=0.1,
mcmc_jumping_covariance = identity_matrix,

mode_check, graph_format=(eps,fig))

PIE_obs Y_obs I_obs;

I am asking because I get usually the following error at this point: (Using Dynare 4.5.4 the below code is from check_posterior_sampler_options.m)

% here are all samplers requiring a proposal distribution
if ~strcmp(posterior_sampler_options.posterior_sampling_method,‘slice’)
if ~options_.cova_compute && ~(options_.load_mh_file && posterior_sampler_options.use_mh_covariance_matrix)
skipline()
disp(‘check_posterior_sampler_options:: I cannot start the MCMC because the Hessian of the posterior kernel at the mode was not computed’)
disp('check_posterior_sampler_options:: or there is no previous MCMC to load ')
error(‘check_posterior_sampler_options:: MCMC cannot start’)
end
end

Many thanks for any possible comment.
Best regards,
D

Could you please also provide the data and upload a mod-file?

Hi, it seems you are not using a nonlinear Kalman filter, but a Gaussian Particle filter with resampling by default (filter_algorithm=gf and not nlkf). This can explain why the mode_check is not smooth, mode-finding functions do not find anything, and why there is the error message on the Hessian.

Dear Professor Pfeifer,

Many thanks for your availability and my apologies for replying only now.
I preferred making some trials and digest your suggestions before replying.

Looking into the Gaussian filter routine the description was very similar to the one for nlkf and I got mislead. Thanks for letting me notice it.

I have tried using filter_algorithm=nlkf but I get issues with the Hessians used for propagating the distributions of the sigma-points - named ‘nodes’ in the related function in dynare.
This is the error, I usually get:

Error using chol
Matrix must be positive definite.

Error in nonlinear_kalman_filter (line 107)
H_lower_triangular_cholesky = chol(H)’ ;

Error in non_linear_dsge_likelihood (line 340)
LIK =
feval(DynareOptions.particle.algorithm,ReducedForm,Y,start,DynareOptions.particle,DynareOptions.threads);

My understanding is these hessians need to be computed for executing the kalman-filter step by means of Gaussian moment matching. So, they do not serve the same purpose as the hessian computed for making the MC-MC step more efficient. However, I have noticed that matrix H (which is the one causing the error) in nonlinear_kalman_filter.m (line 107) is a scalar = 0 or 1 and can be affected by varying the cova_compute option.

% Get covariance matrices
H = ReducedForm.H;
H_lower_triangular_cholesky = chol(H)’ ;
Q_lower_triangular_cholesky = chol(ReducedForm.Q)’;

Attached a mod file and the data-set.

Many thanks in advance for your time.

The difference between NLKF and GF is the following.

The NL Kalman step can be implemented by using the nonlinearly solved model to predict the state and the measure variables. The rest is as in a standard Kalman Filter. This step produces the posterior distribution of states at time t conditional to t. The NLKF is simply iterating on this step over time.

The GF filter is a particle filter that uses the posterior of the NLKF as proposal to draw the current particles. It is interesting because this posterior includes an information on current measures, which is more optimal. The limit is that this proposal is Gaussian. At last, the interest is that the likelihood of the nonlinear model is used (which is not the case with NLKF) …

Anyway…

Your problem is the following. To use a particle filter, you need
measurement errors with variances to be included in the parameters set
to be estimated.

So if your model generates PIE, Y and Rn as measurement variables, you
need to add 3 measurement errors as well in estimated_params;

estimated_params;
   ... 
   stderr PIE, define the prior here;
   stderr Y, define the prior here;
   stderr Rn, define the prior here;
end;


estimated_params_init;
...
end;

varobs PIE Y Rn ;

These variances will be in the H matrix that are currently causing the
error message.

If you use distribution_approximation=cubature, Dynare will factorize
the matrix. If you use distribution_approximation=unscented, my guess
is the problem will disappear, if the size of H is 3x3, even with
zeros inside (no measurement errors).
In any other filters you may want to use, measurement errors are
compulsory. Otherwise, one can not evaluate the particles weights and
then the likelihood.
Methods exist (namely ABC methods that rely on computing the distance
between the simulated measures and the observed variables with other
things that a likelihood) but are not implemented in Dynare.

At last, this matrix H is not the covariance matrix used for the
MCMC… This one is calculated (in the linear case or in the nonlinear
cases where there is no resampling) as the hessien matrix of the
posterior distribution calculated at the mode. Using the nlkf is OK
before doing a MCMC.

Last of the last, I advise you to use mode_compute = 8 and even to
relaunch it several times from the previous solution to be sure you
reach the mode before starting the MCMC.

This site contains absolutely useful information, i had same issue with my non linear model, so i picked up my necessary codes from here