GsdEmulationPipeline#
- class mobgap.gait_sequences.pipeline.GsdEmulationPipeline(
- algo: BaseGsDetector,
- *,
- convert_to_body_frame: bool = True,
Run a GSD algorithm in isolation on a Gait Dataset.
This wraps any GSD algorithm and allows to apply it to a single datapoint of a Gait Dataset or optimize it based on a whole dataset.
This pipeline can be used in combination with the
tpcp.validateandtpcp.optimizemodules to evaluate or improve the performance of a GSD algorithm.- Parameters:
- algo
The GSD algorithm that should be run/evaluated.
- convert_to_body_frame
If True, the data will be converted to the body frame before running the algorithm. This is the default, as most algorithm expect the data in the body frame. If your data is explictly not aligned and your algorithm supports sensor frame/unaligned input you might want to set this to False.
- Attributes:
- gs_list_
A dataframe specifying the detected gait sequences. The dataframe has a
startandendcolumn, specifying the start and end index of the gait sequence. The values are specified as samples after the start of the recording (i.e. the start of thedata).- algo_
The GSD algo instance with all results after running the algorithm. This can be helpful for debugging or further analysis.
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 thedetectmethod of the algorithm. In addition, we pass the group label of the datapoint asdp_groupto the algorithm. 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.For the
self_optimizemethod, we pass the same metadata to the algorithm, but each value is actually a list of values, one for each datapoint in the dataset.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 data point.
safe_run(datapoint)Run the pipeline with some additional checks.
self_optimize(dataset, **kwargs)Run a "self-optimization" of a GSD-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: BaseGsDetector,
- *,
- convert_to_body_frame: bool = True,
- clone() Self[source]#
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][source]#
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,
Run the pipeline on a single data point.
This extracts the imu_data (
data_ss) and the sampling rate (sampling_rate_hz) from the datapoint and uses thedetectmethod of the GSD algorithm to detect the gait sequences.- 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,
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 nameThe run method must not modify the input parameters of the pipeline
- Parameters:
- datapoint
An instance of a
tpcp.Datasetcontaining 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]],
Run a “self-optimization” of a GSD-algorithm (if it implements the respective method).
This method extracts all data and reference gait sequences from the dataset and uses them to optimize the algorithm by calling the
self_optimizemethod of the GSD algorithm (if it is implemented).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.optimizemodule.- Parameters:
- dataset
A Gait Dataset with reference information.
- kwargs
Additional parameters required for the optimization process. This will be passed to the
self_optimizemethod of the GSD algorithm.
- Returns:
- self
The pipeline instance with the optimized GSD algorithm.
- self_optimize_with_info(
- dataset: DatasetT,
- **kwargs,
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 implementself_optimizeas well.- Parameters:
- dataset
An instance of a
tpcp.Datasetcontaining 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
Examples using mobgap.gait_sequences.pipeline.GsdEmulationPipeline#
Revalidation of the gait sequence detection algorithms