Skip to content

Commit d0ce010

Browse files
committedJul 3, 2023
use full matrix instead of lower cholesky in AdaptiveMHTuner
1 parent f640fbc commit d0ce010

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed
 

‎examples/dev-internal/transformed_example.jl

+12-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ rng = Philox4x()
1717
posterior = BAT.example_posterior()
1818

1919
my_result = @time BAT.bat_sample_impl(rng, posterior, TransformedMCMCSampling(pre_transform=PriorToGaussian(), nchains=4, nsteps=4*100000))
20-
my_samples = my_result.result
2120

22-
mh_result = @time BAT.bat_sample_impl(rng, posterior, TransformedMCMCSampling(tuning_alg=TransformedAdaptiveMHTuning(), pre_transform=PriorToGaussian(), nchains=4, nsteps=4*100000))
2321

24-
(;chain, tuner) = BAT.g_state
22+
23+
24+
density_notrafo = convert(BAT.AbstractMeasureOrDensity, posterior)
25+
density, trafo = BAT.transform_and_unshape(PriorToGaussian(), density_notrafo)
26+
27+
c = BAT._approx_cov(density)
28+
f = BAT.CustomTransform(Mul(c))
29+
30+
my_result = @time BAT.bat_sample_impl(rng, posterior, TransformedMCMCSampling(pre_transform=PriorToGaussian(), tuning_alg=TransformedAdaptiveMHTuning(), nchains=4, nsteps=4*100000, adaptive_transform=f))
31+
32+
my_samples = my_result.result
33+
2534

2635

2736
using Plots

‎src/samplers/transformed_mcmc/mcmc_tuning/mcmc_proposalcov_tuner.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function tuning_update!(tuner::TransformedProposalCovTuner, chain::MCMCIterator,
8585
transform = chain.f_transform
8686

8787

88-
#TODO AC: check with Oli
88+
#TODO AC: rename S_L to S, check with Oli
Has a conversation. Original line has a conversation.
8989
S_L = transform.A
9090
Σ_old = S_L
9191

@@ -113,8 +113,8 @@ function tuning_update!(tuner::TransformedProposalCovTuner, chain::MCMCIterator,
113113

114114
Σ_new = new_Σ_unscal * tuner.scale
115115
#TODO AC: check
116-
S = cholesky(Positive, Σ_new)
117-
chain.f_transform = Mul(S.L)
116+
#S = cholesky(Positive, Σ_new)
117+
chain.f_transform = Mul(Σ_new)
118118
tuner.iteration += 1
119119

120120
nothing
@@ -133,7 +133,7 @@ tuning_callback(::TransformedProposalCovTuner) = nop_func
133133
function tune_mcmc_transform!!(
134134
rng::AbstractRNG,
135135
tuner::TransformedProposalCovTuner,
136-
transform::Mul{<:LowerTriangular}, #AffineMaps.AbstractAffineMap,#{<:typeof(*), <:LowerTriangular{<:Real}},
136+
transform::Any, #AffineMaps.AbstractAffineMap,#{<:typeof(*), <:LowerTriangular{<:Real}},
137137
p_accept::Real,
138138
z_proposed::Vector{<:Float64}, #TODO: use DensitySamples instead
139139
z_current::Vector{<:Float64},

‎src/transforms/adaptive_transform.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function init_adaptive_transform(
1212
adaptive_transform::CustomTransform,
1313
density
1414
)
15-
return adaptive_transform
15+
return adaptive_transform.f
1616
end
1717

1818

0 commit comments

Comments
 (0)
Please sign in to comment.