wepy.resampling.resamplers.clone_merge module

class wepy.resampling.resamplers.clone_merge.CloneMergeResampler(pmin=1e-12, pmax=0.1, min_num_walkers=Ellipsis, max_num_walkers=Ellipsis, **kwargs)[source]

Bases: wepy.resampling.resamplers.resampler.Resampler

Abstract base class for resamplers using the clone-merge decision class.

Provides some common functionality including handling minimum and maximum numbers of walkers and checking constraints on that.

The ‘assign_clones’ method is a convenience method for generating decision records from two intermediate representation data structures which are convenient to produce: merge_groups and walker_clone_nums. See the docstring for more details on the format of these.

Constructor for CloneMegerResampler class.

Parameters
  • pmin (float) – The minimum probability any walker is allowed to have.

  • pmax (float) – The maximum probability any walker is allowed to have.

DECISION

alias of wepy.resampling.decisions.clone_merge.MultiCloneMergeDecision

RESAMPLING_FIELDS = ('decision_id', 'target_idxs', 'step_idx', 'walker_idx')

String names of fields produced in this record group.

Resampling records are typically used to report on the details of how walkers are resampled for a given resampling step.

Warning

This is a critical function of many other components of the wepy framework and probably shouldn’t be altered by most developers.

Thi is where the information about cloning and merging of walkers is given. Seeing as this is a most of the value proposition of wepy as a tool getting rid of it will render most of the framework useless.

But sticking to the ‘loosely coupled, tightly integrated’ mantra you are free to modify these fields. This would be useful for implementing resampling strategies that do not follow basic cloning and merging. Just beware, that most of the lineage based analysis will be broken without implementing a new Decision class.

RESAMPLING_SHAPES = ((1,), Ellipsis, (1,), (1,))

Numpy-style shapes of all fields produced in records.

There should be the same number of elements as there are in the corresponding ‘FIELDS’ class constant.

Each entry should either be:

  1. A tuple of ints that specify the shape of the field element array.

  2. Ellipsis, indicating that the field is variable length and limited to being a rank one array (e.g. (3,) or (1,)).

  3. None, indicating that the first instance of this field will not be known until runtime. Any field that is returned by a record producing method will automatically interpreted as None if not specified here.

Note that the shapes must be tuple and not simple integers for rank-1 arrays.

Option B will result in the special h5py datatype ‘vlen’ and should not be used for large datasets for efficiency reasons.

RESAMPLING_DTYPES = (<class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>)

Specifies the numpy dtypes to be used for records.

There should be the same number of elements as there are in the corresponding ‘FIELDS’ class constant.

Each entry should either be:

  1. A numpy.dtype object.

  1. None, indicating that the first instance of this field will not be known until runtime. Any field that is returned by a record producing method will automatically interpreted as None if not specified here.

RESAMPLING_RECORD_FIELDS = ('decision_id', 'target_idxs', 'step_idx', 'walker_idx')

Optional, names of fields to be selected for truncated representation of the record group.

These entries should be strings that are previously contained in the ‘FIELDS’ class constant.

While strictly no constraints on to which fields can be added here you should only choose those fields whose features could fit into a plaintext csv or similar format.

property pmin
property pmax
_init_walker_actions(n_walkers)[source]

Returns a list of default resampling records for a single resampling step.

Parameters

n_walkers (int) – The number of walkers to generate records for

Returns

decision_records – A list of default decision records for one step of resampling.

Return type

list of dict of str: value

_check_resampled_walkers(resampled_walkers)[source]

Check constraints on resampled walkers.

Raises errors when constraints are violated.

Parameters

resampled_walkers (list of Walker objects) –

assign_clones(merge_groups, walker_clone_nums)[source]

Convert two convenient data structures to a list of almost normalized resampling records.

The two data structures are merge_groups and walker_clone_nums and are convenient to make.

Each is a list with number of elements equal to the number of walkers that resampling will act on.

Each element of the merge_groups is a list-like of integers indicating the indices of the walkers that will be merged into this one (i.e. squashed). A non-empty collection indicates a KEEP_MERGE decision.

Each element of the walker_clone_nums is simply an integer specifying how many clones to make of this walker.

These data structures simply declare requirements on what the actual decision records must achieve. The actual placement of walkers in slots (indices) is unspecified and immaterial.

Parameters
  • merge_groups (list of list of int) – The specification of which walkers will be squashed and merged.

  • walker_clone_nums (list of int) – The number of clones to make for each walker.

Returns

walker_actions – List of resampling record like dictionaries. These are not completely normalized for consumption by reporters, since they don’t have the right list-like wrappers.

Return type

list of dict of str: values

CYCLE_DTYPES = (<class 'int'>, <class 'int'>)

Data types of the cycle fields

CYCLE_FIELDS = ('step_idx', 'walker_idx')

The fields that get added to the decision record for all resampling records. This places a record within a single destructured listing of records for a single cycle of resampling using the step and walker index.

CYCLE_RECORD_FIELDS = ('step_idx', 'walker_idx')

Optional, names of fields to be selected for truncated representation of the record group.

CYCLE_SHAPES = ((1,), (1,))

Data shapes of the cycle fields.

DEBUG_MODES = (True, False)
RESAMPLER_DTYPES = ()

Specifies the numpy dtypes to be used for records.

There should be the same number of elements as there are in the corresponding ‘FIELDS’ class constant.

Each entry should either be:

  1. A numpy.dtype object.

  1. None, indicating that the first instance of this field will not be known until runtime. Any field that is returned by a record producing method will automatically interpreted as None if not specified here.

RESAMPLER_FIELDS = ()

String names of fields produced in this record group.

Resampler records are typically used to report on changes in the state of the resampler.

Notes

These fields are not critical to the proper functioning of the rest of the wepy framework and can be modified freely.

However, reporters specific to this resampler probably will make use of these records.

RESAMPLER_RECORD_FIELDS = ()

Optional, names of fields to be selected for truncated representation of the record group.

These entries should be strings that are previously contained in the ‘FIELDS’ class constant.

While strictly no constraints on to which fields can be added here you should only choose those fields whose features could fit into a plaintext csv or similar format.

RESAMPLER_SHAPES = ()

Numpy-style shapes of all fields produced in records.

There should be the same number of elements as there are in the corresponding ‘FIELDS’ class constant.

Each entry should either be:

  1. A tuple of ints that specify the shape of the field element array.

  2. Ellipsis, indicating that the field is variable length and limited to being a rank one array (e.g. (3,) or (1,)).

  3. None, indicating that the first instance of this field will not be known until runtime. Any field that is returned by a record producing method will automatically interpreted as None if not specified here.

Note that the shapes must be tuple and not simple integers for rank-1 arrays.

Option B will result in the special h5py datatype ‘vlen’ and should not be used for large datasets for efficiency reasons.

_resample_cleanup(**kwargs)

Common cleanup stuff for resamplers.

Unsets the number of walkers for this round of resampling.

_resample_init(walkers, **kwargs)

Common initialization stuff for resamplers.

Sets the number of walkers in this round of resampling.

Parameters

walkers (list of Walker objects) –

_set_resampling_num_walkers(num_walkers)

Sets the concrete number of walkers constraints given a number of walkers and the settings for max and min.

Parameters

num_walkers (int) –

_unset_resampling_num_walkers()
debug_off()
debug_on()
property decision

The decision class for this resampler.

property is_debug_on
max_num_walkers()

” Get the max number of walkers allowed currently

property max_num_walkers_setting

The specification for the maximum number of walkers for the resampler.

min_num_walkers()

” Get the min number of walkers allowed currently

property min_num_walkers_setting

The specification for the minimum number of walkers for the resampler.

resample(walkers, debug_mode=False)

Perform resampling on the set of walkers.

Parameters
  • walkers (list of Walker objects) – The walkers that are to be resampled.

  • debug_mode (bool) – Expert mode debugging setting, only forif you know exactly what you are doing.

Returns

  • resampled_walkers (list of Walker objects) – The set of resampled walkers

  • resampling_data (list of dict of str: value) – A list of destructured resampling records from this round of resampling.

  • resampler_data (list of dict of str: value) – A list of records recording how the state of the resampler was updated.

resampler_field_dtypes()

Access the class level DTYPES constant for this record group.

resampler_field_names()

Access the class level FIELDS constant for this record group.

resampler_field_shapes()

Access the class level SHAPES constant for this record group.

resampler_fields()

Returns a list of zipped field specs.

Returns

record_specs – A list of the specs for each field, a spec is a tuple of type (field_name, shape_spec, dtype_spec)

Return type

list of tuple

resampler_record_field_names()

Access the class level RECORD_FIELDS constant for this record group.

resampling_field_dtypes()

Access the class level DTYPES constant for this record group.

resampling_field_names()

Access the class level FIELDS constant for this record group.

resampling_field_shapes()

Access the class level SHAPES constant for this record group.

resampling_fields()

Returns a list of zipped field specs.

Returns

record_specs – A list of the specs for each field, a spec is a tuple of type (field_name, shape_spec, dtype_spec)

Return type

list of tuple

resampling_record_field_names()

Access the class level RECORD_FIELDS constant for this record group.

set_debug_mode(mode)
Parameters

mode