Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
dynare
Commits
abad13d0
Commit
abad13d0
authored
12 years ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Kill estimation if the likelihood is complex or NaN.
parent
17638552
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
matlab/dsge_likelihood.m
+32
-13
32 additions, 13 deletions
matlab/dsge_likelihood.m
matlab/print_info.m
+10
-8
10 additions, 8 deletions
matlab/print_info.m
with
42 additions
and
21 deletions
matlab/dsge_likelihood.m
+
32
−
13
View file @
abad13d0
...
...
@@ -80,8 +80,12 @@ function [fval,DLIK,Hess,exit_flag,ys,trend_coeff,info,Model,DynareOptions,Bayes
%!
The
covariance
matrix
of
the
measurement
errors
is
not
positive
definite
.
%!
@item
info
==
45
%!
Likelihood
is
not
a
number
(
NaN
).
%!
@item
info
==
4
5
%!
@item
info
==
4
6
%!
Likelihood
is
a
complex
valued
number
.
%!
@item
info
==
47
%!
Posterior
kernel
is
not
a
number
(
logged
prior
density
is
NaN
)
%!
@item
info
==
48
%!
Posterior
kernel
is
a
complex
valued
number
(
logged
prior
density
is
complex
).
%!
@end
table
%!
@item
Model
%!
Matlab
'
s
structure
describing
the
model
(
initialized
by
dynare
,
see
@ref
{
M_
}).
...
...
@@ -133,7 +137,7 @@ function [fval,DLIK,Hess,exit_flag,ys,trend_coeff,info,Model,DynareOptions,Bayes
%
set
also
'
exit_flag
'
equal
to
0
instead
of
1
.
It
is
only
when
%
dsge_likelihood
()
is
called
by
an
optimizer
called
by
%
dynare_estimation_1
()
that
'
exit_flag
'
is
ignored
and
penalized
'
fval
'
is
%
actually
used
.
%
actually
used
.
%
In
that
case
,
'
penalty
'
is
properly
initialized
,
at
the
very
end
of
the
%
present
function
,
by
a
call
to
dsge_likelihood
()
made
in
%
initial_estimation_checks
().
If
a
condition
triggers
exit_flag
==
...
...
@@ -176,7 +180,7 @@ end
if
nargout
==
1
,
analytic_derivation
=
0
;
end
%------------------------------------------------------------------------------
%
1
.
Get
the
structural
parameters
&
define
penalties
%------------------------------------------------------------------------------
...
...
@@ -332,7 +336,7 @@ if (kalman_algo == 2) || (kalman_algo == 4)
else
if
all
(
all
(
abs
(
H
-
diag
(
diag
(
H
)))
<
1e-14
))
%
ie
,
the
covariance
matrix
is
diagonal
...
H
=
diag
(
H
);
mmm
=
mm
;
mmm
=
mm
;
else
Z
=
[
Z
,
eye
(
pp
)];
T
=
blkdiag
(
T
,
zeros
(
pp
));
...
...
@@ -381,7 +385,7 @@ switch DynareOptions.lik_init
%
Use
standard
kalman
filter
except
if
the
univariate
filter
is
explicitely
choosen
.
if
kalman_algo
==
0
kalman_algo
=
3
;
elseif
~
((
kalman_algo
==
3
)
||
(
kalman_algo
==
4
))
elseif
~
((
kalman_algo
==
3
)
||
(
kalman_algo
==
4
))
error
([
'
diffuse
filter
:
options_
.
kalman_algo
can
only
be
equal
'
...
'
to
0
(
default
),
3
or
4
'
])
end
...
...
@@ -417,7 +421,7 @@ switch DynareOptions.lik_init
else
if
all
(
all
(
abs
(
H
-
diag
(
diag
(
H
)))
<
1e-14
))
%
ie
,
the
covariance
matrix
is
diagonal
...
H1
=
diag
(
H
);
mmm
=
mm
;
mmm
=
mm
;
else
Z
=
[
Z
,
eye
(
pp
)];
T
=
blkdiag
(
T
,
zeros
(
pp
));
...
...
@@ -605,8 +609,8 @@ if ((kalman_algo==1) || (kalman_algo==3))% Multivariate Kalman Filter
kalman_tol
,
riccati_tol
,
...
DynareOptions
.
presample
,
...
T
,
Q
,
R
,
H
,
Z
,
mm
,
pp
,
rr
,
Zflag
,
diffuse_periods
,
...
analytic_deriv_info
{
:
});
analytic_deriv_info
{
:
});
end
else
if
0
%
DynareOptions
.
block
...
...
@@ -644,7 +648,7 @@ end
if
(
kalman_algo
==
2
)
||
(
kalman_algo
==
4
)
%
Univariate
Kalman
Filter
%
resetting
measurement
error
covariance
matrix
when
necessary
%
%
resetting
measurement
error
covariance
matrix
when
necessary
%
if
~
correlated_errors_have_been_checked
if
isequal
(
H
,
0
)
H
=
zeros
(
pp
,
1
);
...
...
@@ -718,18 +722,20 @@ if analytic_derivation
end
end
if
isnan
(
LIK
)
info
=
45
;
exit_flag
=
0
;
return
end
if
imag
(
LIK
)
~=
0
likelihood
=
penalty
;
else
likelihood
=
LIK
;
info
=
46
;
exit_flag
=
0
;
return
end
likelihood
=
LIK
;
%
------------------------------------------------------------------------------
%
5
.
Adds
prior
if
necessary
%
-----------------------------------------------------------------------------
-
...
...
@@ -751,8 +757,21 @@ if analytic_derivation
else
lnprior
=
priordens
(
xparam1
,
BayesInfo
.
pshape
,
BayesInfo
.
p6
,
BayesInfo
.
p7
,
BayesInfo
.
p3
,
BayesInfo
.
p4
);
end
fval
=
(
likelihood
-
lnprior
);
if
isnan
(
fval
)
info
=
47
;
exit_flag
=
0
;
return
end
if
imag
(
fval
)
~=
0
info
=
48
;
exit_flag
=
0
;
return
end
%
Update
DynareOptions
.
kalman_algo
.
DynareOptions
.
kalman_algo
=
kalman_algo
;
...
...
This diff is collapsed.
Click to expand it.
matlab/print_info.m
+
10
−
8
View file @
abad13d0
...
...
@@ -65,7 +65,7 @@ if ~noprint
error
(
'Some updated params are complex'
)
case
24
error
(
'Some updated params contain NaN or Inf'
)
case
30
case
30
error
(
'Variance can
''
t be computed'
)
case
41
error
(
'one (many) parameter(s) do(es) not satisfy the lower bound'
);
...
...
@@ -77,20 +77,22 @@ if ~noprint
error
(
'The covariance matrix of the measurement errors is not positive definite.'
);
case
45
%DsgeLikelihood_hh / dsge_likelihood
error
(
'Likelihood is not a number (NaN) or a complex number'
);
case
46
%DsgeLikelihood_hh / dsge_likelihood
error
(
'Likelihood is a complex number'
);
case
47
%DsgeLikelihood_hh / dsge_likelihood
error
(
'Prior density is not a number (NaN)'
);
case
48
%DsgeLikelihood_hh / dsge_likelihood
error
(
'Prior density is a complex number'
);
case
51
error
(
'You are estimating a DSGE-VAR model, but the value of the dsge prior weight is too low!'
)
case
52
%DsgeVarLikelihood
error
(
''
);
case
61
%Discretionary policy
error
([
'Discretionary policy: maximum number of iterations has '
...
'been reached. Procedure failed. '
]);
error
([
'Discretionary policy: maximum number of iterations has been reached. Procedure failed. '
]);
case
62
error
([
'Discretionary policy: some eigenvalues greater than '
...
'options_.qz_criterium. Model potentially unstable.'
]);
error
([
'Discretionary policy: some eigenvalues greater than options_.qz_criterium. Model potentially unstable.'
]);
case
63
error
([
'Discretionary policy: NaN elements are present in the '
...
'solution. Procedure failed.'
]);
error
([
'Discretionary policy: NaN elements are present in the solution. Procedure failed.'
]);
% Aim Code Conversions by convertAimCodeToInfo.m
case
102
error
(
'Aim: roots not correctly computed by real_schur'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment