rexfw.replicas package

Module contents

Replica classes which sample from a single PDF

class rexfw.replicas.Replica(name, state, pdf, sampler_class, sampler_params, proposers, output_folder, comm)[source]

Bases: object

_accept_buffered_proposal(request)[source]

If the information in the request object says so, accepts a proposal by setting the replica state to the buffered proposal and, in any case, appending the current replica state to the list of stored samples. Also syncs communication with master object and updates stored replica energies and the sample counter

Parameters:request (AcceptBufferedProposalRequest) – a request containing information whether the proposal should be accepted or not
_calculate_proposal(request)[source]

Calculates a proposal for a replica and using information given in request parameter

Parameters:request (ProposeRequest) – a request object containing the name of the replica to which a state will be proposed to and other information needed to calculate the proposal
Returns:a swap proposal state
Return type:depends on your application
_current_master = None
_do_nothing(request)[source]

Does nothing :-) Serves to synchronize communication with the master object

Parameters:request (DoNothingRequest) – a DoNothingRequest
_dump_energies()[source]

Updates files with replica energies and empties list of stored energies

_dump_samples(request)[source]

Writes samples and energies to a file, then empties list of stored samples in memory

Parameters:request (DumpSamplesRequest) – a request object containing information which samples to write
_increase_sample_counter()[source]

Guess what - increases the sample counter!

_pick_proposer(params)[source]

Picks proposer from this replicas’ proposer list

Parameters:params (ExchangeParams) – an object holding parameters defining the exchange to be performed
Returns:the proposer object which will be used to calculate the proposal
Return type:AbstractProposer
_propose(request)[source]

Calculates a swap proposal state and sends works and heats to master object

Parameters:request (ProposeRequest) – a request object containing information needed to calculate the proposal
_sample(request)[source]

Makes the sampler draw a sample, stores it, stores sampling statistics, increases the sample counter and updates the energy trace list

Parameters:request (SampleRequest) – a request object asking this replica to do all of the above
_send_get_state_and_energy_request(request)[source]

Sends a GetStateAndEnergyRequest to another replica given in the request parameter

Parameters:request (SendGetStateAndEnergyRequest) – a request object telling this replica which other replica to ask for its state and energy
_send_state_and_energy(request)[source]

Sends the current state and energy to another replica and makes it store them

Parameters:request (GetStateAndEnergyRequest) – a request object telling this replica which other replica to send state and energy to
_send_stats(request)[source]

Sends sampling statistics to master object. Also empties sampling stats list

Parameters:request (SendStatsRequest) – a request object asking this replica to do the above
_send_works_heats(proposal)[source]

Sends works and heats corresponding to a swap proposal to the master object

Parameters:proposal (depends on your application) – a state proposed for swapping
_setup_request_processing_table()[source]

Sets up a dictionary containing possible incoming request objects as keys and string templates for the function calls to process the request as values

_setup_sampler()[source]

Instantiates the sampler object from the sampler class given in rexfw.replicas.Replica.__init__()

_store_state_energy(request)[source]

Stores state and energy given in request parameter. Also sends a DoNothingRequest to the master object. This is neccessary to keep communication in sync

Parameters:request (StoreStateEnergyRequest) – a request object containing current state and energy of a different replica
_update_energy_trace()[source]

Updates the list of stored replica energies

energy

Returns the replica energy, that is, the negative log-probability of the replica’s PDF evaluated at the current state

Returns:the current replica energy
Return type:depends on your application
get_energy(state)[source]

Calculates replica energy (negative log-probability) for a given state

Parameters:state (depends on your application) – state for which to evaluate the negative log-probability of the replica’s PDF
process_request(request)[source]

Processes a request by looking up the corresponding function in the request processing table

Parameters:request (depends) – request object to process
state

Returns the current state of the replica (and thus the sampler)

Returns:current state of replica (and sampler)
Return type:depends on your application