Skip to content

Commit

Permalink
Fix Blackjax SMC integration (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciguaran authored Oct 7, 2024
1 parent e96d07f commit 7815e5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 12 additions & 7 deletions pymc_experimental/inference/smc/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import jax.numpy as jnp
import numpy as np

from blackjax.smc import extend_params
from blackjax.smc.resampling import systematic
from pymc import draw, modelcontext, to_inference_data
from pymc.backends import NDArray
Expand Down Expand Up @@ -126,16 +127,20 @@ def sample_smc_blackjax(

if kernel == "HMC":
mcmc_kernel = blackjax.mcmc.hmc
mcmc_parameters = dict(
step_size=inner_kernel_params["step_size"],
inverse_mass_matrix=jnp.eye(posterior_dimensions),
num_integration_steps=inner_kernel_params["integration_steps"],
mcmc_parameters = extend_params(
dict(
step_size=inner_kernel_params["step_size"],
inverse_mass_matrix=jnp.eye(posterior_dimensions),
num_integration_steps=inner_kernel_params["integration_steps"],
)
)
elif kernel == "NUTS":
mcmc_kernel = blackjax.mcmc.nuts
mcmc_parameters = dict(
step_size=inner_kernel_params["step_size"],
inverse_mass_matrix=jnp.eye(posterior_dimensions),
mcmc_parameters = extend_params(
dict(
step_size=inner_kernel_params["step_size"],
inverse_mass_matrix=jnp.eye(posterior_dimensions),
)
)
else:
raise ValueError(f"Invalid kernel {kernel}, valid options are 'HMC' and 'NUTS'")
Expand Down
1 change: 0 additions & 1 deletion tests/test_blackjax_smc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def fast_model():
("NUTS", False, {"step_size": 0.1}),
],
)
@pytest.mark.xfail(reason="Still need to investigate")
def test_sample_smc_blackjax(kernel, check_for_integration_steps, inner_kernel_params):
"""
When running the two gaussians model
Expand Down

0 comments on commit 7815e5b

Please sign in to comment.