Last updated: 2021-10-04

Checks: 6 1

Knit directory: false.alarm/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20201020) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version ea17d6a. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Renviron
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    .httr-oauth
    Ignored:    R/RcppExports.R
    Ignored:    _targets/
    Ignored:    dev/
    Ignored:    inst/extdata/
    Ignored:    output/Fluss_a103l_II.svg
    Ignored:    output/Fluss_a103l_V.svg
    Ignored:    output/Fluss_a104s_II.svg
    Ignored:    output/Fluss_a104s_V.svg
    Ignored:    output/Fluss_a105l_II.svg
    Ignored:    output/Fluss_a105l_V.svg
    Ignored:    output/Fluss_a109l_II.svg
    Ignored:    output/Fluss_a109l_aVF.svg
    Ignored:    output/Fluss_a123l_II.svg
    Ignored:    output/Fluss_a123l_V.svg
    Ignored:    output/Fluss_a134s_II.svg
    Ignored:    output/Fluss_a134s_V.svg
    Ignored:    output/Fluss_a142s_II.svg
    Ignored:    output/Fluss_a142s_V.svg
    Ignored:    output/Fluss_a145l_II.svg
    Ignored:    output/Fluss_a145l_V.svg
    Ignored:    output/Fluss_a152s_II.svg
    Ignored:    output/Fluss_a152s_V.svg
    Ignored:    output/Fluss_a161l_II.svg
    Ignored:    output/Fluss_a161l_V.svg
    Ignored:    output/Fluss_a163l_II.svg
    Ignored:    output/Fluss_a163l_V.svg
    Ignored:    output/Fluss_a165l_II.svg
    Ignored:    output/Fluss_a165l_V.svg
    Ignored:    papers/_draft/
    Ignored:    papers/aime2021/aime2021.md
    Ignored:    pdfs/
    Ignored:    protocol/0-Reuniao_Entrevista.pdf
    Ignored:    protocol/20210715-Progress Report.pdf
    Ignored:    protocol/A-Relatorio de Progresso.pdf
    Ignored:    protocol/B-Plano de Tese.pdf
    Ignored:    protocol/C-Declaração_PPR.pdf
    Ignored:    protocol/D-Feedback Coorientador.pdf
    Ignored:    protocol/E-CV2021.pdf
    Ignored:    protocol/Z-Relatorio de Progresso.pdf
    Ignored:    protocol/figure/filtered_ecg.svg
    Ignored:    protocol/figure/regime_false.svg
    Ignored:    protocol/figure/regime_filter.svg
    Ignored:    protocol/figure/regime_true.svg
    Ignored:    protocol/figure/roadmap_original.svg
    Ignored:    protocol/figure/roadmap_updated.svg
    Ignored:    renv/library/
    Ignored:    renv/staging/
    Ignored:    src/RcppExports.cpp
    Ignored:    src/RcppExports.o
    Ignored:    src/false.alarm.dll
    Ignored:    src/fft.o
    Ignored:    src/mass.o
    Ignored:    src/math.o
    Ignored:    src/mpx.o
    Ignored:    src/scrimp.o
    Ignored:    src/stamp.o
    Ignored:    src/stomp.o
    Ignored:    src/windowfunc.o
    Ignored:    tmp/

Unstaged changes:
    Modified:   _targets.R
    Modified:   analysis/blog.Rmd
    Modified:   papers/references.bib
    Modified:   src/math.cpp

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/blog.Rmd) and HTML (docs/blog.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd ea17d6a Francisco Bischoff 2021-10-03 text
html ea17d6a Francisco Bischoff 2021-10-03 text
html 1bcac45 Francisco Bischoff 2021-08-17 site
Rmd c88cbd5 Francisco Bischoff 2021-08-17 targets workflowr

1 Purpose

This blog is a continuation of the thesis Report link. The reader must follow this page from top to bottom.

1.1 2021, August Update #1

The first workflow presented in July has changed. Its purpose was to define a “big picture” of the process.

The main changes introduced were:

1.1.1 The Data

Initially, the data had been carried along the workflow, being copied at each new step. That obviously is not the way to handle it. Thus, the raw data is stored only on the “dataset” object and reused where needed.

Now, any modification to the raw data will create a new object, for example, “ds_filtered” where the SQI filter is applied over the data.

1.1.2 Streaming paradigm

The goal of this work is to operate with streaming data. Thus, the Matrix Profile computation algorithm has been rewritten to handle as receiving data in chunks. The algorithm can simulate one observation at a time or a batch of observations (for efficiency). The result will always be as if one observation had been received individually by the model.

To avoid unnecessary recomputations for this analysis phase, the companion statistics needed by the model are pre-computed and fed alongside the data the algorithm needs to process. The pre-computation also allows experimenting with parameters during this process.

1.2 2021, October Update #1

1.2.1 Regime Change Detection

While implementing the streaming-like pipeline, some declarations must be made. In 2017, the FLUSS (Fast Low-cost Unipotent Semantic Segmentation) and the FLOSS (Fast Low-cost Online Semantic Segmentation) algorithm was introduced by Gharghabi et al..1 In 2018, the same group published their findings using multi-dimensional time series2 using the same algorithms.

Claims about the algorithm:

  • Domain Agnosticism: the algorithm makes no assumptions about the data as opposed to most available algorithms so far.
  • Streaming: the algorithm can provide real-time information.
  • Real-World Data Suitability: the objective is not to explain all the data but to flag regions of interest and “don’t know” areas are acceptable.
  • FLOSS is not: a change point detection algorithm.3 The interest here is changes in the shapes of a sequence of measurements.

Briefly describing the regime detection algorithm, which can be explored in the original paper,2 it is based on the assumption that between two regimes, the most similar shape (its nearest neighbor) is located on “the same side.” And this information is obtained from the Matrix Profile computation. More precisely, using only the Profile Index.

Before talking about the Matrix Profile computation, some findings deserve to be mentioned:

In the original paper, in chapter 3.5, the authors of FLOSS wisely introduce the temporal constraint. But some details are not mentioned. 1) As this algorithm only needs the Profile Index, should we use the already computed Indexes or recompute the Matrix Profile using this constraint (i.e., the constraint is on the Profile Index or in the FLOSS algorithm?). That is not an issue about the algorithm but a choice we need to be aware of beforehand. If we apply the constraint on the Profile Index, we need to have this parameter set from the start. If not, the FLOSS algorithm can not take into account the indexes that are larger than the constraint. 2) The correction curve typically used on FLUSS and FLOSS is declared by the authors as “simply a uniform distribution,” but this is not “simply” that. Empirically, there is a helpful pattern to know about the distribution when using temporal constraints (at least from the start, in the Matrix Profile stage). At first glance, we see that the distribution resembles the skewed distribution used in FLOSS but is shorter, while the \(constraint \ge MatrixProfileSize/2\). For lower constraints, the maximum value of this distribution is equal to \(MatrixProfileSize/2\) between the indexes \(constraint\) to the index \(MatrixProfileSize - (constraint \times 0.9)\). That is important to know, and it was not stated by the authors because the output of the FLOSS algorithm should be normalized and constrained between 0 and 1. That allows us to compare different trials using different parameters in the process. Finally, the last data points are not irrelevant, opposed to what was stated by the authors, since an Online algorithm needs to return an answer as soon as the application domain requires. That is very much relevant to this work’s field, as, for example, for asystole detection, we have a window of 4 seconds to fire the alarm. If the time constraint is 10 seconds, this would mean (by the original article) that the last 10 seconds of the incoming data would not be sufficient to detect the regime change.

About the first point mentioned above, it seems more appropriate to set the temporal constraint in the Matrix Profile algorithm, and indeed this is what the original paper did. This reduces the computation time of the online Matrix Profile and any post-processing done afterwards will inherit this constraint. The distribution for correcting the FLOSS algorithm is also simpler. On the other hand, it is possible to apply time constraint in the FLOSS algorithm, leaving the online Matrix Profile in its original form. The theoretical distribution changes significantly according to the constraint value. The upside of this approach, at least during the prospective phase, is to allow us to decide the time constraint value later on the pipeline, avoiding the recomputation of the Matrix Profile. The results on detecting regime changes are very similar to the first approach.

Concerning the second point mentioned above, the solution for evaluating the effect of using time constraints in this work’s setting was to generate the ideal distribution using the constrained parameters beforehand. That gives us enough data to evaluate a regime change accurately utilizing a minimum of \(2 \times WindowSize\) datapoints. The best index is still to be determined, and current tests are using 3 seconds limit.

TODO: explain with images

1.2.2 The Matrix Profile Algorithm

Since the first Matrix Profile computation algorithm, the STAMP,4 several improvements on the algorithm was made.5,6 Still, the ability to keep a growing Matrix Profile (i.e., Online) relies on the STAMP algorithm. If the problem allows collecting several data points (chunks), STOMP5 can speed up the computation. Curiously, the main bottleneck of all these algorithms is the FFT (Fast Fourier Transform) algorithm that is the core of the MASS algorithm published by Mueen et al.7 in 2010 and later in 2015, having its code released on Professor Mueen’s webpage.8 The FFT libraries available are highly optimized and CPU (or GPU) dependent what makes it at the same time fast but brittle and not suitable for MCU’s (Microcontroller Unit), for example. More interestingly yet, is the fact that several published works using Matrix Profile, MPdist9 for instance, uses an unpublished algorithm called ‘MPX’ that computes the Matrix Profile using cross-correlation methods ending up faster and is easily portable.

This work contributes to extending the MPX algorithm to allow the Online computation of the Matrix Profile. More precisely, we are interested in the Right Matrix Profile, which means the updated indexes are only those referred to the last incoming datapoint since we are looking for future changes in the regime, not looking backward. This one-directional algorithm is already described in the FLOSS paper.2

Another contribution of this work is an unexplored constraint that we could apply on building the Matrix Profile that we will call Similarity Threshold (ST). The original work outputs the similarity values in Euclidean Distance (ED) values, while MPX naturally outputs the values in Pearson’s correlation (CC) coefficients. Both ED and CC are interchangeable using the formula (1). However, we may argue that it is easier to compare values that do not depend on the \(WindowSize\) during an exploratory phase. MPX happens to naturally return values in CC, saving a few more computation time.

\[ CC = 1 - \frac{ED}{(2 \times WindowSize)} \tag{1} \]

The ST is an interesting factor that we can use, especially when detecting pattern changes during time. The FLUSS/FLOSS algorithms rely on counting references between indexes in the time series. ST can help remove “noise” from these references since only similar patterns above a certain threshold are referenced, and changes have more impact on these counts. The best threshold is still to be determined.

.. talk about the evaluation metric

1.
Gharghabi S, Ding Y, Yeh C-CM, Kamgar K, Ulanova L, Keogh E. 2017 IEEE international conference on data mining (ICDM). In: IEEE; 2017. doi:10.1109/icdm.2017.21
2.
Gharghabi S, Yeh C-CM, Ding Y, et al. Domain agnostic online semantic segmentation for multi-dimensional time series. Data Mining and Knowledge Discovery. 2018;33(1):96-130. doi:10.1007/s10618-018-0589-3
3.
Aminikhanghahi S, Cook DJ. A survey of methods for time series change point detection. Knowledge and Information Systems. 2016;51(2):339-367. doi:10.1007/s10115-016-0987-z
4.
Yeh C-CM, Zhu Y, Ulanova L, et al. 2016 IEEE 16th international conference on data mining (ICDM). In: IEEE; 2016. doi:10.1109/icdm.2016.0179
5.
Zhu Y, Zimmerman Z, Senobari NS, et al. 2016 IEEE 16th international conference on data mining (ICDM). In: IEEE; 2016. doi:10.1109/icdm.2016.0085
6.
Zhu Y, Yeh C-CM, Zimmerman Z, Kamgar K, Keogh E. 2018 IEEE international conference on data mining (ICDM). In: IEEE; 2018. doi:10.1109/icdm.2018.00099
7.
Mueen A, Nath S, Liu J. SIGMOD/PODS ’10: International conference on management of data. In: ACM; 2010. doi:10.1145/1807167.1807188
8.
Mueen A, Zhu Y, Yeh M, et al. The fastest similarity search algorithm for time series subsequences under euclidean distance. Published 2017. Accessed October 2, 2021. https://www.cs.unm.edu/~mueen/FastestSimilaritySearch.html
9.
Gharghabi S, Imani S, Bagnall A, Darvishzadeh A, Keogh E. 2018 IEEE international conference on data mining (ICDM). In: IEEE; 2018. doi:10.1109/icdm.2018.00119

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Portugal.1252  LC_CTYPE=C                          
[3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C                        
[5] LC_TIME=Portuguese_Portugal.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] here_1.0.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        whisker_0.4       knitr_1.33        magrittr_2.0.1   
 [5] workflowr_1.6.2   debugme_1.1.0     R6_2.5.1          rlang_0.4.11     
 [9] fansi_0.5.0       stringr_1.4.0     tools_4.1.1       xfun_0.24        
[13] utf8_1.2.2        git2r_0.28.0.9000 jquerylib_0.1.4   htmltools_0.5.1.1
[17] ellipsis_0.3.2    rprojroot_2.0.2   yaml_2.2.1        digest_0.6.27    
[21] tibble_3.1.4      lifecycle_1.0.0   crayon_1.4.1      later_1.3.0      
[25] sass_0.4.0        vctrs_0.3.8       promises_1.2.0.1  fs_1.5.0         
[29] glue_1.4.2        evaluate_0.14     rmarkdown_2.11    stringi_1.7.3    
[33] bslib_0.2.5.1     compiler_4.1.1    pillar_1.6.2      jsonlite_1.7.2   
[37] httpuv_1.6.3      pkgconfig_2.0.3