@@ -58,7 +58,7 @@ julia> # Set the seed so get some consistency.
58
58
julia> # Sample!
59
59
chain = sample(model, RAM(), 10_000; chain_type=Chains, num_warmup, progress=false, initial_params=zeros(2));
60
60
61
- julia> norm (cov(Array(chain)) - [1.0 0.5; 0.5 1.0]) < 0.2
61
+ julia> isapprox (cov(Array(chain)), model.A; rtol = 0.2)
62
62
true
63
63
```
64
64
@@ -134,15 +134,14 @@ function step_inner(
134
134
135
135
# Sample the proposal.
136
136
x = state. x
137
- U = randn (rng, d)
138
- x_new = x + state. S * U
137
+ U = randn (rng, eltype (x), d)
138
+ x_new = muladd ( state. S, U, x)
139
139
140
140
# Compute the acceptance probability.
141
141
lp = state. logprob
142
142
lp_new = LogDensityProblems. logdensity (f, x_new)
143
143
logα = min (lp_new - lp, zero (lp)) # `min` because we'll use this for updating
144
- # TODO : use `randexp` instead.
145
- isaccept = log (rand (rng)) < logα
144
+ isaccept = randexp (rng) > - logα
146
145
147
146
return x_new, lp_new, U, logα, isaccept
148
147
end
@@ -177,13 +176,14 @@ function AbstractMCMC.step(
177
176
d = LogDensityProblems. dimension (f)
178
177
179
178
# Initial parameter state.
180
- x = initial_params === nothing ? rand (rng, d) : initial_params
179
+ T = initial_params === nothing ? eltype (sampler. γ) : Base. promote_type (eltype (sampler. γ), eltype (initial_params))
180
+ x = initial_params === nothing ? rand (rng, T, d) : convert (AbstractVector{T}, initial_params)
181
181
# Initialize the Cholesky factor of the covariance matrix.
182
- S = LowerTriangular (sampler. S === nothing ? diagm (0 => ones (eltype (sampler . γ) , d)) : sampler. S)
182
+ S = LowerTriangular (sampler. S === nothing ? diagm (0 => ones (T , d)) : convert (AbstractMatrix{T}, sampler. S) )
183
183
184
- # Constuct the initial state.
184
+ # Construct the initial state.
185
185
lp = LogDensityProblems. logdensity (f, x)
186
- state = RAMState (x, lp, S, 0.0 , 0 , 1 , true )
186
+ state = RAMState (x, lp, S, zero (T) , 0 , 1 , true )
187
187
188
188
return AdvancedMH. Transition (x, lp, true ), state
189
189
end
@@ -207,7 +207,7 @@ function valid_eigenvalues(S, lower_bound, upper_bound)
207
207
(lower_bound == 0 && upper_bound == Inf ) && return true
208
208
# Note that this is just the diagonal when `S` is triangular.
209
209
eigenvals = LinearAlgebra. eigvals (S)
210
- return all (lower_bound . <= eigenvals . <= upper_bound)
210
+ return all (x -> lower_bound <= x <= upper_bound, eigenvals )
211
211
end
212
212
213
213
function AbstractMCMC. step_warmup (
0 commit comments