Skip to content

Commit

Permalink
Added burn and thin properties to MarkovChain which raises an error w…
Browse files Browse the repository at this point in the history
…hen they are accessed or set.
  • Loading branch information
C-bowman committed Dec 3, 2023
1 parent 6d68488 commit bfcefde
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions inference/mcmc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,30 @@ def __plot_checks(self, burn: int, thin: int, plot_type: str):
\r>> Number of samples after burn / thin is {reduced_length}.
"""
)

@property
def burn(self):
self.__burn_thin_error()

@burn.setter
def burn(self, val):
self.__burn_thin_error()

@property
def thin(self):
self.__burn_thin_error()

@thin.setter
def thin(self, val):
self.__burn_thin_error()

def __burn_thin_error(self):
raise AttributeError(
f"""\n
\r[ {self.__class__.__name__} error ]
\r>> The 'burn' and 'thin' instance attributes of inference-tools
\r>> mcmc samplers were removed in version 0.13.0. Burn and thin
\r>> values should now be passed explicitly to any methods with
\r>> 'burn' and 'thin' keyword arguments.
"""
)
15 changes: 15 additions & 0 deletions tests/mcmc/test_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,18 @@ def test_hamiltonian_chain_plots():
chain.trace_plot(burn=200)
with pytest.raises(ValueError):
chain.matrix_plot(thin=500)


def test_hamiltonian_chain_burn_thin_error():
posterior = ToroidalGaussian()
chain = HamiltonianChain(
posterior=posterior, start=array([1, 0.1, 0.1]), grad=posterior.gradient
)
with pytest.raises(AttributeError):
chain.burn = 10
with pytest.raises(AttributeError):
burn = chain.burn
with pytest.raises(AttributeError):
chain.thin = 5
with pytest.raises(AttributeError):
thin = chain.thin

0 comments on commit bfcefde

Please sign in to comment.