wepy.resampling.decisions.clone_merge module

class wepy.resampling.decisions.clone_merge.CloneMergeDecisionEnum(value)[source]

Bases: enum.Enum

Enum definition for cloning and merging decision values.”

  • NOTHING : 1

  • CLONE : 2

  • SQUASH : 3

  • KEEP_MERGE : 4

NOTHING = 1

Do nothing with the walker sample.

CLONE = 2

Clone the walker into multiple children equally splitting the weight.

SQUASH = 3

Destroy the walker sample value (state) and donate the sample weight to another KEEP_MERGE walker sample.

KEEP_MERGE = 4

Do nothing with the sample value (state) but squashed walkers will donate their weight to it.

class wepy.resampling.decisions.clone_merge.MultiCloneMergeDecision[source]

Bases: wepy.resampling.decisions.decision.Decision

Decision encoding cloning and merging decisions for weighted ensemble.

The decision records have in addition to the ‘decision_id’ a field called ‘target_idxs’. This field has differing interpretations depending on the ‘decision_id’.

For NOTHING and KEEP_MERGE it indicates the walker index to assign this sample to after resampling. In this sense the walker is merely a vessel for the propagation of the state and acts as a slot.

For SQUASH it indicates the walker that it’s weight will be given to, which must have a KEEP_MERGE record for it.

For CLONE it indicates the walker indices that clones of this one will be placed in. This field is variable length and the length corresponds to the number of clones.

ENUM

alias of wepy.resampling.decisions.clone_merge.CloneMergeDecisionEnum

DEFAULT_DECISION = 1

The default decision to choose.

FIELDS = ('decision_id', 'target_idxs')

The names of the fields that go into the decision record.

SHAPES = ((1,), Ellipsis)

Field data shapes.

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

Field data types.

RECORD_FIELDS = ('decision_id', 'target_idxs')

The fields that could be used in a reduced table-like representation.

classmethod default_decision()
classmethod enum_by_name(enum_name)

Get the enum name for an enum_value.

Parameters

enum_name (enum) –

Returns

enum_value

Return type

int

classmethod enum_by_value(enum_value)

Get the enum name for an enum_value.

Parameters

enum_value (int) –

Returns

enum_name

Return type

enum

classmethod enum_dict_by_name()

Get the decision enumeration as a dict mapping name to integer.

classmethod enum_dict_by_value()

Get the decision enumeration as a dict mapping integer to name.

classmethod field_dtypes()

Field data types.

classmethod field_names()

Names of the decision record fields.

classmethod field_shapes()

Field data shapes.

classmethod fields()

Specs for each field.

Returns

fields – Field specs each spec is of the form (name, shape, dtype).

Return type

list of tuples

classmethod parents(step)

Given a step of resampling records (for a single resampling step) returns the parents of the children of this step.

Parameters

step (list of decision records) – The decision records for a step of resampling for each walker.

Returns

walker_step_parents – For each element, the index of it in the list corresponds to the child index and the value of the element is the index of it’s parent before the decision action.

Return type

list of int

classmethod record_field_names()

The fields that could be used in a reduced table-like representation.

ANCESTOR_DECISION_IDS = (1, 4, 2)

Specify the enum values where their walker state sample value is passed on in the next generation, i.e. after performing the action.

classmethod record(enum_value, target_idxs)[source]

Generate a record for the enum_value and the other fields.

Parameters

enum_value (int) –

Returns

rec

Return type

dict of str: value

classmethod action(walkers, decisions)[source]

Perform the instructions for a set of resampling records on walkers.

The decisions are a collection of decision records which contain the decision value and the instruction values for a particular walker within its cohort (sample set).

The collection is organized as a list of lists. The outer list corresponds to the steps of resampling within a cycle.

The inner list is a list of decision records for a specific step of resampling, where the index of the decision record is the walker index.

Parameters
  • walkers (list of Walker objects) – The walkers you want to perform the decision instructions on.

  • decisions (list of list of decision records) – The decisions for each resampling step and their instructions to apply to the walkers.

Returns

resampled_walkers – The resampled walkers.

Return type

list of Walker objects

:raises NotImplementedError : abstract method: