Last updated: 2022-01-16

Checks: 7 0

Knit directory: false.alarm/

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


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

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 afebf46. 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:    .devcontainer/exts/
    Ignored:    .history
    Ignored:    .httr-oauth
    Ignored:    R/RcppExports.R
    Ignored:    _classifier/.gittargets
    Ignored:    _classifier/meta/process
    Ignored:    _classifier/meta/progress
    Ignored:    _classifier/objects/
    Ignored:    _classifier/user/
    Ignored:    _targets/.gitattributes
    Ignored:    _targets/.gittargets
    Ignored:    _targets/meta/process
    Ignored:    _targets/meta/progress
    Ignored:    _targets/objects/
    Ignored:    _targets/user/
    Ignored:    dev/
    Ignored:    inst/extdata/
    Ignored:    output/images/
    Ignored:    papers/aime2021/aime2021.md
    Ignored:    protocol/SecondReport.pdf
    Ignored:    protocol/SecondReport_cache/
    Ignored:    protocol/SecondReport_files/
    Ignored:    renv/library/
    Ignored:    renv/python/
    Ignored:    renv/staging/
    Ignored:    src/RcppExports.cpp
    Ignored:    src/RcppExports.o
    Ignored:    src/contrast.o
    Ignored:    src/false.alarm.so
    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:    tests/testthat/_snaps/
    Ignored:    tmp/

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 0c43c48 Francisco Bischoff 2022-01-12 wsl
Rmd 95ae431 Francisco Bischoff 2022-01-05 blogdog
Rmd 4fbd6a6 Francisco Bischoff 2022-01-04 bloggin
Rmd 1ef8e75 Francisco Bischoff 2021-10-14 freeze for presentation
html ca1941e GitHub Actions 2021-10-12 Build site.
Rmd 6b03f43 Francisco Bischoff 2021-10-11 Squashed commit of the following:
html 6b03f43 Francisco Bischoff 2021-10-11 Squashed commit of the following:
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 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) algorithms were 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 to date.
  • Streaming: the algorithm can provide real-time information.
  • Real-World Data Suitability: the objective is not to explain all the data. Therefore, areas marked as “don’t know” areas are acceptable.
  • FLOSS is not: a change point detection algorithm3. 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 paper2, it is based on the assumption that between two regimes, the most similar shape (its nearest neighbor) is located on “the same side”. 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. Nevertheless, 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. One option is to apply the constraint on the Profile Index, and we need to have this parameter set from the start. The second option is to have the FLOSS algorithm not accounting for the indexes beyond the constraint, keeping the original Profile Index. 2) The authors declare the correction curve typically used on FLUSS and FLOSS as “simply a uniform distribution”, but this is not an accurate statement. 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)\). This is shown in Fig. 1. That is important because the output of the FLOSS algorithm should be normalized and constrained between 0 and 1, which allows us to compare different trials using different parameters in the process. Finally, the last datapoints 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.

As for 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. That reduces the computation time of the online Matrix Profile, and any post-processing done afterward will inherit this constraint. The distribution for correcting the FLOSS algorithm is also simpler. On the other hand, it is possible to apply the time constraint in the FLOSS algorithm, leaving the online Matrix Profile in its original form. See Fig. 2. 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 in the pipeline, avoiding the recomputation of the Matrix Profile. The results on detecting regime changes are very similar to the first approach. See Fig. 3.

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.

Figure 1  - 1D-IAC distributions for earlier temporal constraint (on Matrix Profile)

Figure 1 - 1D-IAC distributions for earlier temporal constraint (on Matrix Profile)

Version Author Date
ca1941e GitHub Actions 2021-10-12
Figure 2  - 1D-IAC distributions for later temporal constraint (on FLOSS)

Figure 2 - 1D-IAC distributions for later temporal constraint (on FLOSS)

Version Author Date
ca1941e GitHub Actions 2021-10-12
Figure 3  - CAC and Regime detection using early and later IAC

Figure 3 - CAC and Regime detection using early and later IAC

Version Author Date
ca1941e GitHub Actions 2021-10-12

1.2.2 The Matrix Profile Algorithm

Since the first Matrix Profile computation algorithm, the STAMP4, several improvements on the algorithm were made5,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 webpage8. 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, whose updated indexes refer only 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 paper2.

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 equation \(\eqref{edcc}\). 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} \label{edcc} \]

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. More information and visual content on ST will be provided later. The best ST threshold is still to be determined.

1.3 2022, January Update #1

These last months were dedicated to several important things:

  1. Restructuring the roadmap
  2. Refining the main pipeline
  3. Preparing for modeling and parameter tuning
  4. Feasibility trial
  5. And others

1.3.1 Refining the main pipeline

That can also be thought of as “rethinking” the pipeline. What also lead to the roadmap restructuration.

It is essential not only to write a pipeline that can “autoplot” itself for fine-grain inspection but also to design a high-level graph that can explain it “in a glance”. This exercise was helpful both ways: telling the story in a short version also reveals missing things and misleading paths that are not so obvious when thinking “low-level”.

1.3.2 Preparing for modeling and parameter tuning

Here is one missing part that should have been addressed (formally) earlier. Although this work has its purpose of being finally deployed on small hardware, this prospective phase will need several hours of computing, tuning, evaluation, and validation of all findings.

Thus it was necessary to revisit the frameworks we are used to working on R: caret and the newest tidymodels collection. For sure, there are other frameworks and opinions10. Notwithstanding, this project will follow the tidymodels road. Two significant arguments 1) constantly improving and constantly being re-checked for bugs; 2) allows to plug in a custom modeling algorithm that, in this case, will be the one needed for developing this work.

1.3.3 Feasibility trial

A side-project called “false.alarm.io” has been derived from this work (an unfortunate mix of “false.alarm” and “PlatformIO”11, the IDE chosen to interface the panoply of embedded systems we can experiment). The current results of this side-project are very enlightening and show that the final algorithm can indeed be used in small hardware. Further data will be available in the future.

1.3.4 And others

After this “step back” to look forward, it was time to define how the regime change algorithm would integrate with the actual decision of triggering or not the alarm. Some hypotheses were thought out: (1) clustering similar patterns, (2) anomaly detection, (3) classification, and (4) forecasting. Among these methods, it was thought, in order to avoid exceeding processor capacity, an initial set of shapelets12 can be sufficient to rule in or out the TRUE/FALSE challenge. Depending on the accuracy of this approach and the resources available, another method can be introduced for both (1) improving the “negative”1 samples and (2) learning more shapelets to improve the TRUE/FALSE alarm discrimination.

Minor update, but also important concerning the FAIR principle “Interoperability”: the dataset stored publicly on Zenodo13 was converted from .mat to .csv.

Further Steps

  • Explanation on the evaluation method for regime change detection (as described in the FLOSS paper2 )
  • Explain the Cross-validation and evaluation of the algorithm
  • Publish results

References

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, 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, 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

10. Thompson J. On not using tidymodels. Published October 2020. Accessed January 5, 2022. https://staffblogs.le.ac.uk/teachingr/2020/10/05/on-not-using-tidymodels/

11. PlatformIO, a professional collaborative platform for embedded development. Accessed January 5, 2022. https://platformio.org/

12. Rakthanmanon T, Keogh E. Fast shapelets: A scalable algorithm for discovering time series shapelets. In: Proceedings of the 2013 Siam International Conference on Data Mining. Society for Industrial; Applied Mathematics; 2013:668-676. doi:10.1137/1.9781611972832.74

13. Reducing false arrhythmia alarms in the icu - the physionet computing in cardiology challenge 2015. Published online March 24, 2021. doi:10.5281/zenodo.4634013


R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

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

other attached packages:
[1] stringr_1.4.0     tibble_3.1.6      ggplot2_3.3.5     gittargets_0.0.1 
[5] tarchetypes_0.4.1 targets_0.10.0    workflowr_1.7.0   here_1.0.1       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8            gert_1.5.0            languageserver_0.3.12
 [4] getPass_0.2-2         ps_1.6.0              rprojroot_2.0.2      
 [7] digest_0.6.29         utf8_1.2.2            R6_2.5.1             
[10] backports_1.4.1       sys_3.4               evaluate_0.14        
[13] highr_0.9             httr_1.4.2            pillar_1.6.4         
[16] rlang_0.99.0.9003     uuid_1.0-3            rstudioapi_0.13      
[19] data.table_1.14.2     whisker_0.4           callr_3.7.0          
[22] jquerylib_0.1.4       rmarkdown_2.11        labeling_0.4.2       
[25] igraph_1.2.11         munsell_0.5.0         compiler_4.1.2       
[28] httpuv_1.6.5          xfun_0.29             pkgconfig_2.0.3      
[31] askpass_1.1           htmltools_0.5.2       openssl_1.4.6        
[34] tidyselect_1.1.1      gridExtra_2.3         codetools_0.2-18     
[37] fansi_1.0.2           crayon_1.4.2          dplyr_1.0.7          
[40] withr_2.4.3           later_1.3.0           grid_4.1.2           
[43] jsonlite_1.7.2        gtable_0.3.0          lifecycle_1.0.1      
[46] git2r_0.29.0          magrittr_2.0.1        credentials_1.3.2    
[49] scales_1.1.1          cli_3.1.0             stringi_1.7.6        
[52] debugme_1.1.0         farver_2.1.0          renv_0.15.1          
[55] fs_1.5.2              promises_1.2.0.1      xml2_1.3.3           
[58] bslib_0.3.1           ellipsis_0.3.2        generics_0.1.1       
[61] vctrs_0.3.8           tools_4.1.2           glue_1.6.0           
[64] purrr_0.3.4           processx_3.5.2        fastmap_1.1.0        
[67] yaml_2.2.1            colorspace_2.0-2      base64url_1.4        
[70] knitr_1.37            sass_0.4.0           

  1. The term “negative” does not imply that the patient has a “normal” ECG. It means that the “negative” section is not a life-threatening condition that needs to trigger an alarm.