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

Improve (hopefully) how HybridGibbs uses samplers state and history #503

Merged
merged 18 commits into from
Sep 10, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add comment on storing acc rate
  • Loading branch information
nabriis committed Sep 8, 2024
commit 01725b5ee9b18a1e5b41b6ef7ca0830d55f856e1
21 changes: 17 additions & 4 deletions cuqi/experimental/mcmc/_gibbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,31 @@ def step(self):
# TODO. Some samplers (NUTS) seem to require to run _pre_warmup before _pre_sample
self._pre_warmup_and_pre_sample_sampler(sampler)

# Take MCMC steps
# Allow for multiple sampling steps in each Gibbs step
for _ in range(self.num_sampling_steps[par_name]):
# Sampling step
acc = sampler.step()

# Store acceptance rate in sampler (mathcing behavior of Sampler class Sample method)
nabriis marked this conversation as resolved.
Show resolved Hide resolved
self.samplers[par_name]._acc.append(acc)
nabriis marked this conversation as resolved.
Show resolved Hide resolved

# Extract samples (Ensure even 1-dimensional samples are 1D arrays)
self.current_samples[par_name] = sampler.current_point.reshape(-1)

def tune(self, skip_len, idx):
""" Tune each of the samplers """
def tune(self, skip_len, update_count):
""" Tune each of the samplers in the Gibbs sampling scheme
amal-ghamdi marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
skip_len : int
Defines the number of steps in between tuning (i.e. the tuning interval).

update_count : int
The number of times tuning has been performed. Can be used for internal bookkeeping.

"""
for par_name in self.par_names:
self.samplers[par_name].tune(skip_len=skip_len, update_count=idx)
self.samplers[par_name].tune(skip_len=skip_len, update_count=update_count)

# ------------ Private methods ------------
def _initialize_samplers(self):
Expand Down