wepy.walker module¶
Reference implementations for a general walker and walker state with utilities for cloning and merging walkers.
Wepy does not require that this or a subclass of this Walker or WalkerState is used and only that it is something that acts like it (duck typed).
The required attributes for the Walker interface are:
state : object implementing the WalkerState interface
weight : float
The weight attribute is simply a float and the proper normalization of weights among a weighted ensemble of walkers should be enforced by the resampler.
The clone, squash, and merge methods can be accessed by Decision classes for implementing cloning and merging. As can the module level split and keep_merge functions.
The WalkerState interface must have a method dict which returns a dictionary with string keys and arbitrary values.
Additionally the WalkerState should provide its own __getitem__ magic method for the accessor syntax, i.e. walker.state[‘positions’].
-
wepy.walker.
split
(walker, number=2)[source]¶ Split (AKA make multiple clones) of a single walker.
Creates multiple new walkers that have the same state as the given walker with weight evenly divided between them.
- Parameters
walker (object implementing the Walker interface) – The walker to split/clone
number (int) –
- The number of clones to make of the walker
(Default value = 2)
- Returns
cloned_walkers
- Return type
list of objects implementing the Walker interface
-
wepy.walker.
keep_merge
(walkers, keep_idx)[source]¶ Merge a set of walkers using the state of one of them.
- Parameters
walkers (list of objects implementing the Walker interface) – The walkers that will be merged together
keep_idx (int) – The index of the walker in the walkers list that will be used to set the state of the new merged walker.
- Returns
merged_walker
- Return type
object implementing the Walker interface
-
wepy.walker.
merge
(walkers)[source]¶ Merge this walker with another keeping the state of one of them and adding the weights.
The walker that has it’s state kept is a random choice weighted by the walkers weights.
- Parameters
walkers (list of objects implementing the Walker interface) – The walkers that will be merged together
- Returns
merged_walker
- Return type
object implementing the Walker interface
-
class
wepy.walker.
Walker
(state, weight)[source]¶ Bases:
object
Reference implementation of the Walker interface.
A container for:
state
weight
Constructor for Walker.
- Parameters
state (object implementing the WalkerState interface) –
weight (float) –
-
clone
(number=1)[source]¶ Clone this walker by making a copy with the same state and split the probability uniformly between clones.
The number is the increase in the number of walkers.
e.g. number=1 will return 2 walkers with the same state as this object but with probability split 50/50 between them
- Parameters
number (int) –
- Number of extra clones to make
(Default value = 1)
- Returns
cloned_walkers
- Return type
list of objects implementing the Walker interface
-
class
wepy.walker.
WalkerState
(**kwargs)[source]¶ Bases:
object
Reference implementation of the WalkerState interface.
Access all key-value pairs as a dictionary with the dict() method.
Access individual values using the accessor syntax similar to dictionaries:
>>> WalkerState(my_key='value')['my_key'] 'value'
Constructor for WalkerState.
All key-word arguments passed in will be set as the key-value pairs for the state.