Introduction to adept package

Marta Karas

Ciprian Crainiceanu

Jacek Urbanek

2019-06-18

Introduction

The adept package implements ADaptive Empirical Pattern Transformation (ADEPT) method1 for pattern segmentation from a time-series. ADEPT is optimized to perform fast, accurate walking strides segmentation from high-density data collected with a wearable accelerometer during walking. The method was validated using data collected with sensors worn at left wrist, left hip and both ankles.

This vignette introduces ADEPT algorithm and demonstrates the usage of segmentPattern function which implements ADEPT approach. Here, we focus on examples with simulated data; see the Walking strides segmentation with adept2 for the example of walking stride segmentation in real-life data.

ADEPT method

ADEPT identifies patterns in a time-series x via maximization of chosen similarity statistic (correlation, covariance, etc.) between a time-series x and a pattern template(s). It accounts for variability in both (1) pattern duration and (2) pattern shape.

Pattern template

We define a pattern template as a 1-dimensional numeric vector which values represent the pattern of interest (e.g. accelerometry data of a human stride).

In this vignette, a pattern template is a simulated data vector.

Install and load adept package

Install adept package from GitHub.

# install.packages("devtools")      
devtools::install_github("martakarass/adept")

Load adept and other packages.

library(adept)
library(magrittr)
library(ggplot2)

Pattern segmentation with adept package

The examples below are organized into suites. Examples within one suite share data simulation settings, for example: Examples 1: signal with no noise, same-length pattern.

Examples 1: signal with no noise, same-length pattern

Example 1(a): segment pattern

We use segmentPattern to segment pattern from a time-series x. We assume that a perfect template is available. We use a grid of potential pattern durations of {0.9, 0.95, 1.03, 1.1} seconds; the grid is imperfect in a sense it does not contain the duration of the true pattern used in x simulation.

segmentPattern output

The segmentation result is a data frame, where each row describes one identified pattern occurrence:

  • tau_i - index of x where pattern starts,
  • T_i - pattern duration, expressed in x vector length,
  • sim_i - similarity between a template and x,
  • template_i - index of a template best matched to a time-series x (here: one template was used, hence all template_i’s equal 1).

See ?segmentPattern for details.

Example 1(b): use pattern.dur.seq to modify a grid of pattern duration

We next generate a dense grid of potential pattern durations, including value 1.0 seconds used in the x simulation. A perfect match (sim_i = 1) between a time-series x and a template is obtained.

Examples 2: signal with no noise, pattern duration varies

Simulate data

We simulate a time-series x. We assume that

  • x is collected at a frequency of 100 Hz,
  • there is one shape of a pattern present within x,
  • patterns have various duration,
  • there is no noise in the collected data.

Example 2(a): segment pattern

We use a dense grid of potential pattern duration, including all values used in the x simulation to again obtain the perfect match (sim_i = 1). In this example, the start and the end points of identified patterns are connected (see figure below).

Example 2(b): use pattern.dur.seq to modify a grid of pattern duration

Next, we use a less dense grid of potential pattern duration. We observe that perfect match (sim_i = 1) between a template and time-series x is no longer obtained. Note:

  • A less dense pattern.dur.seq grid yields a shorter time of method execution.
  • As explained later, when peak detection tuning is used, having a “maximally dense” pattern duration grid does not contribute much.

Example 2(c): use similarity.measure to modify similarity statistic

We use similarity.measure to modify the similarity statistic. We observe that sim_i values in the result data frame change and the segmentation results change slightly too. The explanation is that a change of similarity statistic takes an effect on ADEPT iterative maximization procedure.

Examples 3: signal with no noise, pattern duration and pattern shape vary

Simulate data

We simulate a time-series x. We assume that

  • x is collected at a frequency of 100 Hz,
  • there are two shapes of pattern present within x,
  • patterns have various duration,
  • there is no noise in the collected data.

Example 3(b): use similarity.measure.thresh to modify the threshold of minimal similarity

We use a similarity threshold to segment only those patterns for which similarity (here: correlation) is greater than 0.95. Note that using the threshold may substantially speed up method execution when working with a large data set.

Examples 4: signal with noise, pattern duration and pattern shape vary

Simulate data

We simulate a time-series x. We assume that

  • x is collected at a frequency of 100 Hz,
  • there are two shapes of a pattern present within x,
  • patterns have various duration,
  • there is noise in the collected data.

Example 4(b): use x.adept.ma.W to smooth x for similarity matrix computation

We use x.adept.ma.W to define a length of a smoothing window to smooth x for similarity matrix computation; x.adept.ma.W is expressed in seconds and the default is NULL (no smoothing applied).

Smoothing of a time-series x

Function windowSmooth allows observing the effect of smoothing for different values of smoothing window length W. W is expressed in seconds. Here, W = 0.1 seconds seems to be a plausible choice.

Use x.adept.ma.W = 0.1 and compare with results from Example 4(a). Observe that using a smoothed version of x in similarity matrix computation is pronounced in sim_i values in the output data frame, as well as in a slight change in tau_i and T_i values.

Example 4(c): use fine-tune procedure for peak detection

We employ a fine-tuning procedure for stride identification.

Fine-tune procedure "maxima"

Fine-tune procedure "maxima" tunes preliminarily identified start and end of a pattern occurrence so as they correspond to local maxima of x found within neighborhoods of the preliminary locations.

  • The parameter finetune.maxima.nbh.W, expressed in seconds, defines a length of the two neighborhoods within which we search for local maxima.
  • Smoothed version of x may be used for local maxima search (as presented later).

We observe that almost all identified pattern occurrence start/end points are hitting the time point which our eyes identify as local x maxima.

Example 4(d): use fine-tune procedure and smooth signal for peak detection

We smooth x for both similarity matrix computation (set x.adept.ma.W = 0.1) and for fine-tune peak detection procedure (set finetune.maxima.nbh.W = 0.3).

  • Here, W = 0.5 seconds seems to be a plausible choice for fine-tune peak detection procedure as it removes (“smooth together”) multiple local maxima of x, leaving out a single one.