binf package

Module contents

Future Binf stuff goes here. Currently, the major focus is to redesign the Universe and access to atoms, molecules etc. Also Posterior and BinfSampler will be redesigned at some point.

class binf.AbstractBinfNamedCallable(name)[source]

Bases: object

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 35
_abc_registry = <_weakrefset.WeakSet object>
_check_differentiability(**variables)[source]

Checks whether this object can be differentiated w.r.t. specific variables

_complete_variables(variables)[source]

If needed, updates the dictionary of variables passed to this object when calling evaluate() with values for fixed variables

_delete_variable(name)[source]

Removes a variable from the set of registed variables

Parameters:name (str) – name of the variable to be removed
_evaluate(**variables)[source]

In this method, the actual function evaluation takes place

The variables argument holds values for both fixed and unfixed variables; the implementation in this method thus does not depend on whether the set of originally passed variables equals the set of original variables

Parameters:**variables – list of variable name / value pairs
_evaluate_gradient(**variables)[source]

In this method, the actual gradient evaluation takes place

The variables argument holds values for both fixed and unfixed variables; the implementation in this method thus does not depend on whether the set of originally passed variables equals the set of original variables

Parameters:**variables – list of variable name / value pairs
_get_variables_intersection(test_variables)[source]

Returns the intersection of the variables stored in the argument with the set of currently registered variables

_register_variable(name, differentiable=False)[source]

Registers a variable so that later on it can be fixed or checked whether it has been passed to the __call__ method

Parameters:
  • name (str) – name of the new variable
  • differentiable (bool) – True for variables you might at one point want to take the gradient w.r.t. This is probably deprecated.
_set_original_variables()[source]

Stores the original set of named variables this object takes

differentiable_variables

Returns the set of currently registered variables this object implements the gradient w.r.t

Returns:set of variables this object can be differentiated w.r.t.
Return type:set
fix_variables(**fixed_vars)[source]

Sets (‘fixes’) specific variables to values given as keyword arguments by removing these variables from the list of registered variables and registering corresponding parameters to this object.

gradient(**variables)[source]

This function will be called from outside to evaluate the gradient of the function (or a related one, e.g., log-probability) represented by this object

Parameters:**variables – list of variable name / value pairs
Returns:gradient of the function represented by this object
Return type:numpy.ndarray
name

Returns the name of this object

update_var_param_types(**values)[source]

Updates the dictionary holding the types of registered variables

var_param_types

Empty by default, but for a conditional PDF to be built, one has to add AbstractParameter subclasses suiting the variables.

variables

Returns the set of currently registed variables

Returns:set of currently registered variables
Return type:set
class binf.ArrayParameter(value=None, name=None, base=None)[source]

Bases: csb.statistics.pdf.parameterized.AbstractParameter

NULL = None
_add_derived(parameter)
_compute(base_value)

Compute a new value for the current parameter given the value of a base parameter (assuming self.is_virtual). By default this returns the value of the base parameter (i.e. self just inherits the value of its base untouched).

_ensure_consistency()

Make sure that the current value is up to date. If it isn’t, trigger a real-time cascaded update following the path from the nearest consistent base down to self. Also mark all nodes consistent in the course of doing this update.

_invalidate()

Mark self and its virtual children as inconsistent

_nearest_consistent_base()

Compute and return the path from self to the nearest consistent base parameter.

@return: path, leaf-to-root @rtype: list of L{AbstractParameter}

_recompute(consistent=True)

If self is virtual, force the current parameter to recompute itself from its immediate base. This operation has no side effects and does not propagate.

_recompute_derivatives()

Recompute all derived parameters starting from self and mark them consistent.

_set_base(parameter)
_update(value)

Overwrite the current value of the parameter. This triggers an abstract (custom) validation hook, but has no side effects (i.e. it doesn’t propagate!)

_validate(value)[source]

Validate and sanitize the specified value before assignment. @return: sanitized value

@raise ParameterValueError: on invalid value

bind_to(parameter)

Bind the current parameter to a base parameter. This converts the current parameter to a virtual one, whose value will get implicitly updated to be consistent with its base.

Note that virtual parameters must have exactly one base; computing a parameter from multiple bases is not allowed. Cycles are also not allowed; the topology must always stay a tree with a non-virtual parameter at the root.

@param parameter: base parameter to compute this instance from @param parameter: L{AbstractParameter}

@raise ParameterizationError: if this parameter is already virtual @raise ParameterizationError: on attempt to create a circular dependency

find_base_parameter()

Find and return the non-virtual base parameter that is the root of the current hierarchy. If self is not virtual, return self.

@return: base parameter @rtype: L{AbstractParameter}

is_virtual

True if this parameter is virtual (computed)

name

Parameter name

set(value)

Update the value of this parameter. This is not possible for virtual parameters.

@param value: new value @type value: object

@raise ParameterizationError: if this is a virtual parameter @raise ParameterValueError: on invalid value

value

Parameter value (guaranteed to be up to date)