Repeat#

class deeptrack.features.Repeat(feature: Feature, N: int | Callable[[...], int], **kwargs: Any)#

Bases: StructuralFeature

Apply a feature multiple times.

Repeat iteratively applies another feature, passing the output of each iteration as input to the next. This enables chained transformations, where each iteration builds upon the previous one. The number of repetitions is defined by N.

Each iteration operates with its own set of properties, and the index of the current iteration is accessible via _ID. _ID is extended to include the current iteration index, ensuring deterministic behavior when needed.

The use of Repeat

>>> dt.Repeat(A, 3)

is equivalent to using the ^ operator

>>> A ^ 3

Parameters#

feature: Feature

The feature to be repeated N times.

N: int

The number of times to apply the feature in sequence.

**kwargs: Any, optional

Additional keyword arguments.

Attributes#

feature: Feature

The feature to be applied sequentially N times.

Methods#

get(x, N, _ID, **kwargs) -> Any

Applies the feature N times in sequence, passing the output of each iteration as the input to the next.

Examples#

>>> import deeptrack as dt

Define an Add feature that adds 10 to its input:

>>> add_ten_feature = dt.Add(value=10)

Apply this feature 3 times using Repeat:

>>> pipeline = dt.Repeat(add_ten_feature, N=3)

Process an input list:

>>> pipeline.resolve([1, 2, 3])
[31, 32, 33]

Alternative shorthand using ^ operator:

>>> pipeline = add_ten_feature ^ 3
>>> pipeline.resolve([1, 2, 3])
[31, 32, 33]
>>> pipeline.feature(_ID=(0,))
[11, 12, 13]
>>> pipeline.feature(_ID=(1,))
[21, 22, 23]
>>> pipeline.feature(_ID=(2,))
[31, 32, 33]

Methods Summary

get(inputs, *, N[, _ID])

Sequentially apply the feature N times.

Methods Documentation

get(inputs: Any, *, N: int, _ID: tuple[int, ...] = (), **kwargs: Any) Any#

Sequentially apply the feature N times.

This method applies the feature N times, passing the output of each iteration as the input to the next. The _ID tuple is updated at each iteration, ensuring dynamic property updates and reproducibility.

Each iteration uses the output of the previous one. This makes Repeat suitable for building recursive, cumulative, or progressive transformations.

Parameters#

x: Any

The input data to be transformed by the repeated feature.

N: int

The number of times to sequentially apply the feature, where each iteration builds on the previous output.

_ID: tuple[int, …], optional

A unique identifier for tracking the iteration index, ensuring reproducibility, caching, and dynamic property updates. Defaults to ().

**kwargs: Any

Additional keyword arguments passed to the feature.

Returns#

Any

The output of the final iteration after N sequential applications of the feature.