Skip to content

Commit

Permalink
Merge pull request #432 from mj-will/tweak-mcmcflowproposal
Browse files Browse the repository at this point in the history
MAINT: tweak MCMC flowproposal
  • Loading branch information
mj-will authored Oct 26, 2024
2 parents 99cd120 + 5bf6dcf commit 5351ede
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions nessai/experimental/proposal/mcmc/proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ def populate(
n_reject += 1 - accept
z_chain[i] = z_current
if self.n_accept is not None and n_accept.mean() > self.n_accept:
n_steps = i
break
else:
n_steps = self.n_steps
if self.n_accept is not None:
logger.warning(
(
Expand All @@ -153,15 +155,23 @@ def populate(
)
)

keep = n_accept > 0
logger.debug(f"Replacing {n_walkers - keep.sum()} walkers")
x_current = x_current[keep]

z_new_history = np.array(z_new_history)
z_chain = z_chain[:n_steps]
self.step.update_stats(
n_accept=n_accept.mean(),
n_reject=n_reject.mean(),
)

self.samples = self.convert_to_samples(x_current)

self.population_time += datetime.datetime.now() - st
if len(x_current) == 0:
logger.warning("No samples accepted!")
return

self.samples = self.convert_to_samples(x_current)
if self._plot_chain and plot:
self.plot_chain(z_chain)
if self._plot_pool and plot:
Expand Down
1 change: 1 addition & 0 deletions nessai/proposal/flowproposal/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class BaseFlowProposal(RejectionProposal):
behaviour to change without changing the keyword arguments.
"""
_FlowModelClass = FlowModel
alt_dist = None

def __init__(
self,
Expand Down

0 comments on commit 5351ede

Please sign in to comment.