Merge#
- class deeptrack.features.Merge(function: Callable[[...], Callable[[list[Any]], Any]], **kwargs: Any)#
Bases:
FeatureApply a custom function to a list of inputs.
Merge applies a user-defined function to a list of inputs. The function parameter must be a callable that returns another function, where: - The outer function can depend on other properties in the pipeline. - The inner function takes a list of inputs and return a single output.
The function must be wrapped in an outer layer to enable dependencies on other properties while ensuring correct execution.
Parameters#
- function: Callable[…, Callable[[list[Any]], Any]]
A callable that produces a function. The outer function can depend on other properties of the pipeline, while the inner function processes a list of inputs and returns either a single output or a list of outputs.
- **kwargs: Any
Additional parameters passed to the parent Feature class.
Attributes#
- __distributed__: bool
Set to False, indicating that this feature’s .get() method processes the entire input at once even if it is a list, rather than distributing calls for each item of the list.
Methods#
- get(list_of_inputs, function, **kwargs) -> Any
Applies the custom function to the list of inputs.
Examples#
>>> import deeptrack as dt
Define a merge function that averages multiple arrays:
>>> import numpy as np >>> >>> def merge_function_factory(): ... def merge_function(list_of_inputs): ... return np.mean(np.stack(list_of_inputs), axis=0) ... return merge_function
Create a Merge feature:
>>> merge_feature = dt.Merge(function=merge_function_factory)
Create some arrays:
>>> array_1 = np.ones((2, 3)) * 2 >>> array_2 = np.ones((2, 3)) * 4
Apply the feature to a list of arrays:
>>> output_array = merge_feature([array_1, array_2]) >>> output_array array([[3., 3., 3.], [3., 3., 3.]])
Methods Summary
get(list_of_inputs, function, **kwargs)Apply the custom function to a list of inputs.
Methods Documentation
- get(list_of_inputs: list[Any], function: Callable[[list[Any]], Any], **kwargs: Any) Any#
Apply the custom function to a list of inputs.
Parameters#
- list_of_inputs: list[Any]
A list of inputs to be processed by the function.
- function: Callable[[list[Any]], Any]
The function that processes the list of inputs and returns either a single transformed input or a list of transformed inputs. The function is expected to be the evaluated inner function produced by the factory passed at initialization.
- **kwargs: Any
Additional arguments (unused in this implementation).
Returns#
- Any
The processed inputs after applying the function.