lale.lib.rasl.monoid module

class lale.lib.rasl.monoid.Monoid[source]

Bases: ABC

Data that can be combined in an associative way. See :class:MonoidFactory for ways to create/unpack a given monoid.

abstract combine(other: _SelfType) _SelfType[source]

Combines this monoid instance with another, producing a result. This operation must be observationally associative, satisfying x.from_monoid(a.combine(b.combine(c))) == x.from_monoid(a.combine(b).combine(c))) where x is the instance of :class:MonoidFactory that created these instances.

property is_absorbing

A monoid value x is absorbing if for all y, x.combine(y) == x. This can help stop training early for monoids with learned coefficients.

class lale.lib.rasl.monoid.MonoidFactory(*args, **kwargs)[source]

Bases: Generic[_InputType_contra, _OutputType_co, _M], Protocol

This protocol determines if a class supports creating a monoid and using it to support associative computation. Due to the runtime_checkable decorator, isinstance(obj, MonoidFactory) will succeed if the object has the requisite methods, even if it does not have this protocol as a base class.

abstract from_monoid(monoid: _M) _OutputType_co[source]

Given the monoid instance, return the appropriate type of output. This method may also modify self based on the monoid instance.

abstract to_monoid(batch: _InputType_contra) _M[source]

Create a monoid instance representing the input data

class lale.lib.rasl.monoid.MonoidableOperator(*args, **kwargs)[source]

Bases: MonoidFactory[Any, None, _M], Protocol

This is a useful base class for operator implementations that support associative (monoid-based) fit. Given the implementation supplied :class:MonoidFactory methods, this class provides default :method:partial_fit and :method:fit implementations.

fit(X, y=None)[source]
partial_fit(X, y=None)[source]