CadEmulationPipeline#

class mobgap.cadence.pipeline.CadEmulationPipeline(algo: BaseCadCalculator)[source]#

Run a cadence estimation algorithm in isolation per gait sequence/WB on a Gait Dataset.

This wraps any cadence estimation algorithm and allows running the algorithm on a single datapoint of a Gait Dataset. The pipeline uses the reference data for all required inputs to the algorithm.

The algorithm will be executed once for each walking bout in the reference data. The algorithm will be provided with the initial contacts from the reference data as direct input.

Parameters:
algo

The cadence estimation algorithm that should be run/evaluated.

Attributes:
cadence_per_sec_

Dataframe containing the cadence for each second of each WB. This is the combined output of all algorithm results run on each WB.

cadence_per_stride_

The interpolated cadence for each stride of each WB. The reference system is used to define the strides. Only strides that are considered valid by the reference system (cadence not NaN) are considered. This means that this output can be compared directly to the reference data on a stride level.

per_wb_algo_

A dictionary containing the algorithm instance for each WB. Each algorithm instance contains the results for the respective WB. This might be used for further analysis or debugging.

Notes

All emulation pipelines pass available metadata of the dataset to the algorithm. This includes the recording metadata (recording_metadata) and the participant metadata (participant_metadata), which are passed as keyword arguments to the detect method of the algorithm. In addition, we pass the group label of the datapoint as dp_group. This is usually not required by algorithms (because this would mean that the algorithm changes behaviour based on the exact recording provided). However, it can be helpful when working with “dummy” algorithms, that simply return some fixed pre-defined results or to be used as cache key, when the algorithm has internal caching mechanisms.

Methods

clone()

Create a new instance of the class with all parameters copied over.

get_params([deep])

Get parameters for this algorithm.

run(datapoint)

Run the cadence estimation algorithm on a single datapoint.

safe_run(datapoint)

Run the pipeline with some additional checks.

self_optimize(dataset, **kwargs)

Optimize the input parameters of the pipeline or algorithm using any logic.

self_optimize_with_info(dataset, **kwargs)

Optimize the input parameters of the pipeline or algorithm using any logic.

set_params(**params)

Set the parameters of this Algorithm.

__init__(algo: BaseCadCalculator) None[source]#
clone() Self#

Create a new instance of the class with all parameters copied over.

This will create a new instance of the class itself and all nested objects

get_params(deep: bool = True) dict[str, Any]#

Get parameters for this algorithm.

Parameters:
deep

Only relevant if object contains nested algorithm objects. If this is the case and deep is True, the params of these nested objects are included in the output using a prefix like nested_object_name__ (Note the two “_” at the end)

Returns:
params

Parameter names mapped to their values.

run(
datapoint: BaseGaitDatasetWithReference,
) Self[source]#

Run the cadence estimation algorithm on a single datapoint.

Parameters:
datapoint

A single datapoint of a Gait Dataset with reference information.

Returns:
self

The pipeline instance with all result attributes populated.

safe_run(
datapoint: DatasetT,
) Self#

Run the pipeline with some additional checks.

It is preferred to use this method over run, as it can catch some simple implementation errors of custom pipelines.

The following things are checked:

  • The run method must return self (or at least an instance of the pipeline)

  • The run method must set result attributes on the pipeline

  • All result attributes must have a trailing _ in their name

  • The run method must not modify the input parameters of the pipeline

Parameters:
datapoint

An instance of a tpcp.Dataset containing only a single datapoint. The structure of the data will depend on the dataset.

Returns:
self

The class instance with all result attributes populated

self_optimize(
dataset: DatasetT,
**kwargs,
) Self#

Optimize the input parameters of the pipeline or algorithm using any logic.

This method can be used to adapt the input parameters (values provided in the init) based on any data driven heuristic.

Note

The optimizations must only modify the input parameters (aka self.clone should retain the optimization results). If you need to return further information, implement self_optimize_with_info instead.

Parameters:
dataset

An instance of a tpcp.Dataset containing one or multiple data points that can be used for training. The structure of the data and the available reference information will depend on the dataset.

kwargs

Additional parameters required for the optimization process.

Returns:
self

The class instance with optimized input parameters.

self_optimize_with_info(
dataset: DatasetT,
**kwargs,
) tuple[Self, Any]#

Optimize the input parameters of the pipeline or algorithm using any logic.

This is equivalent to self_optimize, but allows you to return additional information as a second return value. If you implement this method, there is no need to implement self_optimize as well.

Parameters:
dataset

An instance of a tpcp.Dataset containing one or multiple data points that can be used for training. The structure of the data and the available reference information will depend on the dataset.

kwargs

Additional parameters required for the optimization process.

Returns:
self

The class instance with optimized input parameters.

info

An arbitrary piece of information

set_params(**params: Any) Self#

Set the parameters of this Algorithm.

To set parameters of nested objects use nested_object_name__para_name=.

Examples using mobgap.cadence.pipeline.CadEmulationPipeline#

Revalidation of the cadence algorithms

Revalidation of the cadence algorithms