gaitmap.stride_segmentation.hmm.RothHmmFeatureTransformer#
- class gaitmap.stride_segmentation.hmm.RothHmmFeatureTransformer(sampling_rate_feature_space_hz: float = 51.2, low_pass_filter: BaseFilter | None = cf(ButterworthFilter(cutoff_freq_hz=10.0, filter_type='lowpass', order=4)), axes: list[str] = cf(['gyr_ml']), features: list[str] = cf(['raw', 'gradient']), window_size_s: float = 0.2, standardization: bool = True)[source]#
Transform all data and stride labels into the feature space required for training an HMM.
Note
This algorithm is only available via the
gaitmap_madpackage and distributed under a AGPL3 licence. To use it, you need to explicitly install thegaitmap_madpackage. Learn more about that here.This method is expected to be used in combination with the
RothSegmentationHmmclass. Default values of all parameters are set based on the work of Nils Roth [1].This applies the following transformations to the data:
Low pass filter followed by a resample to a (lower) sampling rate
On the transformed data the following set of features can be calculated (controlled by
features):raw (no transformation)
gradient (gradient calculated using polyfit on a moving window)
mean (sliding window mean)
standard deviation (sliding window std)
variance (sliding window var)
The stride labels if provided will simply be transformed to the sampling rate of the feature space.
This is a very specific high level feature transformer based on the work of Nils Roth [1]. You can create a custom transformer with a similar API interface, if you need more flexibility as exposed by the parameters (see
BaseHmmFeatureTransformer).- Parameters:
- sampling_rate_feature_space_hz
The sampling rate of the data the model was trained with
- low_pass_filter
Instance of a low pass filter to be applied to the data before resampling. Note, that this filter is not strictly required, as the downsampling will apply a second filter to ensure that the Nyquist frequency is not exceeded. However, you might want to use this filter to smooth the signal beyond what is required for correct downsampling. Can be disabled by setting to
None.- axes
List of sensor axes which will be used as model input
- features
List of features which will be used as model input
- window_size_s
window size of moving centered window for feature extraction
- standardization
Flag for feature standardization / z-score normalization. Note, that this is done individually for “train” and “test” data. I.e., we don’t store the standardization parameters from the “train” data. In the particular case of the Roth HMM this worked well, as sufficient data was available for testing.
- Other Parameters:
- data
The data passed to the transform method.
- roi_list
Optional roi list (with values in samples) passed to the transform method
- sampling_rate_hz
The sampling rate of the input data
- Attributes:
- transformed_data_
The transformed data.
- transformed_roi_list_
If a roi_list was provided, this will be the transformed roi list in the new sampling rate
Notes
[1] (1,2)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.
Inverse transform a state sequence to the original sampling rate.
set_params(**params)Set the parameters of this Algorithm.
to_json()Export the current object parameters as json.
transform([data, roi_list, sampling_rate_hz])Perform feature transformation for a single dataset and/or stride list.
- __init__(sampling_rate_feature_space_hz: float = 51.2, low_pass_filter: BaseFilter | None = cf(ButterworthFilter(cutoff_freq_hz=10.0, filter_type='lowpass', order=4)), axes: list[str] = cf(['gyr_ml']), features: list[str] = cf(['raw', 'gradient']), window_size_s: float = 0.2, standardization: bool = True) 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_jsonmethod 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.
- inverse_transform_state_sequence(state_sequence: ndarray, *, data: array) ndarray[source]#
Inverse transform a state sequence to the original sampling rate.
- Parameters:
- state_sequence
The state sequence to be transformed back to the original sampling rate. This is done by repeating each state for the number of samples it was downsampled to.
- data
The original data used for the transformation
- Returns:
- The state sequence in the original sampling rate
- 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_jsonmethod of any gaitmap algorithm to load the object again.Warning
This will only export the Parameters of the instance, but not any results!
- transform(data: DataFrame | None = None, *, roi_list: DataFrame | None = None, sampling_rate_hz: float | None = None, **_)[source]#
Perform feature transformation for a single dataset and/or stride list.
- Parameters:
- data
data to be filtered
- roi_list
Optional roi list/stride list (with values in samples), that will also be resampled to match the data at the new sampling rate. Note, that only the start and end columns will be modified. Other columns remain untouched.
- sampling_rate_hz
The sampling rate of the data in Hz