Parameter#

class Parameter(invariant=<function Parameter.<lambda>>, error_message='Parameter value is not valid.')[source]#

Bases: object

A descriptor for validating and managing distribution parameters.

This class implements the descriptor protocol for managing access to attributes representing the parameters of a statistical distribution. It allows you to set the conditions (invariants) that the parameter value must satisfy.

Parameters:
  • invariant (Callable[[float], bool], optional) – A predicate function for validating parameter values. Defaults to lambda x: True.

  • error_message (str, optional) – An error message in case of failed validation. Defaults to “Parameter value is not valid.”.

Variables:
  • invariant (Callable[[float], bool]) – A function that checks if the parameter value is valid. Returns True if the value is correct, and False otherwise.

  • error_message (str) – An error message that is raised if the invariant is not satisfied.

  • public_name (str) – The name of the attribute as defined in the owner class.

  • private_name (str) – The name of the attribute used to store the value within an instance of the owner class.

Examples

class NormalDistribution(ContinuousDistribution):
    # Location parameter can be any number
    loc = Parameter()
    # Scale parameter must be a positive number
    scale = Parameter(invariant=lambda s: s > 0, error_message="Standard deviation (scale) must be positive.")