35
35
Distributions. insupport (:: Type{TuringWishart} , X:: Matrix ) = isposdef (X)
36
36
Distributions. insupport (d:: TuringWishart , X:: Matrix ) = size (X) == size (d) && isposdef (X)
37
37
38
- dim (d:: TuringWishart ) = size (d. chol, 1 )
39
- Base. size (d:: TuringWishart ) = (p = dim (d); (p, p))
38
+ Distributions . dim (d:: TuringWishart ) = size (d. chol, 1 )
39
+ Base. size (d:: TuringWishart ) = (p = Distributions . dim (d); (p, p))
40
40
Base. size (d:: TuringWishart , i) = size (d)[i]
41
- LinearAlgebra. rank (d:: TuringWishart ) = dim (d)
41
+ LinearAlgebra. rank (d:: TuringWishart ) = Distributions . dim (d)
42
42
43
43
# ### Statistics
44
44
45
45
Distributions. mean (d:: TuringWishart ) = d. df * Matrix (d. chol)
46
46
47
47
function Distributions. mode (d:: TuringWishart )
48
- r = d. df - dim (d) - 1.0
48
+ r = d. df - Distributions . dim (d) - 1.0
49
49
if r > 0.0
50
50
return Matrix (d. chol) * r
51
51
else
@@ -54,7 +54,7 @@ function Distributions.mode(d::TuringWishart)
54
54
end
55
55
56
56
function Distributions. meanlogdet (d:: TuringWishart )
57
- p = dim (d)
57
+ p = Distributions . dim (d)
58
58
df = d. df
59
59
v = logdet (d. chol) + p * logtwo
60
60
for i = 1 : p
@@ -64,7 +64,7 @@ function Distributions.meanlogdet(d::TuringWishart)
64
64
end
65
65
66
66
function Distributions. entropy (d:: TuringWishart )
67
- p = dim (d)
67
+ p = Distributions . dim (d)
68
68
df = d. df
69
69
d. c0 - 0.5 * (df - p - 1 ) * meanlogdet (d) + 0.5 * df * p
70
70
end
84
84
85
85
function Distributions. logpdf (d:: TuringWishart , X:: AbstractMatrix{<:Real} )
86
86
df = d. df
87
- p = dim (d)
87
+ p = Distributions . dim (d)
88
88
Xcf = cholesky (X)
89
89
return 0.5 * ((df - (p + 1 )) * logdet (Xcf) - tr (d. chol \ X)) - d. c0
90
90
end
91
91
92
92
# ### Sampling
93
93
function Distributions. _rand! (rng:: AbstractRNG , d:: TuringWishart , A:: AbstractMatrix )
94
- _wishart_genA! (rng, dim (d), d. df, A)
94
+ _wishart_genA! (rng, Distributions . dim (d), d. df, A)
95
95
unwhiten! (d. chol, A)
96
96
A .= A * A'
97
97
end
@@ -147,16 +147,16 @@ end
147
147
Distributions. insupport (:: Type{TuringInverseWishart} , X:: Matrix ) = isposdef (X)
148
148
Distributions. insupport (d:: TuringInverseWishart , X:: Matrix ) = size (X) == size (d) && isposdef (X)
149
149
150
- dim (d:: TuringInverseWishart ) = size (d. S, 1 )
151
- Base. size (d:: TuringInverseWishart ) = (p = dim (d); (p, p))
150
+ Distributions . dim (d:: TuringInverseWishart ) = size (d. S, 1 )
151
+ Base. size (d:: TuringInverseWishart ) = (p = Distributions . dim (d); (p, p))
152
152
Base. size (d:: TuringInverseWishart , i) = size (d)[i]
153
- LinearAlgebra. rank (d:: TuringInverseWishart ) = dim (d)
153
+ LinearAlgebra. rank (d:: TuringInverseWishart ) = Distributions . dim (d)
154
154
155
155
# ### Statistics
156
156
157
157
function Distributions. mean (d:: TuringInverseWishart )
158
158
df = d. df
159
- p = dim (d)
159
+ p = Distributions . dim (d)
160
160
r = df - (p + 1 )
161
161
if r > 0.0
162
162
return d. S * (1.0 / r)
@@ -165,25 +165,25 @@ function Distributions.mean(d::TuringInverseWishart)
165
165
end
166
166
end
167
167
168
- Distributions. mode (d:: TuringInverseWishart ) = d. S * inv (d. df + dim (d) + 1.0 )
168
+ Distributions. mode (d:: TuringInverseWishart ) = d. S * inv (d. df + Distributions . dim (d) + 1.0 )
169
169
170
170
# https://en.wikipedia.org/wiki/Inverse-Wishart_distribution#Moments
171
171
function Distributions. cov (d:: TuringInverseWishart , i:: Integer , j:: Integer , k:: Integer , l:: Integer )
172
- p, ν, Ψ = (dim (d), d. df, d. S)
172
+ p, ν, Ψ = (Distributions . dim (d), d. df, d. S)
173
173
ν > p + 3 || throw (ArgumentError (" cov only defined for df > dim + 3" ))
174
174
inv ((ν - p)* (ν - p - 3 )* (ν - p - 1 )^ 2 )* (2 Ψ[i,j]* Ψ[k,l] + (ν- p- 1 )* (Ψ[i,k]* Ψ[j,l] + Ψ[i,l]* Ψ[k,j]))
175
175
end
176
176
177
177
function Distributions. var (d:: TuringInverseWishart , i:: Integer , j:: Integer )
178
- p, ν, Ψ = (dim (d), d. df, d. S)
178
+ p, ν, Ψ = (Distributions . dim (d), d. df, d. S)
179
179
ν > p + 3 || throw (ArgumentError (" var only defined for df > dim + 3" ))
180
180
inv ((ν - p)* (ν - p - 3 )* (ν - p - 1 )^ 2 )* (ν - p + 1 )* Ψ[i,j]^ 2 + (ν - p - 1 )* Ψ[i,i]* Ψ[j,j]
181
181
end
182
182
183
183
# ### Evaluation
184
184
185
185
function Distributions. logpdf (d:: TuringInverseWishart , X:: AbstractMatrix{<:Real} )
186
- p = dim (d)
186
+ p = Distributions . dim (d)
187
187
df = d. df
188
188
Xcf = cholesky (X)
189
189
# we use the fact: tr(Ψ * inv(X)) = tr(inv(X) * Ψ) = tr(X \ Ψ)
194
194
195
195
# ### Sampling
196
196
197
- Distributions. _rand! (rng:: AbstractRNG , d:: TuringInverseWishart , A:: AbstractMatrix ) =
198
- (A .= inv (cholesky! (_rand! (rng, TuringWishart (d. df, inv (cholesky (d. S))), A))))
197
+ function Distributions. _rand! (rng:: AbstractRNG , d:: TuringInverseWishart , A:: AbstractMatrix )
198
+ X = Distributions. _rand! (rng, TuringWishart (d. df, inv (cholesky (d. S))), A)
199
+ A .= inv (cholesky! (X))
200
+ end
199
201
200
202
# # Adjoints
201
203
0 commit comments