gaitmap.stride_segmentation.hmm.PreTrainedRothSegmentationModel#

class gaitmap.stride_segmentation.hmm.PreTrainedRothSegmentationModel[source]#

Load a pre-trained stride segmentation HMM.

Note

This algorithm is only available via the gaitmap_mad package and distributed under a AGPL3 licence. To use it, you need to explicitly install the gaitmap_mad package. Learn more about that here.

Attributes:
n_states

Return the number of states of the final model.

stride_states

Return the ids of the stride states.

transition_states

Return the ids of the transition states.

Notes

This model was trained on the pre-visit @lab recordings of the first 28 participants of the fallrisk-pd study. According to [1] the expected performance on unseen data under lab conditions is around 96% F1 score and under real-world conditions ca. 92% F1 score.

The model is only for level walking and was only trained on PD data (so it might not generalize well to other conditions).

Recommended use for general segmentation of straight strides. But, the model will probably also segment turning strides as it only considers the gyr_ml data. If only straight strides are desired, strides should be filtered based on turning angle after parameter estimation.

[1]

Roth, N., Küderle, A., Ullrich, M. et al. Hidden Markov Model based stride segmentation on unsupervised free-living gait data in Parkinson`s disease patients. J NeuroEngineering Rehabil 18, 93 (2021). https://doi.org/10.1186/s12984-021-00883-7

Methods

clone()

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

from_json(json_str)

Import an gaitmap object from its json representation.

get_params([deep])

Get parameters for this algorithm.

predict(data, sampling_rate_hz)

Perform prediction based on given data and given model.

self_optimize(data_sequence, ...)

Create and train the HMM model based on the given data and labels.

self_optimize_with_info(data_sequence, ...)

Create and train the HMM model based on the given data and labels.

set_params(**params)

Set the parameters of this Algorithm.

to_json()

Export the current object parameters as json.

__init__(stride_model: SimpleHmm = cf(SimpleHmm(algo_train='baum-welch', architecture='left-right-strict', data_columns=None, max_iterations=10, model=None, n_gmm_components=6, n_jobs=1, n_states=20, name='stride_model', stop_threshold=1e-09, verbose=True)), transition_model: SimpleHmm = cf(SimpleHmm(algo_train='baum-welch', architecture='left-right-loose', data_columns=None, max_iterations=10, model=None, n_gmm_components=3, n_jobs=1, n_states=5, name='transition_model', stop_threshold=1e-09, verbose=True)), feature_transform: RothHmmFeatureTransformer = cf(RothHmmFeatureTransformer(axes=['gyr_ml'], features=['raw', 'gradient'], low_pass_filter=ButterworthFilter(cutoff_freq_hz=10.0, filter_type='lowpass', order=4), sampling_rate_feature_space_hz=51.2, standardization=True, window_size_s=0.2)), *, algo_predict: Literal['viterbi', 'map'] = 'viterbi', algo_train: Literal['viterbi', 'baum-welch'] = 'baum-welch', stop_threshold: float = 1e-09, max_iterations: int = 1, initialization: Literal['labels', 'fully-connected'] = 'labels', verbose: bool = True, n_jobs: int = 1, name: str = 'segmentation_model', model: HiddenMarkovModel | None = None, data_columns: tuple[str, ...] | None = None) None[source]#
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

classmethod from_json(json_str: str) Self[source]#

Import an gaitmap object from its json representation.

For details have a look at the this example.

You can use the to_json method of a class to export it as a compatible json string.

Parameters:
json_str

json formatted string

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.

predict(data: DataFrame, sampling_rate_hz: float) Self[source]#

Perform prediction based on given data and given model.

This generates the hidden state sequence and stores it in the hidden_state_sequence_ attribute. Data will first be transformed using the feature transform and then the trained model will be used to predict the individual hidden states.

Parameters:
data

The data to predict the hidden state sequence for. Note, that this must have the same columns than the data used during training.

sampling_rate_hz

The sampling rate of the data.

Returns:
self

The instance with the result objects attached.

self_optimize(data_sequence: Sequence[DataFrame], stride_list_sequence: Sequence[DataFrame], sampling_rate_hz: float) Self[source]#

Create and train the HMM model based on the given data and labels.

This will first apply the feature transformation to the given data and then train the HMM model in three steps:

  1. Train the stride model on the stride data

  2. Train the transition model on the transition data

  3. Assemble the final model by combining the stride and transition model and train it for a couple further iterations

Parameters:
data_sequence

Sequence of gaitmap sensordata objects.

stride_list_sequence

Sequence of gaitmap stride lists. The number of stride lists must match the number of sensordata objects (i.e. they must belong together).

sampling_rate_hz

Sampling frequency of the data.

Returns:
self

The trained model instance.

self_optimize_with_info(data_sequence: Sequence[DataFrame], stride_list_sequence: Sequence[DataFrame], sampling_rate_hz: float) tuple[typing_extensions.Self, dict[Literal['self', 'transition_model', 'stride_model'], pomegranate.callbacks.History]][source]#

Create and train the HMM model based on the given data and labels.

This is identical to self_optimize, but returns additional information about the training process. The dictionary returned as second parameter contains the training history for each of the three models ( stride-model, transition-model, and the combined final model “self”).

Parameters:
data_sequence

Sequence of gaitmap sensordata objects.

stride_list_sequence

Sequence of gaitmap stride lists. The number of stride lists must match the number of sensordata objects (i.e. they must belong together).

sampling_rate_hz

Sampling frequency of the data.

Returns:
self

The trained model instance.

history

Dictionary containing the training history for each of the three models

set_params(**params: Any) Self[source]#

Set the parameters of this Algorithm.

To set parameters of nested objects use nested_object_name__para_name=.

to_json() str[source]#

Export the current object parameters as json.

For details have a look at the this example.

You can use the from_json method of any gaitmap algorithm to load the object again.

Warning

This will only export the Parameters of the instance, but not any results!

Examples using gaitmap.stride_segmentation.hmm.PreTrainedRothSegmentationModel#

HMM stride segmentation - Prediction with pre-trained model

HMM stride segmentation - Prediction with pre-trained model

HMM stride segmentation - Prediction with pre-trained model