Custom Transformations (Custom)

The Custom class allows you to specify your own transformations that operate on a single observation sequence. This allows your own transformations to be seamlessly combined with others provided by Sequentia, by using the Compose class.

API reference

class sequentia.preprocessing.Custom(func, name=None, desc=None)[source]

Apply a custom transformation to the input observation sequence(s).

Parameters
func: callable

A lambda or function that specifies the transformation that should be applied to a single observation sequence.

name: str

Name of the transformation.

desc: str

Description of the transformation.

Examples

>>> # Create some sample data
>>> X = [np.random.random((10 * i, 3)) for i in range(1, 4)]
>>> # Apply a custom transformation
>>> X = Custom(lambda x: x**2, name='Square', desc='Square observations element-wise')(X)
transform(x)

Applies the transformation to a single observation sequence.

Parameters
X: numpy.ndarray (float)

An individual observation sequence.

Returns
transformed:class:numpy:numpy.ndarray (float)

The transformed input observation sequence.

__call__(X, validate=True)

Applies the transformation to the observation sequence(s).

Parameters
X: numpy.ndarray (float) or list of numpy.ndarray (float)

An individual observation sequence or a list of multiple observation sequences.

validate: bool

Whether or not to validate the input sequences.

Returns
transformed:class:numpy:numpy.ndarray (float) or list of numpy.ndarray (float)

The transformed input observation sequence(s).