binf.samplers package

Submodules

binf.samplers.gibbs module

Gibbs sampler implementations

class binf.samplers.gibbs.GibbsSampler(pdf, state, subsamplers)[source]

Bases: csb.statistics.samplers.mc.singlechain.AbstractSingleChainMC

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 36
_abc_registry = <_weakrefset.WeakSet object>
_accept_proposal(proposal_state)

Accept the proposal state by setting it as the current state of the sampler object

@param proposal_state: The proposal state @type proposal_state: L{State}

_calc_pacc()[source]

Not applicable

_checkstate(state)[source]

Checks whether the state is a dict

_propose()[source]

Not applicable

_setup_conditional_pdfs()[source]

Sets up the conditional PDFs from the full PDF

_update_conditional_pdf_params()[source]

Updates parameters of the conditional PDFs to values set in this object’s PDF

_update_state(**variables)[source]

Updates this object’s state’s variables to new values

_update_statistics(accepted)

Update the sampling statistics.

@param accepted: Whether or not the proposal state has been accepted @type accepted: boolean

_update_subsampler_states()[source]

Updates subsampler states, e.g., after a replica exchange swap

acceptance_rate

Acceptance rate.

energy

Negative log-likelihood of the current state. @rtype: float

last_draw_stats

Returns information about most recent move for each subsampler

Returns:information about most recent move for each subsampler
Return type:dict
last_move_accepted

Information whether the last MC move was accepted or not.

pdf

Returns the PDF object this sampler samples from

Returns:PDF object
Return type:AbstractBinfPDF
sample()[source]

Performs one iteration of the Gibbs sampling scheme

Returns:a state
Return type:BinfState
sampling_stats

Sampling statistics, consisting of sampler statistics of the subsamplers

Returns:all subsampler sampling statistics
Return type:OrderedDict
state

Returns the current state of this sampler

Returns:current state
Return type:BinfState
subsamplers

Returns the subsamplers the Gibbs sampler iterates over

Returns:subsamplers for each variable
Return type:dict
temperature
update_samplers(**samplers)[source]

Updates the subsamplers

binf.samplers.hmc module

HMC sampler implementations

class binf.samplers.hmc.HMCSampleStats(accepted, stepsize)

Bases: tuple

_asdict()

Return a new OrderedDict which maps field names to their values

_fields = ('accepted', 'stepsize')
classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)

Make a new HMCSampleStats object from a sequence or iterable

_replace(**kwds)

Return a new HMCSampleStats object replacing specified fields with new values

accepted

Alias for field number 0

count(value) → integer -- return number of occurrences of value
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

stepsize

Alias for field number 1

class binf.samplers.hmc.HMCSampler(pdf, state, timestep, nsteps, timestep_adaption_limit=0, adaption_uprate=1.05, adaption_downrate=0.95, variable_name=None)[source]

Bases: object

_adapt_timestep()[source]

Increases / decreasese the leap frog time step depending on whether the last move has been rejected / accepted.

_copy_state(state)[source]

Copies a state

Parameters:state (numpy.ndarray) – variable value to copy
_leapfrog(q, p, timestep, nsteps)[source]

Performs leap frog integration of Hamiltonian dynamics guided by the gradient of the negative log-probability

Parameters:
  • q (numpy.ndarray) – initial ‘position’
  • p (numpy.ndarray) – initial ‘momentum’
  • timestep (float) – integration time step
  • nsteps (int) – # of integration steps
Returns:

‘position’ and ‘momentum’ at the end of the approximated MD trajectory

Return type:

(numpy.ndarray, numpy.ndarray)

acceptance_rate
last_draw_stats

Returns information about the most recently performed move

This is usually used by a replica exchange scheme to log sampling statistics.

Returns:whether the last move has been accepted and the current time step in the shape of a named tuple in a dictionary. This contrived is needed for Gibbs sampling / replica exchange statistics.
Return type:dict
last_move_accepted

Returns whether the last move has been accepted or not

Returns:whether the last move has been accepted or not
Return type:bool
sample()[source]

Draws a random sample

Returns:a sample
Return type:numpy.ndarray
variable_name

Returns the name of the variable this sampler is supposed to draw random samples from

Returns:variable name
Return type:str

Module contents

This module contains implementations of various MCMC samplers

class binf.samplers.BinfState(variables={}, momenta={})[source]

Bases: object

momenta

I currently don’t use this

update_momenta(**momenta)[source]

I currently don’t use this

update_variables(**variables)[source]

Updates variables

Parameters:**variables (dict) – named and typed variables to update this state with
variables

Returns a copy (!) of the variables and their values held by this state

Returns:copy of variables
Return type:dict