LrcEmulationPipeline#

class mobgap.laterality.pipeline.LrcEmulationPipeline(algo: BaseLRClassifier)[source]#

Run a LRC algorithm in isolation, using reference ICs as input.

This pipeline can wrap any LR-classifier and run it on a datapoint of any valid dataset or optimize it across a full dataset. The LRC is called once per WB in the datapoint and the reference initial contacts are used as the ic_list input for the algorithm.

This pipeline should be used when performing a “block-wise” evaluation of an LRC algorithm or when optimizing an LRC either using external (tpcp.optimize) or internal (self_optimize) optimization.

Parameters:
algo

The LRC algorithm to be run in the pipeline.

Other Parameters:
datapoint

The datapoint that was passed to the run method.

Attributes:
ic_lr_list_

A dataframe containing all ICs across all WBs of a datapoint with an additional column lr_label specifying the detected left/right label.

per_wb_algo_

A dict of the LRC algorithm instances run on each WB of the datapoint. The key is the wb-id. Each instance contains the reference to the data it was called with, the classified labels and potential additional debug information provided by the individual algorithm.

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 pipeline on a single datapoint.

safe_run(datapoint)

Run the pipeline with some additional checks.

self_optimize(dataset, **kwargs)

Run a "self-optimization" of an LRD-algorithm (if it implements the respective method).

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: BaseLRClassifier) 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 pipeline on a single datapoint.

This extracts the imu data (data_ss) and the reference initial contact per reference WB within the datapoint and then calls the detect method of the algorithm once per WB.

Parameters:
datapoint

A single datapoint of a Gait Dataset with reference information.

Returns:
self

The pipeline instance with the detected gait sequences stored in the gs_list_ attribute.

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: BaseGaitDatasetWithReference,
**kwargs: Unpack[dict[str, Any]],
) Self[source]#

Run a “self-optimization” of an LRD-algorithm (if it implements the respective method).

This method extracts the data_list, ic_list, and left-right label from each wb in each datapoint in the dataset, and then calls the self_optimize method of the algorithm with these lists.

Note, that this is only useful for algorithms with “internal” optimization logic (i.e. ML-based algorithms). If you want to optimize the hyperparameters of the algorithm, you should use the tpcp.optimize module.

Parameters:
dataset

A Gait Dataset with reference information.

kwargs

Additional parameters required for the optimization process. This will be passed to the self_optimize method of the GSD algorithm.

Returns:
self

The pipeline instance with the optimized LRD algorithm.

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.laterality.pipeline.LrcEmulationPipeline#

LRC Evaluation

LRC Evaluation

Revalidation of the laterality classification algorithms

Revalidation of the laterality classification algorithms