gaitmap.stride_segmentation.DtwTemplate#

class gaitmap.stride_segmentation.DtwTemplate(*, data: ndarray | DataFrame | None = None, sampling_rate_hz: float | None = None, scaling: BaseTransformer | None = None, use_cols: Sequence[str | int] | None = None)[source]#

Wrap all required information about a dtw template.

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.

Parameters:
data

The actual data representing the template. If this should be a array or a dataframe might depend on your usecase. This data is the unscaled version of the template. Use the get_data method to get the correctly scaled template.

sampling_rate_hz

The sampling rate that was used to record the template data. This will be overwritten by the sampling rate of provided to the self_optimize method.

scaling

A valid scaler instance, that is used to transform the template data. It is usually a good idea to choose a scaler that maps the template to a range from -1-1. The same scaler must then be applied to the data before matching the template. This can be done using the transform_data method.

Note that the scaler is not adapted to the template in any way for this base DtwTemplate class. The scaler will be applied to the data (using transform_data) and to the template (using get_data) as is. If you want to use a trainable scaler, that is modified based on the template data, use one of the TrainableTemplateMixin subclasses and create new templates via the provided self_optimize method.

use_cols

The columns of the template that should actually be used. If the template is an array this must be a list of int, if it is a dataframe, the content of use_cols must match a subset of these columns. This will affect the return value of the get_data method.

See also

gaitmap.stride_segmentation.BaseDtw

How to apply templates

gaitmap.stride_segmentation.BarthDtw

How to apply templates for stride segmentation

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_data()

Return the template data.

get_params([deep])

Get parameters for this algorithm.

set_params(**params)

Set the parameters of this Algorithm.

to_json()

Export the current object parameters as json.

transform_data(data, sampling_rate_hz)

Transform external data according to the template scaling.

__init__(*, data: ndarray | DataFrame | None = None, sampling_rate_hz: float | None = None, scaling: BaseTransformer | None = None, use_cols: Sequence[str | int] | 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_data() ndarray | DataFrame[source]#

Return the template data.

This will only return the columns of data that are listed in use_cols and will apply the scaling.

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.

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!

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

Transform external data according to the template scaling.

This method should be applied to the data before the template is matched. There is usually no need to do this manually, as all the implemented Dtw methods do this automatically internally.

Parameters:
dataSingleSensorData

The data to transform.

sampling_rate_hzfloat

The sampling rate of the data. This will be forwarded to the scaler, incase it is used.

Returns:
SingleSensorData

The transformed data.

Examples using gaitmap.stride_segmentation.DtwTemplate#

BaseDtw simple segmentation

BaseDtw simple segmentation

BaseDtw simple segmentation