Skip to content

Commit df4feb1

Browse files
Tor FjeldeTor Fjelde
authored andcommitted
fixed doctest
1 parent 11f3b64 commit df4feb1

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/AdvancedMH.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export
2323
SymmetricRandomWalkProposal,
2424
Ensemble,
2525
StretchProposal,
26-
MALA
26+
MALA,
27+
RobustAdaptiveMetropolis
2728

2829
# Reexports
2930
export sample, MCMCThreads, MCMCDistributed, MCMCSerial
@@ -160,9 +161,6 @@ include("proposal.jl")
160161
include("mh-core.jl")
161162
include("emcee.jl")
162163
include("MALA.jl")
163-
164164
include("RobustAdaptiveMetropolis.jl")
165-
using .RobustAdaptiveMetropolis
166-
export RAM
167165

168166
end # module AdvancedMH

src/RobustAdaptiveMetropolis.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ julia> # Sample!
5151
chain_type=Chains, num_warmup, progress=false, initial_params=zeros(2)
5252
);
5353
54-
julia> isapprox(cov(Array(chain)), model.A; rtol = 0.2)
54+
julia> isapprox(cov(Array(chain)), model.Σ; rtol = 0.2)
5555
true
5656
```
5757
5858
It's also possible to restrict the eigenvalues to avoid either too small or too large values. See p. 13 in [^VIH12].
5959
60-
```jldoctest ram-gaussian`
60+
```jldoctest ram-gaussian
6161
julia> chain = sample(
6262
model,
6363
RobustAdaptiveMetropolis(eigenvalue_lower_bound=0.1, eigenvalue_upper_bound=2.0),
@@ -144,7 +144,7 @@ function ram_step_inner(
144144
lp = state.logprob
145145
lp_new = LogDensityProblems.logdensity(f, x_new)
146146
logα = min(lp_new - lp, zero(lp)) # `min` because we'll use this for updating
147-
isaccept = randexp(rng) > -logα
147+
isaccept = Random.randexp(rng) > -logα
148148

149149
return x_new, lp_new, U, logα, isaccept
150150
end
@@ -159,14 +159,14 @@ function ram_adapt(
159159
S = state.S
160160
# TODO: Make this configurable by defining a more general path.
161161
η = state.iteration^(-sampler.γ)
162-
ΔS = η * abs(Δα) * S * U / norm(U)
162+
ΔS = η * abs(Δα) * S * U / LinearAlgebra.norm(U)
163163
# TODO: Maybe do in-place and then have the user extract it with a callback if they really want it.
164164
S_new = if sign(Δα) == 1
165165
# One rank update.
166-
LinearAlgebra.lowrankupdate(Cholesky(S), ΔS).L
166+
LinearAlgebra.lowrankupdate(LinearAlgebra.Cholesky(S), ΔS).L
167167
else
168168
# One rank downdate.
169-
LinearAlgebra.lowrankdowndate(Cholesky(S), ΔS).L
169+
LinearAlgebra.lowrankdowndate(LinearAlgebra.Cholesky(S), ΔS).L
170170
end
171171
return S_new, η
172172
end
@@ -190,8 +190,8 @@ function AbstractMCMC.step(
190190
initial_params === nothing ? rand(rng, T, d) :
191191
convert(AbstractVector{T}, initial_params)
192192
# Initialize the Cholesky factor of the covariance matrix.
193-
S = LowerTriangular(
194-
sampler.S === nothing ? diagm(0 => ones(T, d)) :
193+
S = LinearAlgebra.LowerTriangular(
194+
sampler.S === nothing ? LinearAlgebra.diagm(0 => ones(T, d)) :
195195
convert(AbstractMatrix{T}, sampler.S),
196196
)
197197

0 commit comments

Comments
 (0)