Skip to content

Commit f62ee93

Browse files
committed
Initial import
0 parents  commit f62ee93

File tree

164 files changed

+7242
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+7242
-0
lines changed

dist/Contents.m

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
% PROBABILITY DISTRIBUTION FUNCTIONS (contents of the dist-folder):
2+
%
3+
% probability density functions
4+
% BETA_LPDF - Beta log-probability density function (lpdf).
5+
% BETA_PDF - Beta probability density function (pdf).
6+
% DIR_LPDF - Log probability density function of uniform Dirichlet
7+
% distribution
8+
% DIR_PDF - Probability density function of uniform Dirichlet
9+
% distribution
10+
% GAM_CDF - Cumulative of Gamma probability density function (cdf).
11+
% GAM_LPDF - Log of Gamma probability density function (lpdf).
12+
% GAM_PDF - Gamma probability density function (pdf).
13+
% INVGAM_LPDF - Inverse-Gamma log probability density function.
14+
% INVGAM_PDF - Inverse-Gamma probability density function.
15+
% LAPLACE_LPDF - Laplace log-probability density function (lpdf).
16+
% LAPLACE_PDF - Laplace probability density function (pdf).
17+
% LOGN_LPDF - Log normal log-probability density function (lpdf)
18+
% LOGT_LPDF - Log probability density function (lpdf) for log Student's T
19+
% MNORM_LPDF - Multivariate-Normal log-probability density function (lpdf).
20+
% MNORM_PDF - Multivariate-Normal log-probability density function (lpdf).
21+
% KERNELP - Kernel density estimator for one dimensional distribution.
22+
% NORM_LPDF - Normal log-probability density function (lpdf).
23+
% NORM_PDF - Normal probability density function (pdf).
24+
% POISS_LPDF - Poisson log-probability density function.
25+
% POISS_PDF - Poisson probability density function.
26+
% SINVCHI2_LPDF - Scaled inverse-chi log-probability density function.
27+
% SINVCHI2_PDF - Scaled inverse-chi probability density function.
28+
% T_LPDF - Student's T log-probability density function (lpdf)
29+
% T_PDF - Student's T probability density function (pdf)
30+
% NORM_P - create Gaussian (multivariate) (hierarchical) prior
31+
% INVGAM_P - Create inverse-Gamma prior
32+
%
33+
% Error and gradient functions:
34+
% INVGAM_E - compute an error term for a parameter with inverse
35+
% gamma distribution (single parameter).
36+
% INVGAM_G - compute a gradient term for a parameter with inverse
37+
% gamma distribution (single parameter).
38+
% LAPLACE_E - compute an error term for a parameter with Laplace
39+
% distribution (single parameter).
40+
% LAPLACE_G - compute a gradient for a parameter with Laplace
41+
% distribution (single parameter).
42+
% MNORM_E - compute an error term for parameters with normal
43+
% distribution (multiple parameters).
44+
% MNORM_G - compute a gradient for parameters with normal
45+
% distribution (multible parameters)
46+
% MNORM_S - Maximum log likelihood second derivatives
47+
% NORM_E - compute an error term for a parameter with normal
48+
% distribution (single parameter).
49+
% NORM_G - compute a gradient for a parameter with normal
50+
% distribution (single parameter).
51+
% NORM_S - Maximum log likelihood second derivatives (single variable)
52+
% T_E - compute an error term for a parameter with Student's
53+
% t-distribution (single parameter).
54+
% T_G - compute a gradient for a parameter with Student's
55+
% t-distribution (single parameter).
56+
% DIR_E - compute an error term for a parameter with Dirichlet
57+
% distribution (single parameter).
58+
% GINVGAM_E - Compute an error term for a parameter with inverse
59+
% gamma distribution (single parameter).
60+
% GINVGAM_G - Compute a gradient term for a parameter with inverse
61+
% gamma distribution (single parameter).
62+
% GP2R_E - Evaluate error function for Gaussian Process.
63+
% GP2R_G - Evaluate gradient of error for Gaussian Process.
64+
% GNORM_E - Compute an error term for a parameter with normal
65+
% distribution (single parameter).
66+
% GNORM_G - Compute a gradient for a parameter with normal
67+
% distribution (single parameter).
68+
% GNORM_S - Maximum log likelihood second derivatives.
69+
% GT_E - Compute an error term for a parameter with Student's
70+
% t-distribution (single parameter).
71+
% GT_G - Compute a gradient for a parameter with Student's
72+
% t-distribution (single parameter).
73+
% GT_S - Maximum log likelihood second derivatives for
74+
% t-distribution.
75+
% T_S - Maximum log likelihood second derivatives for t-distribution
76+
% T_P - Create student t prior
77+
%
78+
% Functions to sample from full conditional distribution
79+
% COND_GINVGAM_CAT - Sample conditional distribution from
80+
% inverse gamma likelihood for a group and
81+
% categorical prior.
82+
% COND_GNORM_INVGAM - Sample conditional distribution from
83+
% normal likelihood for group and
84+
% inverse gamma prior.
85+
% COND_GNORM_NORM - Sample conditional distribution from normal
86+
% likelihood for a group and normal prior.
87+
% COND_GT_CAT - Sample conditional distribution from t
88+
% likelihood for a group and categorical prior.
89+
% COND_GT_INVGAM - Sample conditional distribution from t
90+
% likelihood for a group and inverse gamma prior.
91+
% COND_INVGAM_CAT - Sample conditional distribution from
92+
% inverse gamma likelihood and categorical prior.
93+
% COND_INVGAM_INVGAM - Sample conditional distribution from
94+
% inverse gamma likelihood and prior
95+
% COND_LAPLACE_INVGAM - Sample conditional distribution from Laplace
96+
% likelihood and inverse gamma prior.
97+
% COND_MNORM_INVWISH - Sample conditional distribution from normal
98+
% likelihood for multiparameter group and
99+
% inverse wishard prior.
100+
% COND_NORM_GINVGAM - Sample conditional distribution from
101+
% normal likelihood and inverse gamma prior
102+
% for a group
103+
% COND_NORM_INVGAM - Sample conditional distribution from
104+
% normal likelihood and inverse gamma prior
105+
% COND_T_CAT - Sample conditional distribution from t
106+
% likelihood and categorical prior.
107+
% COND_T_INVGAM - Sample conditional distribution from t
108+
% likelihood and inverse gamma prior.
109+
%
110+
% Random number generators
111+
% CATRAND - Random matrices from categorical distribution.
112+
% DIRRAND - Uniform dirichlet random vectors
113+
% EXPRAND - Random matrices from exponential distribution.
114+
% GAMRAND - Random matrices from gamma distribution.
115+
% INTRAND - Random matrices from uniform integer distribution.
116+
% INVGAMRAND - Random matrices from inverse gamma distribution
117+
% INVGAMRAND1 - Random matrices from inverse gamma distribution
118+
% INVWISHRND - Random matrices from inverse Wishart distribution.
119+
% NORMLTRAND - Random draws from a left-truncated normal
120+
% distribution, with mean = mu, variance = sigma2
121+
% NORMRTRAND - Random draws from a right-truncated normal
122+
% distribution, with mean = mu, variance = sigma2
123+
% NORMTRAND - Random draws from a normal truncated to interval
124+
% NORMTZRAND - Random draws from a normal distribution truncated by zero
125+
% WISHRND - Random matrices from Wishart distribution.
126+
% SINVCHI2RAND - Random matrices from scaled inverse-chi distribution
127+
% TRAND - Random numbers from Student's t-distribution
128+
% UNIFRAND - Generate unifrom random numberm from interval [A,B]

dist/beta_lpdf.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function y = beta_lpdf(x,a,b)
2+
%BETA_LPDF Beta log-probability density function (lpdf).
3+
%
4+
% Y = BETA_LPDF(X,A,B) Returns the log of the Beta pdf with
5+
% parameters A and B, at the values in X.
6+
%
7+
% The size of Y is the common size of the input arguments. A scalar input
8+
% functions as a constant matrix of the same size as the other inputs.
9+
%
10+
% Default value for A and B is 1.
11+
12+
% Copyright (c) 2005 Aki Vehtari
13+
14+
% This software is distributed under the GNU General Public
15+
% License (version 2 or later); please refer to the file
16+
% License.txt, included with the software, for details.
17+
18+
if nargin < 3,
19+
a = 1;
20+
end
21+
22+
if nargin < 2;
23+
b = 1;
24+
end
25+
26+
if nargin < 1,
27+
error('Requires at least one input argument.');
28+
end
29+
30+
y= (a-1).*log(x) +(b-1).*log(1-x) -betaln(a,b);

dist/beta_pdf.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function y = beta_pdf(x,a,b)
2+
%BETA_PDF Beta probability density function (pdf).
3+
%
4+
% Y = BETA_PDF(X,A,B) Returns the Beta pdf with
5+
% parameters A and B, at the values in X.
6+
%
7+
% The size of Y is the common size of the input arguments. A
8+
% scalar input functions as a constant matrix of the same size as
9+
% the other inputs.
10+
%
11+
% Default value for A and B is 1.
12+
13+
% Copyright (c) 2005 Aki Vehtari
14+
15+
% This software is distributed under the GNU General Public
16+
% License (version 2 or later); please refer to the file
17+
% License.txt, included with the software, for details.
18+
19+
if nargin < 3,
20+
a = 1;
21+
end
22+
23+
if nargin < 2;
24+
b = 1;
25+
end
26+
27+
if nargin < 1,
28+
error('Requires at least one input argument.');
29+
end
30+
31+
y=exp((a-1).*log(x) +(b-1).*log(1-x) -betaln(a,b));

dist/catrand.dll

6.5 KB
Binary file not shown.

dist/catrand.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function r = catrand(p, m, n);
2+
%CATRAND Random matrices from categorical distribution.
3+
%
4+
% Description
5+
% R = CATRAND(P) returns a matrix of random numbers chosen
6+
% from the categorical distribution with parameter P.
7+
% P is array of probabilities, which are not necessarily
8+
% normalized, though they must be non-negative, and not all zero
9+
% The size of R is the size of P. Alternatively,
10+
% R = CATRAND(P,M,N) returns an M by N matrix.
11+
12+
% Copyright (c) 1999-2004 Aki Vehtari
13+
14+
% This software is distributed under the GNU General Public
15+
% License (version 2 or later); please refer to the file
16+
% License.txt, included with the software, for details.
17+
18+
19+
p=p(:);
20+
pc=cumsum(p);
21+
pc=pc./pc(end);
22+
if nargin < 2
23+
m=1;n=1;
24+
elseif nargin <3
25+
n=m;
26+
end
27+
r=binsgeq(pc,rand(m,n));

dist/catrand.mexaxp

19.4 KB
Binary file not shown.

dist/catrand.mexglx

8.06 KB
Binary file not shown.

dist/cond_ginvgam_cat.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function r = cond_ginvgam_cat(a, a1, a2, x)
2+
% COND_GINVGAM_CAT Sample conditional distribution from inverse
3+
% gamma likelihood for a group and categorical prior.
4+
%
5+
% Description
6+
% R = COND_GINVGAM_CAT(A, A1, A2, X) generates one sample
7+
% from the conditional distribution of A given
8+
% parameter structure X of lower level, structure A1 of
9+
% same level hyper-parameters and A2 of higher level, i.e
10+
% is r~P(A|A1,A2,X). Returns one new sample R from the
11+
% distribution above.
12+
13+
% Copyright (c) 1999-2000 Aki Vehtari
14+
15+
% This software is distributed under the GNU General Public
16+
% License (version 2 or later); please refer to the file
17+
% License.txt, included with the software, for details.
18+
19+
20+
ii=a1.ii;
21+
m=length(ii);
22+
s=a1.s;
23+
nus=a2.nus;
24+
p=nus;
25+
r=zeros(1,m);
26+
for i=1:m
27+
xi2=x(ii{i}).^2;
28+
s2=s(i).^2;
29+
for j=1:length(nus)
30+
p(j)=sum(invgam_lpdf(xi2,s2,nus(j)));
31+
end
32+
p=exp(p-max(p));
33+
r(i)=nus(catrand(p));
34+
end

dist/cond_gnorm_invgam.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function r = cond_gnorm_invgam(a, a1, a2, x)
2+
% COND_GNORM_INVGAM Sample conditional distribution from
3+
% normal likelihood for group and
4+
% inverse gamma prior.
5+
%
6+
% Description
7+
% R = COND_GNORM_INVGAM(A, A1, A2, X) generates one sample
8+
% from the conditional distribution of A given
9+
% parameter structure X of lower level, structure A1 of
10+
% same level hyper-parameters and A2 of higher level, i.e
11+
% is r~P(A|A1,A2,X). Returns one new sample R from the
12+
% distribution above
13+
14+
% Copyright (c) 1999-2000 Aki Vehtari
15+
16+
% This software is distributed under the GNU General Public
17+
% License (version 2 or later); please refer to the file
18+
% License.txt, included with the software, for details.
19+
20+
21+
ii=a1.ii;
22+
m=length(ii);
23+
r=zeros(1,m);
24+
if size(a2.s,2)>1
25+
for i=1:m
26+
n=length(ii{i});
27+
r(i)=sqrt(invgamrand1((a2.nu*a2.s(i).^2+sumsqr(x(ii{i})))/(a2.nu+n), a2.nu+n));
28+
end
29+
else
30+
for i=1:m
31+
n=length(ii{i});
32+
r(i)=sqrt(invgamrand1((a2.nu*a2.s.^2+sumsqr(x(ii{i})))/(a2.nu+n), a2.nu+n));
33+
end
34+
end

dist/cond_gnorm_norm.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function r = cond_gnorm_norm(a, a1, a2, x)
2+
% COND_GNORM_NORM Sample conditional distribution from normal
3+
% likelihood for a group and normal prior.
4+
%
5+
%
6+
% Description
7+
% R = COND_GNORM_NORM(A, A1, A2, X) generates one sample
8+
% from the conditional distribution of A given
9+
% parameter structure X of lower level, structure A1 of
10+
% same level hyper-parameters and A2 of higher level, i.e
11+
% is r~P(A|A1,A2,X). Returns one new sample R from the
12+
% distribution above.
13+
14+
% Copyright (c) 1999-2000 Aki Vehtari
15+
16+
17+
% This software is distributed under the GNU General Public
18+
% License (version 2 or later); please refer to the file
19+
% License.txt, included with the software, for details.
20+
21+
ii=a1.ii;
22+
m=length(ii);
23+
if size(a2.s,2)<m
24+
a2.s=a2.s(ones(1,m));
25+
end
26+
r=zeros(1,m);
27+
for i=1:m
28+
n=length(ii{i});
29+
p1=n./a1.s(i).^2;p2=1./a2.s(i).^2;
30+
r(i)=(p2*a2.mu+p1*mean(x(ii{i})))./(p1+p2)+randn(1)*sqrt(1./(p1+p2));
31+
end

0 commit comments

Comments
 (0)