Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt fit_hmc to work with latest blackjax version #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sts_jax/structural_time_series/learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ def unnorm_log_pos(_unc_params):
return lp

# Initialize the HMC sampler using window_adaptations
warmup = blackjax.window_adaptation(blackjax.nuts, unnorm_log_pos, num_steps=warmup_steps, progress_bar=verbose)
warmup = blackjax.window_adaptation(blackjax.nuts, unnorm_log_pos, progress_bar=verbose)
init_key, key = jr.split(key)
hmc_initial_state, hmc_kernel, _ = warmup.run(init_key, initial_unc_params)
(hmc_initial_state, parameters), _ = warmup.run(init_key, initial_unc_params, num_steps=warmup_steps)
hmc_kernel = blackjax.nuts(unnorm_log_pos, **parameters).step

@jit
def hmc_step(hmc_state, step_key):
Expand All @@ -180,7 +181,7 @@ def hmc_step(hmc_state, step_key):
for _ in pbar:
step_key, key = jr.split(key)
hmc_state, params = hmc_step(hmc_state, step_key)
log_probs.append(-hmc_state.potential_energy)
log_probs.append(-hmc_state.logdensity)
samples.append(params)

# Combine the samples into a single pytree
Expand Down