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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stéphane Adjemian
dynare
Commits
dfa01edd
"preprocessor/NumericalInitialization.hh" did not exist on "ba0b58dfab48577145845df6fe3552790800910b"
Commit
dfa01edd
authored
11 months ago
by
Gregor Boehl
Browse files
Options
Downloads
Patches
Plain Diff
fix multivariate_student implementations
parent
bc3c11ee
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
matlab/distributions/multivariate_student_pdf.m
+27
-6
27 additions, 6 deletions
matlab/distributions/multivariate_student_pdf.m
matlab/distributions/rand_multivariate_student.m
+11
-9
11 additions, 9 deletions
matlab/distributions/rand_multivariate_student.m
with
38 additions
and
15 deletions
matlab/distributions/multivariate_student_pdf.m
+
27
−
6
View file @
dfa01edd
...
@@ -4,9 +4,10 @@ function density = multivariate_student_pdf(X,Mean,Sigma_upper_chol,df)
...
@@ -4,9 +4,10 @@ function density = multivariate_student_pdf(X,Mean,Sigma_upper_chol,df)
%
%
% INPUTS
% INPUTS
%
%
% X [double]
1
*n vector
% X [double]
dim
*n vector
% Mean [double] 1*n vector, expectation of the multivariate random variable.
% Mean [double] 1*n vector, expectation of the multivariate random variable.
% Sigma_upper_chol [double] n*n matrix, upper triangular Cholesky decomposition of Sigma (the "covariance matrix").
% Sigma_upper_chol [double] n*n matrix, upper triangular Cholesky decomposition of Sigma (the covariance
% matrix up to a factor df/(df-2)).
% df [integer] degrees of freedom.
% df [integer] degrees of freedom.
%
%
% OUTPUTS
% OUTPUTS
...
@@ -14,7 +15,7 @@ function density = multivariate_student_pdf(X,Mean,Sigma_upper_chol,df)
...
@@ -14,7 +15,7 @@ function density = multivariate_student_pdf(X,Mean,Sigma_upper_chol,df)
%
%
% SPECIAL REQUIREMENTS
% SPECIAL REQUIREMENTS
% Copyright © 2003-20
17
Dynare Team
% Copyright © 2003-20
24
Dynare Team
%
%
% This file is part of Dynare.
% This file is part of Dynare.
%
%
...
@@ -30,7 +31,27 @@ function density = multivariate_student_pdf(X,Mean,Sigma_upper_chol,df)
...
@@ -30,7 +31,27 @@ function density = multivariate_student_pdf(X,Mean,Sigma_upper_chol,df)
%
%
% You should have received a copy of the GNU General Public License
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
nn
=
length
(
X
);
if
df
<=
0
t1
=
gamma
(
.
5
*
(
nn
+
df
)
)
/
(
gamma
(
.
5
*
nn
)
*
(
df
*
pi
)
^
(
.
5
*
nn
)
)
;
error
(
'Degrees of freedom
''
df
''
must be positive'
)
end
[
~
,
nn
]
=
size
(
X
);
t1
=
gamma
(
.
5
*
(
nn
+
df
)
)
/
(
gamma
(
.
5
*
df
)
*
(
df
*
pi
)
^
(
.
5
*
nn
)
);
t2
=
t1
/
prod
(
diag
(
Sigma_upper_chol
))
;
t2
=
t1
/
prod
(
diag
(
Sigma_upper_chol
))
;
density
=
t2
/
(
1
+
(
X
-
Mean
)
*
(
Sigma_upper_chol
\(
transpose
(
Sigma_upper_chol
)\
transpose
(
X
-
Mean
)))/
df
)
^
(
.
5
*
(
nn
+
df
));
density
=
t2
.
/
(
1
+
sum
(((
X
-
Mean
)/
Sigma_upper_chol
)
.^
2
,
2
)/
df
)
.^
(
.
5
*
(
nn
+
df
));
\ No newline at end of file
return
% --*-- Unit tests --*--
%@test:1
% Normal density
try
m1
=
multivariate_student_pdf
([
1
2
],
0
,
chol
([
1
0.5
;
0.5
1
]),
10
)
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
%$
if
t
(
1
)
t
(
2
)
=
dassert
(
m1
,
0.02440738691918476
,
1e-6
);
end
T
=
all
(
t
);
%@eof:1
This diff is collapsed.
Click to expand it.
matlab/distributions/rand_multivariate_student.m
+
11
−
9
View file @
dfa01edd
function
draw
=
rand_multivariate_student
(
Mean
,
Sigma_upper_chol
,
df
)
function
draw
=
rand_multivariate_student
(
Mean
,
Sigma_upper_chol
,
df
,
n
)
% function draw = rand_multivariate_student(Mean,Sigma_upper_chol,df)
% function draw = rand_multivariate_student(Mean,Sigma_upper_chol,df
,n
)
% Pseudo random draws from a multivariate student distribution,
% Pseudo random draws from a multivariate student distribution,
% with expectation Mean, variance Sigma*df/(df-2) and degrees of freedom df>0.
% with expectation Mean, variance Sigma*df/(df-2) and degrees of freedom df>0.
%
%
% INPUTS
% INPUTS
%
%
% Mean [double] 1*n vector, expectation of the multivariate random variable.
% Mean [double] 1*n vector, expectation of the multivariate random variable.
% Sigma_upper_chol [double] n*n matrix, upper triangular Cholesky decomposition of Sigma
% Sigma_upper_chol [double] n*n matrix, upper triangular Cholesky decomposition of Sigma
(the covariance
%
(the covariance
matrix up to a factor df/(df-2)).
% matrix up to a factor df/(df-2)).
% df [integer] degrees of freedom.
% df [integer] degrees of freedom.
% n [integer] number of draws (defaults to 1).
%
%
% OUTPUTS
% OUTPUTS
% draw [double]
1*n
vector drawn from a multivariate normal distribution with expectation Mean and
% draw [double]
n*dim
vector drawn from a multivariate normal distribution with expectation Mean and
% covariance Sigma.
% covariance Sigma.
%
%
%
% NOTE See Zellner (appendix B.2, 1971) for a definition.
% NOTE See Zellner (appendix B.2, 1971) for a definition.
% Computes the t-distributed random numbers from
% Computes the t-distributed random numbers from
% X = \mu + Y\sqrt{\frac{\nu}{U}}
% X = \mu + Y\sqrt{\frac{\nu}{U}}
...
@@ -39,6 +39,8 @@ function draw = rand_multivariate_student(Mean,Sigma_upper_chol,df)
...
@@ -39,6 +39,8 @@ function draw = rand_multivariate_student(Mean,Sigma_upper_chol,df)
%
%
% You should have received a copy of the GNU General Public License
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
if
nargin
==
3
n
=
length
(
Mean
);
n
=
1
draw
=
Mean
+
randn
(
1
,
n
)
*
Sigma_upper_chol
*
sqrt
(
df
/
sum
(
randn
(
df
,
1
)
.^
2
));
end
dim
=
length
(
Mean
);
draw
=
Mean
+
(
randn
(
n
,
dim
)
*
Sigma_upper_chol
)
.*
sqrt
(
df
.
/
sum
(
randn
(
n
,
df
)
.^
2
,
2
));
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