firecrown.updatable.Updatable#

class firecrown.updatable.Updatable(parameter_prefix=None)[source]#

Bases: ABC

Abstract class Updatable is the base class for Updatable objects in Firecrown.

Any class in Firecrown that supports updating from a ParamsMap should inherit from Updatable. Such classes are expected to change state only in through their implementation of _update (including any other private methods used to implement _update). Other functions should not change the data of Updatable objects.

Parameters:

parameter_prefix (None | str) –

Public Methods:

__init__([parameter_prefix])

Updatable initialization.

__setattr__(key, value)

Set the attribute named key to the supplied value.

set_parameter(key, value)

Sets the parameter to the given value.

set_internal_parameter(key, value)

Assure this InternalParameter has not already been set, and then set it.

set_sampler_parameter(key, value)

Assure this SamplerParameter has not already been set, and then set it.

update(params)

Update self by calling to prepare for the next MCMC sample.

is_updated()

Determine if the object has been updated.

reset()

Reset the updatable.

required_parameters()

Returns a RequiredParameters object.

get_derived_parameters()

Returns a collection of derived parameters.

Private Methods:

_update(params)

Method for auxiliary updates to be made to an updatable.

_reset()

Abstract method implemented by all concrete classes to update self.

_required_parameters()

Return a RequiredParameters object containing the information for this class.

_get_derived_parameters()

Returns the derived parameters of an implementation.


__setattr__(key, value)[source]#

Set the attribute named key to the supplied value.

There is special handling for two types: SamplerParameter and InternalParameter.

We also keep track of all Updatable instance variables added, appending a reference to each to self._updatables as well as storing the attribute directly.

Parameters:
  • key (str) –

  • value (Any) –

Return type:

None

_get_derived_parameters()[source]#

Returns the derived parameters of an implementation.

Derived classes can override this, returning a DerivedParameterCollection containing the derived parameters for the class. The default implementation returns an empty DerivedParameterCollection.

Return type:

DerivedParameterCollection

_required_parameters()[source]#

Return a RequiredParameters object containing the information for this class.

This method can be overridden by subclasses to add additional parameters. The default implementation returns an empty RequiredParameters object. This is only implemented to allow

The base class implementation returns a list with all SamplerParameter objects properties.

Return type:

RequiredParameters

_reset()[source]#

Abstract method implemented by all concrete classes to update self.

Concrete classes must override this, resetting themselves.

The base class implementation does nothing.

Return type:

None

_update(params)[source]#

Method for auxiliary updates to be made to an updatable.

Do any updating other than calling update() on contained Updatable objects. Implement this method in a subclass only when it has something to do. If the supplied ParamsMap is lacking a required parameter, an implementation should raise a TypeError.

This default implementation does nothing.

Parameters:

params (ParamsMap) – a new set of parameter values

Return type:

None

final get_derived_parameters()[source]#

Returns a collection of derived parameters.

This occurs once per iteration of the statistical analysis. First call returns the DerivedParameterCollection, further calls return None.

Return type:

None | DerivedParameterCollection

is_updated()[source]#

Determine if the object has been updated.

Return True if the object is currently updated, and False if not. A default-constructed Updatable has not been updated. After update, but before reset, has been called the object is updated. After reset has been called, the object is not currently updated.

Return type:

bool

final required_parameters()[source]#

Returns a RequiredParameters object.

This object contains the information for all parameters defined in the implementing class, any additional parameter.

Return type:

RequiredParameters

final reset()[source]#

Reset the updatable.

Clean up self by clearing the _updated status and reseting all internals. We call the abstract method _reset to allow derived classes to clean up any additional internals.

Each MCMC framework connector should call this after handling an MCMC sample.

Return type:

None

set_internal_parameter(key, value)[source]#

Assure this InternalParameter has not already been set, and then set it.

Parameters:
Return type:

None

set_parameter(key, value)[source]#

Sets the parameter to the given value.

Assure this InternalParameter or SamplerParameter has not already been set, and then set it.

Parameters:
Return type:

None

set_sampler_parameter(key, value)[source]#

Assure this SamplerParameter has not already been set, and then set it.

Parameters:
Return type:

None

final update(params)[source]#

Update self by calling to prepare for the next MCMC sample.

We first update the values of sampler parameters from the values in params. An error will be raised if any of self’s sampler parameters can not be found in params or if any internal parameters are provided in params.

We then use the params to update each contained Updatable or UpdatableCollection object. The method _update() is called to give subclasses an opportunity to do any other preparation for the next MCMC sample.

Parameters:

params (ParamsMap) – new parameter values

Return type:

None