Class markov::Walker
Walker
is an abstract base class for configuration space explorers
A walker container stores its current state and cost and has pointers to a model and random number generator to make steps. It is specifically designed to allow copy assignment (assuming the Model::State_T does), such that it can be duplicated in population markovs. The Walker provides a base implementation of the step function, which
- proposes a random new state,
- computes the cost difference,
- invokes a pure virtual method to decide whether to accept, and
- modifies the internal state if true is returned.
From this we can implement a RandomWalker
by always returning true and a Metropolis
walker by returning the Boltzmann acceptance rate.
markov::Metropolis
Inheritance
Constructors
Walker()
The rng
and model
must be set before the object can be used. cost
is only intialized after a call to init()
Declaration
markov::Walker<Model>::Walker()
Methods
init()
Must be called after the rng_
and model_
have been set. It initializes the walker to a random state and precomputes its current cost.
Note
This is typically the only direct call to calculate_cost
; from here the current cost_
is updated from the computed difference at each step.
Declaration
virtual void markov::Walker<Model>::init()
init()
Must be called after the model_
has been set. Initializes the walker to a specific state and precomputes its current cost.
Declaration
virtual void markov::Walker<Model>::init(const typename Model::State_T&state)
accept()
Implementations of the walker interface must provide a method to decide which steps to accept/reject. Currently this is only based on cost_difference
, but the state or transition could be added.
Declaration
virtual bool markov::Walker<Model>::accept(const typename Model::Cost_T&cost_difference)=0
verify_cost_difference()
Verify cost difference does a sanity check on the calculated energy difference by evaluating the whole cost function and comparing it to the cached value. This is very costly and happens only in DEBUG builds, not in RELEASE builds.
Note
An exception thrown by this sanity check means that the implementations of calculate_cost
and calculate_cost_difference
are not compatible (or, less likely, the model or state have been modified since the total cost was cached).
Declaration
bool markov::Walker<Model>::verify_cost_difference(const typename Model::Cost_T&returned_difference)
apply_transition()
For models derived from model::FacedGraphModel, an extra parameter for a cost object is necessary to communicate cached calculations.
Declaration
std::enable_if<std::is_base_of<model::FacedGraphModel<TS, TT>, TM>::value, void>::type markov::Walker<Model>::apply_transition(const typename Model::Transition_T&transition, typename Model::Cost_T cost_diff)
apply_transition()
For all other models, no extra cost parameter is needed.
Declaration
std::enable_if<!std::is_base_of<model::FacedGraphModel<TS, TT>, TM>::value, void>::type markov::Walker<Model>::apply_transition(const typename Model::Transition_T&transition, typename Model::Cost_T cost_diff)
make_sweep()
For models derived from markov::LinearSweepModel, let the model handle the entire sweep.
Declaration
std::enable_if<std::is_base_of<markov::LinearSweepModel<TS>, TM>::value, void>::type markov::Walker<Model>::make_sweep()
make_sweep()
For models with a 'size_t' transition type, do an ordered sweep.
Declaration
std::enable_if<std::is_same<TT, size_t>::value&&!std::is_base_of<markov::LinearSweepModel<TS>, TM>::value, void>::type markov::Walker<Model>::make_sweep()
make_sweep()
For any other transition type, do a random sweep.
Declaration
std::enable_if<!std::is_same<TT, size_t>::value&&!std::is_base_of<markov::LinearSweepModel<TS>, TM>::value, void>::type markov::Walker<Model>::make_sweep()
make_sweeps()
Perform multiple sweeps.
Declaration
void markov::Walker<Model>::make_sweeps(size_t n_sweeps)
make_step()
Perform a single (random) step.
Declaration
void markov::Walker<Model>::make_step()
attempt_transition()
Attempt the given transition and apply it if accepted by the walker condition. For models derived from model::FacedGraphModel, an extra parameter for a cost object is necessary to communicate cached calculations.
Declaration
std::enable_if<std::is_base_of<model::FacedGraphModel<TS, TT>, TM>::value, typename Model::Cost_T>::type markov::Walker<Model>::attempt_transition(const typename Model::Transition_T&transition)
attempt_transition()
Attempt the given transition and apply it if accepted by the walker condition. For all other models, no extra cost parameter is needed.
Declaration
std::enable_if<!std::is_base_of<model::FacedGraphModel<TS, TT>, TM>::value, typename Model::Cost_T>::type markov::Walker<Model>::attempt_transition(const typename Model::Transition_T&transition)
cost()
Return the cost of the current state (cached within the walker).
Declaration
const Model::Cost_T&markov::Walker<Model>::cost() const
state()
Return the current state of this walker.
Declaration
const Model::State_T&markov::Walker<Model>::state() const
set_model()
Provide a pointer to the (non-owned) model to use for cost calculations and proposing new steps.
Declaration
void markov::Walker<Model>::set_model(const Model *model)
set_rng()
Provide a pointer to the (non-owned) random number generator to use. Multithreading must either be handled via mutex within the random number generator or by the calling class.
Declaration
void markov::Walker<Model>::set_rng(utils::RandomGenerator *rng)
model()
Return a constant reference to the model being used.
Declaration
const Model&markov::Walker<Model>::model()
rng()
Return a reference to the random number generator to use.
Declaration
utils::RandomGenerator&markov::Walker<Model>::rng()
swap_state()
Swap the state with another instance.
This exchanges the internal markov::State
and the associated (cached) cost_
with another metropolis instance.
Declaration
void markov::Walker<Model>::swap_state(Walker *other)
get_evaluation_counter()
Declaration
solver::EvaluationCounter markov::Walker<Model>::get_evaluation_counter()
reset_evaluation_counter()
Declaration
void markov::Walker<Model>::reset_evaluation_counter()
save_lowest()
Unconditionally store the current state as the lowest (during init)
Declaration
void markov::Walker<Model>::save_lowest()
check_lowest()
Save the current state as new best if its cost is lower than the previous best.
Declaration
void markov::Walker<Model>::check_lowest()
get_lowest_cost()
Declaration
Model::Cost_T markov::Walker<Model>::get_lowest_cost() const
apply_scale_factor()
Declaration
void markov::Walker<Model>::apply_scale_factor(double scale_factor)
get_lowest_state()
Declaration
const Model::State_T&markov::Walker<Model>::get_lowest_state() const
memory_estimate()
Estimate memory consumption using model parameters.
Declaration
static size_t markov::Walker<Model>::memory_estimate(const Model&model)
compare()
Declaration
static bool markov::Walker<Model>::compare(const Walker<Model>&w1, const Walker<Model>&w2)