OBase

class omoment.OBase

Base class for moment calculating online estimators for univariate distributions.

Provides basic functionality such as:

  • equality and near-equality (for floats, is_close)

  • string representation

  • conversion objects to dictionaries or tuples (convenient for serialization)

  • combination of objects via addition

  • copying of objects

classmethod combine(first: OBase | Iterable[OBase], second: OBase | None = None) OBase

Either combine two objects together or merge an iterable of objects. The logic for correct combination has to be implemented in __add__ and __iadd__ of subclasses.

classmethod compute(*args, **kwargs)

Shortcut for initialization of an empty object and its update based on data.

copy() OBase

Create a new object with identical values.

is_close(other: OBase, rel_tol: float = 1e-09, abs_tol: float = 0.0) bool

Test of near equality: all values are compared with math.isclose and provided relative and absolute tolerance.

classmethod of_dict(d: Dict[str, Number]) OBase

Reconstruct the object from a dictionary (inverse of to_dict method).

classmethod of_tuple(t: Tuple[Number]) OBase

Reconstruct the object from a tuple (inverse of to_tuple method).

to_dict() Dict[str, Number]

Convert the object to dictionary, attribute names are used as keys (for JSON serialization etc.).

to_tuple() Tuple[Number]

Convert the values of attributes to a tuple.

abstract update(x: Number | ndarray | Series, *args, **kwargs) OBase

Update the object based on new data. Subclasses have to implement how to aggregate the new data.