Description Usage Arguments Details Value Examples
View source: R/segmentPattern.R
Segment pattern from a time-series x
via Adaptive Empirical Pattern
Transformation (ADEPT).
1 2 3 4 5 6 | segmentPattern(x, x.fs, template, pattern.dur.seq,
similarity.measure = "cov", similarity.measure.thresh = 0,
x.adept.ma.W = NULL, finetune = NULL, finetune.maxima.ma.W = NULL,
finetune.maxima.nbh.W = NULL, run.parallel = FALSE,
run.parallel.cores = NULL, x.cut = TRUE, x.cut.vl = 6000,
compute.template.idx = FALSE)
|
x |
A numeric vector. A time-series to segment pattern occurrences from. |
x.fs |
A numeric scalar. Frequency at which a time-series |
template |
A list of numeric vectors, or a numeric vector. Each vector represents a distinct pattern template used in segmentation. |
pattern.dur.seq |
A numeric vector. A grid of pattern duration times used in segmentation. Expressed in seconds. See: Details. |
similarity.measure |
A character scalar. Statistic used to compute similarity
between a time-series
Default is |
similarity.measure.thresh |
A numeric scalar. Threshold of minimal similarity
value between a time-series |
x.adept.ma.W |
A numeric scalar.
A length of a window used in moving average smoothing of a time-series |
finetune |
A character scalar. A type of fine-tuning procedure employed in
segmentation. Defaults to
|
finetune.maxima.ma.W |
A numeric scalar.
A length of a window used in moving average smoothing of a time-series |
finetune.maxima.nbh.W |
A numeric scalar.
A length of the two neighborhoods centered at preliminarily identified pattern occurrence beginning and end points
within which we search for local maxima of |
run.parallel |
A logical scalar. Whether or not to use parallel execution in the algorithm.
The |
run.parallel.cores |
An integer scalar.
The number of cores to use for parallel execution.
Default is |
x.cut |
A logical scalar. Whether or not to use time optimization procedure in
which a time-series |
x.cut.vl |
An integer scalar.
Defines a vector length of parts that |
compute.template.idx |
A logical scalar. Whether or not to compute and return information about
which of the provided pattern templates yielded a similarity matrix value
that corresponds to an identified pattern occurrence.
Setting to |
Function implements Adaptive Empirical Pattern Transformation (ADEPT) method for pattern segmentation
from a time-series x
.
ADEPT was designed with the aim of performing fast, accurate walking strides segmentation
from high-density data
collected from wearable accelerometer worn during continuous walking activity.
ADEPT identifies pattern occurrences from a time-series x
via maximizing similarity
(correlation, covariance etc.) between a time-series x
and pattern
templates.
Pattern template is scaled to various scale parameters to allow
for a potentially better match with pattern occurrences that may change
its duration over time. pattern.dur.seq
argument defines a grid of a
pattern duration to be used in segmentation. Note: the more dense grid may potentially
increase segmentation accuracy but may also increase method execution time.
Multiple pattern templates are allowed simultaneously to allow for potentially better match with pattern occurrences that may change its shape over time.
In practice, a pre-defined pattern template may be derived as an empirical pattern, that is, a data-derived vector representing a pattern of interest.
A data.frame
with segmentation results. Each row
of the returned data.frame
describes one identified pattern occurrence:
tau_i
- index of a time-series x
where identified pattern occurrence starts,
T_i
- duration of identified pattern occurrence, expressed in a time-series x
vector length,
sim_i
- value of similarity statistic between an identified pattern occurrence and corresponding
window of a time-series used in similarity matrix computation;
note: this value corresponds to similarity statistic between
preliminarily identified pattern occurrence and corresponding window of a time-series used in similarity matrix computation;
specifically: if the fine-tune procedure is employed,
the similarity value between the final pattern occurrence location and corresponding window of time-series x
signal may differ from the value in this table,
template_i
- if compute.template.idx
equals TRUE
:
index of pattern template that yielded a similarity matrix value
corresponding to an identified pattern occurrence;
if compute.template.idx
equals FALSE
: NA
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | ## Example 1:
## - no noise in time-series x generation,
## - all pattern occurrences of the same length (101) n time-series x generation.
## Generate signal and template.
x0 <- cos(seq(0, 2 * pi * 10, length.out = 1001))
x <- x0
template <- x0[1:101]
## Include true pattern occurrence length 101
## (and some redundat for the sake of example).
pattern.dur.seq <- c(90, 100, 101, 102, 110)
## Use segmentPattern function to identify beginnings tau_i and duration T_i
## of pattern occurrences within a signal x.
out <- segmentPattern(x = x,
x.fs = 1,
template = template,
pattern.dur.seq = pattern.dur.seq,
similarity.measure = "cor")
out
## Example 2:
## - no noise in time-series x generation,
## - use pattern occurrences of different length in time-series x generation.
## Generate signal and template.
set.seed(1)
## Grid of different true pattern occurrence durations.
s.grid <- sample(60:120, size = 10)
x_block <- cos(seq(0, 2 * pi, length.out = 200))
## Generate signal x that consists of "glued" pattern occurrences of different length
x <- numeric()
for (ss in s.grid){
x_block_interpolated <- approx(seq(0, 1, length.out = 200),
x_block,
xout = seq(0, 1, length.out = ss))$y
if (length(x)>0){
x <- x[-length(x)]
}
x <- c(x, x_block_interpolated)
}
## Pattern template used in algorithm
template <- x_block
## Assume dense grid of pattern occurrence duration.
pattern.dur.seq <- 60:120
## Use segmentPattern function to identify beginnings tau_i and duration T_i.
out <- segmentPattern(x = x,
x.fs = 1,
template = template,
pattern.dur.seq = pattern.dur.seq,
similarity.measure = "cor")
out
## Example 3(a):
## - add noise in time-series x generation,
## - use pattern occurrences of different length in time-series x generation.
## Generate signal and template
s.grid <- sample(60:120, size = 10)
x_block <- cos(seq(0, 2 * pi, length.out = 200))
set.seed(1)
x <- numeric()
for (ss in s.grid){
x_block_interpolated <- approx(seq(0, 1, length.out = 200),
x_block,
xout = seq(0, 1, length.out = ss))$y
if (length(x)>0){
x <- x[-length(x)]
}
x <- c(x, x_block_interpolated)
}
x <- x + rnorm(length(x), sd = 0.3)
pattern.dur.seq <- seq(50, 150, by = 5)
## Pattern template used in algorithm
template <- x_block
## Use segmentPattern function to identify beginnings tau_i and duration T_i:
## - use fine-tune "maxima" procedure.
out <- segmentPattern(x = x,
x.fs = 1,
template = template,
pattern.dur.seq = pattern.dur.seq,
similarity.measure = "cor",
finetune = "maxima",
finetune.maxima.ma.W = 30,
finetune.maxima.nbh.W = 120)
out
## Example 3(b):
## Use segmentPattern function to identify beginnings tau_i and duration T_i:
## - use time-series x smooting for ADEPT similarity matrix computation,
## - use fine-tune "maxima" procedure.
out <- segmentPattern(x = x,
x.fs = 1,
template = template,
pattern.dur.seq = pattern.dur.seq,
similarity.measure = "cor",
x.adept.ma.W = 30,
finetune = "maxima",
finetune.maxima.ma.W = 30,
finetune.maxima.nbh.W = 120)
out
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.