GenericMobilisedPipeline#
- class mobgap.pipeline.GenericMobilisedPipeline(
- *,
- gait_sequence_detection: BaseGsDetector,
- initial_contact_detection: BaseIcDetector,
- laterality_classification: BaseLRClassifier,
- cadence_calculation: BaseCadCalculator | None,
- stride_length_calculation: BaseSlCalculator | None,
- walking_speed_calculation: BaseWsCalculator | None,
- turn_detection: BaseTurnDetector | None,
- stride_selection: StrideSelection,
- wba: WbAssembly,
- dmo_thresholds: DataFrame | None,
- dmo_aggregation: BaseAggregator | None,
- recommended_cohorts: tuple[str, ...] | None = None,
Pipeline structure of the Mobilise-D pipeline without any default algorithms.
Warning
While this class implements the basic structure of the Mobilise-D pipeline, we only consider it “The Mobilise-D pipeline” if it is used with the predefined parameters/algorithms for the cohorts these parameters are evaluated for.
This pipeline class can either be used with a custom set of algorithms instances or the “official” predefined parameters for healthy or impaired walking (see Examples). However, when using the predefined parameters it is recommended to use the separate classes instead (
MobilisedPipelineHealthyandMobilisedPipelineImpaired).For detailed steps on how this pipeline works, check the Notes section and the dedicated examples.
- Parameters:
- gait_sequence_detection
A valid instance of a gait sequence detection algorithm. This will get the entire raw data as input. The core output is available via the
gs_list_attribute.- initial_contact_detection
A valid instance of an initial contact detection algorithm. This will run on each gait sequence individually. The concatenated raw ICs are available via the
raw_ic_list_attribute.- laterality_classification
A valid instance of a laterality classification algorithm. This will run on each gait sequence individually, getting the predicted ICs from the IC detection algorithm as input. The concatenated raw ICs with L/R label are available via the
raw_ic_list_attribute.- cadence_calculation
A valid instance of a cadence calculation algorithm. This will run on each “refined” gait sequence individually. This means the provided gait sequence will start and end at the first and last detected IC. The detected ICs (with L/R label) and all
ParticipantMetadataparameters are provided as keyword arguments. The concatenated raw cadence per second values are available via theraw_per_sec_parameters_attribute.- stride_length_calculation
A valid instance of a stride length calculation algorithm. This will run on each “refined” gait sequence individually. This means the provided gait sequence will start and end at the first and last detected IC. The detected ICs (with L/R label) and all
ParticipantMetadataparameters are provided as keyword arguments. The concatenated raw stride length per second values are available via theraw_per_sec_parameters_attribute.- walking_speed_calculation
A valid instance of a walking speed calculation algorithm. This will run on each “refined” gait sequence individually. This means the provided gait sequence will start and end at the first and last detected IC. The detected ICs (with L/R label), cadence per second, stride length per second values and all
ParticipantMetadataparameters are provided as keyword arguments. The concatenated raw walking speed per second values are available via theraw_per_sec_parameters_attribute.Note
If either cadence or stride length is not provided,
Nonewill be passed to the algorithm. Depending on the algorithm, this might raise an error, as the information is required.- turn_detection
A valid instance of a turn detection algorithm. This will run on each gait sequence individually. The concatenated raw turn detections are available via the
raw_turn_list_attribute.- stride_selection
A valid instance of a stride selection algorithm. This will be called with all interpolated stride parameters (
raw_per_stride_parameters_) across all gait sequences.- wba
A valid instance of a walking bout assembly algorithm. This will be called with the filtered stride list from the stride selection algorithm. The final list of strides that are part of a valid WB are available via the
per_stride_parameters_attribute. The aggregated parameters for each WB are available via theper_wb_parameters_attribute.- dmo_thresholds
A DataFrame with the thresholds for the individual DMOs. To learn more about the required structure and the filtering process, please refer to the documentation of the
get_mobilised_dmo_thresholdsandapply_thresholds.- dmo_aggregation
A valid instance of a DMO aggregation algorithm. This will be called with the aggregated parameters for each WB and the mask of the DMOs. The final aggregated parameters are available via the
aggregated_parameters_attribute.- recommended_cohorts
A tuple of recommended cohorts for this pipeline. If a datapoint is provided with a cohort that is not part of this tuple, a warning will be raised. This can also be used in combination with the
MobilisedMetaPipelineto conditionally run a specific pipeline based on the cohort of the participant.
- Other Parameters:
- datapoint
The dataset instance passed to the run method.
- Attributes:
- per_stride_parameters_
The final list of all strides including their parameters that are part of a valid WB. Note, that all per-stride parameters are interpolated based on the per-sec output of the other algorithms. Check out the pipeline examples to learn more about this.
- per_wb_parameters_
Aggregated parameters for each WB. This contains “meta parameters” like the number of strides, duration of the WB and the average over all strides of cadence, stride length and walking speed (if calculated).
- per_wb_parameter_mask_
A “valid” mask calculated using the
apply_thresholdsfunction. It indicates for each WB which DMOs are valid. NaN indicates that the value has not been checked- aggregated_parameters_
The final aggregated parameters. They are calculated based on the per WB parameters and the DMO mask. Invalid parameters are (depending on the implementation in the provided Aggregation algorithm) excluded. This output can either be a dataframe with a single row (all WBs were aggregated to a single value, default), or a dataframe with multiple rows, if the aggregation algorithm uses a different aggregation approach.
- gs_list_
The raw output of the gait sequence detection algorithm. This is a DataFrame with the start and end of each detected gait sequence.
- raw_ic_list_
The raw output of the IC detection and the laterality classification. This is a DataFrame with the detected ICs and the corresponding L/R label.
- raw_turn_list_
The raw output of the turn detection algorithm. This is a DataFrame with the detected turns (start, end, angle, …).
- raw_per_sec_parameters_
A concatenated dataframe with all calculated per-second parameters. The index represents the sample of the center of the second the parameter value belongs to.
- raw_per_stride_parameters_
A concatenated dataframe with all calculated per-stride parameters and the general stride information (start, end, laterality).
- gait_sequence_detection_
The instance of the gait sequence detection algorithm that was run with all of its results.
- gs_iterator_
The instance of the GS iterator that was run with all of its results. This contains the raw results for each GS, as well as the information about the constrained gs. These raw results (inputs and outputs per GS) can be used to test run individual algorithms exactly like they were run within the pipeline.
- stride_selection_
The instance of the stride selection algorithm that was run with all of its results.
- wba_
The instance of the WBA algorithm that was run with all of its results.
- dmo_aggregation_
The instance of the DMO aggregation algorithm that was run with all of its results.
See also
mobgap.pipeline.MobilisedPipelineHealthyA predefined pipeline for healthy/mildly impaired walking.
mobgap.pipeline.MobilisedPipelineImpairedA predefined pipeline for impaired walking.
Notes
The Mobilise-D pipeline consists of the following steps:
Gait sequences are detected using the provided gait sequence detection algorithm.
Within each gait sequence, initial contacts are detected using the provided IC detection algorithm. A “refined” version of the gait sequence is created, starting and ending at the first and last detected IC.
Cadence, stride length and walking speed are calculated for each “refined” gait sequence. The output of these algorithms is provided per second.
Using the L/R label for each IC calculated by the laterality classification algorithm, strides are defined.
The per-second parameters are interpolated to per-stride parameters.
The stride selection algorithm is used to filter out strides that don’t fulfill certain criteria.
The WBA algorithm is used to assemble the strides into walking bouts. This is done independent of the original gait sequences.
Aggregated parameters for each WB are calculated.
If DMO thresholds are provided, these WB-level parameters are filtered based on physiological valid thresholds.
The DMO aggregation algorithm is used to aggregate the WB-level parameters to either a set of values per-recording or any other granularity (i.e. one value per hour), depending on the aggregation algorithm.
For a step-by-step example of how these steps are executed, check out The Mobilise-D pipeline: Step-by-Step Breakdown.
Methods
clone()Create a new instance of the class with all parameters copied over.
get_params([deep])Get parameters for this algorithm.
Get the recommended cohorts for this pipeline.
run(datapoint)Run the pipeline on the provided data..
safe_run(datapoint)Run the pipeline with some additional checks.
score(datapoint)Calculate performance of the pipeline on a datapoint with reference information.
set_params(**params)Set the parameters of this Algorithm.
PredefinedParameters
- __init__(
- *,
- gait_sequence_detection: BaseGsDetector,
- initial_contact_detection: BaseIcDetector,
- laterality_classification: BaseLRClassifier,
- cadence_calculation: BaseCadCalculator | None,
- stride_length_calculation: BaseSlCalculator | None,
- walking_speed_calculation: BaseWsCalculator | None,
- turn_detection: BaseTurnDetector | None,
- stride_selection: StrideSelection,
- wba: WbAssembly,
- dmo_thresholds: DataFrame | None,
- dmo_aggregation: BaseAggregator | None,
- recommended_cohorts: tuple[str, ...] | None = None,
- 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.
- get_recommended_cohorts() tuple[str, ...] | None[source]#
Get the recommended cohorts for this pipeline.
- Returns:
- recommended_cohorts
The recommended cohorts for this pipeline or None
- run(
- datapoint: BaseGaitDatasetT,
Run the pipeline on the provided data..
- Parameters:
- datapoint
The data to run the pipeline on. This needs to be a valid datapoint (i.e. a dataset with just a single row). The Dataset should be a child class of
BaseGaitDatasetor implement all the same parameters and methods.
- Returns:
- self
The pipeline object itself with all the results stored in the attributes.
- 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
- score(
- datapoint: DatasetT,
Calculate performance of the pipeline on a datapoint with reference information.
This is an optional method and does not need to be implemented in many cases. Usually stand-a-lone functions are better suited as scorer.
A typical score method will call
self.run(datapoint)and then compare the results with reference values also available on the dataset.- Parameters:
- datapoint
An instance of a
tpcp.Datasetcontaining only a single datapoint. The structure of the data and the available reference information will depend on the dataset.
- Returns:
- score
A float or dict of float quantifying the quality of the pipeline on the provided data. A higher score is always better.