diff --git a/.github/workflows/draft-pdf.yml b/.github/workflows/draft-pdf.yml new file mode 100644 index 00000000..51a805e3 --- /dev/null +++ b/.github/workflows/draft-pdf.yml @@ -0,0 +1,23 @@ +on: [push] + +jobs: + paper: + runs-on: ubuntu-latest + name: Paper Draft + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build draft PDF + uses: openjournals/openjournals-draft-action@master + with: + journal: joss + # This should be the path to the paper within your repo. + paper-path: paper/paper.md + - name: Upload + uses: actions/upload-artifact@v1 + with: + name: paper + # This is the output path where Pandoc will write the compiled + # PDF. Note, this should be the same directory as the input + # paper.md + path: paper/paper.pdf \ No newline at end of file diff --git a/paper/code/Project.toml b/paper/code/Project.toml new file mode 100644 index 00000000..9e5445fc --- /dev/null +++ b/paper/code/Project.toml @@ -0,0 +1,4 @@ +[deps] +CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" +DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" +TransitionsInTimeseries = "5f5b98ec-1183-43e0-887a-12fdc55c52f7" diff --git a/paper/code/ewstools-tuto-1.py b/paper/code/ewstools-tuto-1.py new file mode 100644 index 00000000..457fba8b --- /dev/null +++ b/paper/code/ewstools-tuto-1.py @@ -0,0 +1,60 @@ +import time +import numpy as np +import matplotlib.pyplot as plt +import ewstools +from ewstools.models import simulate_ricker + +# Set seed for reproducibility +np.random.seed(0) + +# Initialize time series and spectrum computation +series = simulate_ricker(tmax=1000, F=[0,2.7]) +ts = ewstools.TimeSeries(data=series, transition=860) +ts.detrend(method='Lowess', span=0.2) +ts.state[['state','smoothing']].plot() +ts.compute_spectrum(rolling_window=0.5, ham_length=40) + +# Initialize parameters for timing functions +rw = 0.5 +n = 100 +t_elapsed = np.zeros(10) + +# Time functions (in a not very elegant way) +t0 = time.time() +for i in range(n): + ts.compute_var(rolling_window=rw) +t_elapsed[0] = time.time() - t0 + +t0 = time.time() +for i in range(n): + ts.compute_cv() +t_elapsed[1] = time.time() - t0 + +t0 = time.time() +for i in range(n): + ts.compute_skew(rolling_window=rw) +t_elapsed[2] = time.time() - t0 + +t0 = time.time() +for i in range(n): + ts.compute_kurt() +t_elapsed[3] = time.time() - t0 + +t0 = time.time() +for i in range(n): + ts.compute_auto(rolling_window=rw, lag=1) +t_elapsed[4] = time.time() - t0 + +t0 = time.time() +for i in range(n): + ts.compute_smax() +t_elapsed[5] = time.time() - t0 + +t0 = time.time() +for i in range(n): + ts.compute_ktau() +t_elapsed[6] = time.time() - t0 + +t0 = time.time() +surro = ewstools.core.block_bootstrap(ts.state.residuals, n, bs_type='Stationary', block_size=10) +t_elapsed[7] = time.time() - t0 \ No newline at end of file diff --git a/paper/code/figure1.jl b/paper/code/figure1.jl new file mode 100644 index 00000000..2e203e92 --- /dev/null +++ b/paper/code/figure1.jl @@ -0,0 +1,16 @@ +using TransitionsInTimeseries, DelimitedFiles, CairoMakie, Random + +x = readdlm("ewstools-tuto-1.csv", ',')[:, end] +t = eachindex(x) + +# Choose the indicators and how to measure their change over time +indicators = (var, ar1_whitenoise) +change_metrics = (kendalltau, kendalltau) +config = SegmentedWindowConfig(indicators, change_metrics, [t[1]], [t[end]]; + width_ind = length(x) ÷ 2, whichtime = last, min_width_cha = 50) +results = estimate_indicator_changes(config, x, t) +signif = SurrogatesSignificance(n = 1000, tail = [:right, :right], rng = Xoshiro(1995)) +flags = significant_transitions(results, signif) +fig = plot_changes_significance(results, signif) +ylims!(contents(fig[2, 1])[2], (0.037, 0.045)) +save("../figures/figure1.png", fig) \ No newline at end of file diff --git a/paper/code/figure2.jl b/paper/code/figure2.jl new file mode 100644 index 00000000..0c511946 --- /dev/null +++ b/paper/code/figure2.jl @@ -0,0 +1,71 @@ +using TransitionsInTimeseries, DelimitedFiles, CairoMakie, Random + +coefficient_of_variation(x) = std(x) / mean(x) + +function main() + x = readdlm("ewstools-tuto-1.csv", ',')[:, end] + t = eachindex(x) + + # Choose the indicators and how to measure their change over time + indicators = (var, coefficient_of_variation, skewness, kurtosis, + ar1_whitenoise, LowfreqPowerSpectrum()) + stride = [1, 1, 1, 1, 1, 40] + n, m = 100, length(indicators) + t_elapsed = zeros(m+2) + + + for (i, ind) in enumerate(indicators) + # Build configuration with adequate parameters of the sliding window + config = SegmentedWindowConfig((ind, ind), (nothing, nothing), [t[1]], [t[end]]; + width_ind = length(x) ÷ 2, stride_ind = stride[i], whichtime = last, + min_width_cha = 1) + + t0 = time() + for i in 1:n + # Compute the metrics over sliding windows and their significance + results = estimate_indicator_changes(config, x, t) + end + t_elapsed[i] = (time() - t0) / 2 + end + + config = SegmentedWindowConfig((nothing, nothing), (kendalltau, kendalltau), [t[1]], [t[end]]; + width_ind = length(x) ÷ 2, stride_ind = 1, whichtime = last, min_width_cha = 1) + t0 = time() + for i in 1:n + results = estimate_indicator_changes(config, x, t) + end + t_elapsed[m+1] = (time() - t0) / 2 + + sgen = surrogenerator(x, BlockShuffle(), Xoshiro(1995)) + t0 = time() + for i in 1:n + s = sgen() + end + t_elapsed[m+2] = time() - t0 + + return t_elapsed +end + +t_tt = main() +t_et = [0.03840542, 0.05554581, 0.03895116, 0.04029274, 7.96556187, + 2.73067856, 0.39529872, 0.02751493] + +# [0.04681492, 8.13679838, 0.04035759, 0.09219241] +inds = eachindex(t_et) +w = 0.4 + +fig, ax = barplot(inds .- 0.5*w, t_et, label = L"ewstools $\,$", width = w, + fillto = 1e-5) +barplot!(ax, inds .+ 0.5*w, t_tt, label = L"TransitionsInTimeseries.jl $\,$", + width = w, fillto = 1e-5) +ax.yscale = log10 +ax.xticks = (1:8, [L"Variance $\,$", L"Coeff. of variation $\,$", L"Skewness $\,$", + L"Kurtosis $\,$", L"Lag-1 autocorr. $\,$", L"Spectral $\,$", + L"Kendall $\tau$ corr. coeff.", L"Block bootstrap $\,$"]) +ax.ylabel = L"Run time (s) of 100 computations on Ricker model data $\,$" +ax.yticks = (10.0 .^ (-5:1), [L"10^{%$e}" for e in -5:1]) +ax.xgridvisible = false +ax.ygridvisible = false +ax.xticklabelrotation = π / 4 +axislegend(ax, position = :lt) +save("../figures/figure2.png", fig) \ No newline at end of file diff --git a/paper/figures/figure1.png b/paper/figures/figure1.png new file mode 100644 index 00000000..cf84ae89 Binary files /dev/null and b/paper/figures/figure1.png differ diff --git a/paper/figures/figure2.png b/paper/figures/figure2.png new file mode 100644 index 00000000..93def1c6 Binary files /dev/null and b/paper/figures/figure2.png differ diff --git a/paper/paper.bib b/paper/paper.bib new file mode 100644 index 00000000..b78c5b82 --- /dev/null +++ b/paper/paper.bib @@ -0,0 +1,184 @@ + +@article{wolff_changes_2010, + title = {Changes in environment over the last 800,000 years from chemical analysis of the {EPICA} {Dome} {C} ice core}, + volume = {29}, + issn = {02773791}, + url = {https://linkinghub.elsevier.com/retrieve/pii/S027737910900208X}, + doi = {10.1016/j.quascirev.2009.06.013}, + abstract = {The EPICA ice core from Dome C extends 3259 m in depth, and encompasses 800 ka of datable and sequential ice. Numerous chemical species have been measured along the length of the cores. Here we concentrate on interpreting the main low-resolution patterns of major ions. We extend the published record for non-sea-salt calcium, sea-salt sodium and non-sea-salt sulfate flux to 800 ka. The non-sea-salt calcium record confirms that terrestrial dust originating from South America closely mirrored Antarctic climate, both at orbital and millennial timescales. A major cause of the main trends is most likely climate in southern South America, which could be sensitive to subtle changes in atmospheric circulation. Seasalt sodium also follows temperature, but with a threshold at low temperature. We re-examine the use of sodium as a sea ice proxy, concluding that it is probably reflecting extent, with high salt concentrations reflecting larger ice extents. With this interpretation, the sodium flux record indicates low ice extent operating as an amplifier in warm interglacials. Non-sea-salt sulfate flux is almost constant along the core, confirming the lack of change in marine productivity (for sulfur-producing organisms) in the areas of the Southern Ocean contributing to the flux at Dome C. For the first time we also present long records of reversible species such as nitrate and chloride, and show that the pattern of post-depositional losses described for shallower ice is maintained in older ice. It appears possible to use these concentrations to constrain snow accumulation rates in interglacial ice at this site, and the results suggest a possible correction to accumulation rates in one early interglacial. Taken together the chemistry records offer a number of constraints on the way the Earth system combined to give the major climate fluctuations of the late Quaternary period.}, + language = {en}, + number = {1-2}, + urldate = {2022-06-14}, + journal = {Quaternary Science Reviews}, + author = {Wolff, E.W. and Barbante, C. and Becagli, S. and Bigler, M. and Boutron, C.F. and Castellano, E. and de Angelis, M. and Federer, U. and Fischer, H. and Fundel, F. and Hansson, M. and Hutterli, M. and Jonsell, U. and Karlin, T. and Kaufmann, P. and Lambert, F. and Littot, G.C. and Mulvaney, R. and Röthlisberger, R. and Ruth, U. and Severi, M. and Siggaard-Andersen, M.L. and Sime, L.C. and Steffensen, J.P. and Stocker, T.F. and Traversi, R. and Twarloh, B. and Udisti, R. and Wagenbach, D. and Wegner, A.}, + month = jan, + year = {2010}, + pages = {285--295}, + file = {Wolff et al. - 2010 - Changes in environment over the last 800,000 years.pdf:/home/jan/Zotero/storage/JK969GT8/Wolff et al. - 2010 - Changes in environment over the last 800,000 years.pdf:application/pdf}, +} + +@article{dakos_methods_2012, + title = {Methods for {Detecting} {Early} {Warnings} of {Critical} {Transitions} in {Time} {Series} {Illustrated} {Using} {Simulated} {Ecological} {Data}}, + volume = {7}, + issn = {1932-6203}, + url = {https://dx.plos.org/10.1371/journal.pone.0041010}, + doi = {10.1371/journal.pone.0041010}, + abstract = {Many dynamical systems, including lakes, organisms, ocean circulation patterns, or financial markets, are now thought to have tipping points where critical transitions to a contrasting state can happen. Because critical transitions can occur unexpectedly and are difficult to manage, there is a need for methods that can be used to identify when a critical transition is approaching. Recent theory shows that we can identify the proximity of a system to a critical transition using a variety of so-called ‘early warning signals’, and successful empirical examples suggest a potential for practical applicability. However, while the range of proposed methods for predicting critical transitions is rapidly expanding, opinions on their practical use differ widely, and there is no comparative study that tests the limitations of the different methods to identify approaching critical transitions using time-series data. Here, we summarize a range of currently available early warning methods and apply them to two simulated time series that are typical of systems undergoing a critical transition. In addition to a methodological guide, our work offers a practical toolbox that may be used in a wide range of fields to help detect early warning signals of critical transitions in time series data.}, + language = {en}, + number = {7}, + urldate = {2022-09-29}, + journal = {PLoS ONE}, + author = {Dakos, Vasilis and Carpenter, Stephen R. and Brock, William A. and Ellison, Aaron M. and Guttal, Vishwesha and Ives, Anthony R. and Kéfi, Sonia and Livina, Valerie and Seekell, David A. and van Nes, Egbert H. and Scheffer, Marten}, + editor = {Yener, Bülent}, + month = jul, + year = {2012}, + pages = {e41010}, + file = {Dakos et al. - 2012 - Methods for Detecting Early Warnings of Critical T.pdf:/home/jan/Zotero/storage/SMK65I98/Dakos et al. - 2012 - Methods for Detecting Early Warnings of Critical T.pdf:application/pdf}, +} + +@article{bury_deep_2021, + title = {Deep learning for early warning signals of tipping points}, + volume = {118}, + issn = {0027-8424, 1091-6490}, + url = {https://pnas.org/doi/full/10.1073/pnas.2106140118}, + doi = {10.1073/pnas.2106140118}, + abstract = {Significance + Early warning signals (EWS) of tipping points are vital to anticipate system collapse or other sudden shifts. However, existing generic early warning indicators designed to work across all systems do not provide information on the state that lies beyond the tipping point. Our results show how deep learning algorithms (artificial intelligence) can provide EWS of tipping points in real-world systems. The algorithm predicts certain qualitative aspects of the new state, and is also more sensitive and generates fewer false positives than generic indicators. We use theory about system behavior near tipping points so that the algorithm does not require data from the study system but instead learns from a universe of possible models. + , + Many natural systems exhibit tipping points where slowly changing environmental conditions spark a sudden shift to a new and sometimes very different state. As the tipping point is approached, the dynamics of complex and varied systems simplify down to a limited number of possible “normal forms” that determine qualitative aspects of the new state that lies beyond the tipping point, such as whether it will oscillate or be stable. In several of those forms, indicators like increasing lag-1 autocorrelation and variance provide generic early warning signals (EWS) of the tipping point by detecting how dynamics slow down near the transition. But they do not predict the nature of the new state. Here we develop a deep learning algorithm that provides EWS in systems it was not explicitly trained on, by exploiting information about normal forms and scaling behavior of dynamics near tipping points that are common to many dynamical systems. The algorithm provides EWS in 268 empirical and model time series from ecology, thermoacoustics, climatology, and epidemiology with much greater sensitivity and specificity than generic EWS. It can also predict the normal form that characterizes the oncoming tipping point, thus providing qualitative information on certain aspects of the new state. Such approaches can help humans better prepare for, or avoid, undesirable state transitions. The algorithm also illustrates how a universe of possible models can be mined to recognize naturally occurring tipping points.}, + language = {en}, + number = {39}, + urldate = {2022-10-20}, + journal = {Proceedings of the National Academy of Sciences}, + author = {Bury, Thomas M. and Sujith, R. I. and Pavithran, Induja and Scheffer, Marten and Lenton, Timothy M. and Anand, Madhur and Bauch, Chris T.}, + month = sep, + year = {2021}, + pages = {e2106140118}, + file = {Bury et al. - 2021 - Deep learning for early warning signals of tipping.pdf:/home/jan/Zotero/storage/WA6IEXU6/Bury et al. - 2021 - Deep learning for early warning signals of tipping.pdf:application/pdf}, +} + +@article{scheffer_early-warning_2009, + title = {Early-warning signals for critical transitions}, + volume = {461}, + issn = {0028-0836, 1476-4687}, + url = {https://www.nature.com/articles/nature08227}, + doi = {10.1038/nature08227}, + language = {en}, + number = {7260}, + urldate = {2022-10-20}, + journal = {Nature}, + author = {Scheffer, Marten and Bascompte, Jordi and Brock, William A. and Brovkin, Victor and Carpenter, Stephen R. and Dakos, Vasilis and Held, Hermann and van Nes, Egbert H. and Rietkerk, Max and Sugihara, George}, + month = sep, + year = {2009}, + pages = {53--59}, + file = {Scheffer et al. - 2009 - Early-warning signals for critical transitions.pdf:/home/jan/Zotero/storage/AHP85FB4/Scheffer et al. - 2009 - Early-warning signals for critical transitions.pdf:application/pdf}, +} + +@article{bury_ewstools_2023, + title = {ewstools: {A} {Python} package for early warning signals ofbifurcations in time series data}, + volume = {8}, + issn = {2475-9066}, + shorttitle = {ewstools}, + url = {https://joss.theoj.org/papers/10.21105/joss.05038}, + doi = {10.21105/joss.05038}, + abstract = {Many systems in nature and society have the capacity to undergo critical transitions: sudden and profound changes in dynamics that are hard to reverse. Examples include the outbreak of disease, the collapse of an ecosystem, and the onset of a cardiac arrhythmia. From a mathematical perspective, these transitions may be understood as the crossing of a bifurcation (tipping point) in an appropriate dynamical system model. In 2009, Scheffer and colleagues proposed early warning signals (EWS) for bifurcations based on statistics of noisy fluctuations in time series data (Scheffer et al., 2009). This spurred massive interest in the subject, resulting in a multitude of different EWS for anticipating bifurcations (Clements \& Ozgul, 2018). More recently, EWS from deep learning classifiers have outperformed conventional EWS on several model and empirical datasets, whilst also providing information on the type of bifurcation (Bury et al., 2021). Software packages for EWS can facilitate the development and testing of EWS, whilst also providing the scientific community with tools to rapidly apply EWS to their own data.}, + language = {en}, + number = {82}, + urldate = {2023-02-19}, + journal = {Journal of Open Source Software}, + author = {Bury, Thomas M.}, + month = feb, + year = {2023}, + pages = {5038}, + file = {Bury - 2023 - ewstools A Python package for early warning signa.pdf:/home/jan/Zotero/storage/IE6VGV8G/Bury - 2023 - ewstools A Python package for early warning signa.pdf:application/pdf}, +} + +@article{ismail_detecting_2020, + title = {Detecting {Early} {Warning} {Signals} of {Major} {Financial} {Crashes} in {Bitcoin} {Using} {Persistent} {Homology}}, + volume = {8}, + issn = {2169-3536}, + url = {https://ieeexplore.ieee.org/document/9250440/}, + doi = {10.1109/ACCESS.2020.3036370}, + abstract = {This study explores persistent homology to detect early warning signals of the 2017 and 2019 major financial crashes in Bitcoin. Sliding window is used to obtain point cloud datasets from a multidimensional time series (Bitcoin, Ethereum, Litecoin and Ripple). We apply persistent homology to quantify transient loops that appear in multiscale topological spaces, which associated on each point cloud dataset and encode the quantified information in a persistence landscape. Temporal changes in persistence landscapes are measured via their L1-norms. Consequently, a new representative is attained, called L1-norms time series. The L1-norms is associated with indicators: autocorrelation function at lag 1, variance and mean power spectrum at low frequencies to detect the signals. By using Kendall’s tau correlation and significance test, significant rising trend events that occur before major financial crashes in Bitcoin are defined as the signals. A threshold is determined to scan entire data and record all the significant rising trend events. Lastly, we compare L1-norms with residuals time series, which is another representative obtained from de-trending approach. Our result portrays that autocorrelation function at lag 1 and variance of the L1-norms successfully detect early warning signals before the 2017 and 2019 major financial crashes. However, variance of the L1-norms is better since it able to signal another 2018 major financial crash. For the residuals, no early warning signals are detected. Hence, persistent homology provides a better representative than de-trending approach. Overall, persistent homology is a promising method to detect early warning signals of major financial crashes in Bitcoin.}, + language = {en}, + urldate = {2023-03-14}, + journal = {IEEE Access}, + author = {Ismail, Mohd Sabri and Hussain, Saiful Izzuan and Noorani, Mohd Salmi Md.}, + year = {2020}, + pages = {202042--202057}, + file = {Ismail et al. - 2020 - Detecting Early Warning Signals of Major Financial.pdf:/home/jan/Zotero/storage/2Y5IUH4A/Ismail et al. - 2020 - Detecting Early Warning Signals of Major Financial.pdf:application/pdf}, +} + +@article{haaga_timeseriessurrogatesjl_2022, + title = {{TimeseriesSurrogates}.jl: a {Julia} package for generatingsurrogate data}, + volume = {7}, + issn = {2475-9066}, + shorttitle = {{TimeseriesSurrogates}.jl}, + url = {https://joss.theoj.org/papers/10.21105/joss.04414}, + doi = {10.21105/joss.04414}, + language = {en}, + number = {77}, + urldate = {2023-11-06}, + journal = {Journal of Open Source Software}, + author = {Haaga, Kristian Agasøster and Datseris, George}, + month = sep, + year = {2022}, + pages = {4414}, + file = {Haaga and Datseris - 2022 - TimeseriesSurrogates.jl a Julia package for gener.pdf:/home/jan/Zotero/storage/2SID8YPF/Haaga and Datseris - 2022 - TimeseriesSurrogates.jl a Julia package for gener.pdf:application/pdf}, +} + +@article{tse_mechanisms_2016, + title = {Mechanisms of cardiac arrhythmias}, + volume = {32}, + issn = {1880-4276, 1883-2148}, + url = {https://onlinelibrary.wiley.com/doi/10.1016/j.joa.2015.11.003}, + doi = {10.1016/j.joa.2015.11.003}, + abstract = {Blood circulation is the result of the beating of the heart, which provides the mechanical force to pump oxygenated blood to, and deoxygenated blood away from, the peripheral tissues. This depends critically on the preceding electrical activation. Disruptions in the orderly pattern of this propagating cardiac excitation wave can lead to arrhythmias. Understanding of the mechanisms underlying their generation and maintenance requires knowledge of the ionic contributions to the cardiac action potential, which is discussed in the first part of this review. A brief outline of the different classification systems for arrhythmogenesis is then provided, followed by a detailed discussion for each mechanism in turn, highlighting recent advances in this area.}, + language = {en}, + number = {2}, + urldate = {2024-01-04}, + journal = {Journal of Arrhythmia}, + author = {Tse, Gary}, + month = apr, + year = {2016}, + pages = {75--81}, + file = {Tse - 2016 - Mechanisms of cardiac arrhythmias.pdf:/home/jan/Zotero/storage/NASH5BLI/Tse - 2016 - Mechanisms of cardiac arrhythmias.pdf:application/pdf}, +} + +@article{ditlevsen_warning_2023, + title = {Warning of a forthcoming collapse of the {Atlantic} meridional overturning circulation}, + volume = {14}, + issn = {2041-1723}, + url = {https://www.nature.com/articles/s41467-023-39810-w}, + doi = {10.1038/s41467-023-39810-w}, + abstract = {Abstract + The Atlantic meridional overturning circulation (AMOC) is a major tipping element in the climate system and a future collapse would have severe impacts on the climate in the North Atlantic region. In recent years weakening in circulation has been reported, but assessments by the Intergovernmental Panel on Climate Change (IPCC), based on the Climate Model Intercomparison Project (CMIP) model simulations suggest that a full collapse is unlikely within the 21st century. Tipping to an undesired state in the climate is, however, a growing concern with increasing greenhouse gas concentrations. Predictions based on observations rely on detecting early-warning signals, primarily an increase in variance (loss of resilience) and increased autocorrelation (critical slowing down), which have recently been reported for the AMOC. Here we provide statistical significance and data-driven estimators for the time of tipping. We estimate a collapse of the AMOC to occur around mid-century under the current scenario of future emissions.}, + language = {en}, + number = {1}, + urldate = {2024-02-13}, + journal = {Nature Communications}, + author = {Ditlevsen, Peter and Ditlevsen, Susanne}, + month = jul, + year = {2023}, + pages = {4254}, + file = {Ditlevsen and Ditlevsen - 2023 - Warning of a forthcoming collapse of the Atlantic .pdf:/home/jan/Zotero/storage/82KUXTX4/Ditlevsen and Ditlevsen - 2023 - Warning of a forthcoming collapse of the Atlantic .pdf:application/pdf}, +} + +@article{ben-yami_uncertainties_2023, + title = {Uncertainties in critical slowing down indicators of observation-based fingerprints of the {Atlantic} {Overturning} {Circulation}}, + volume = {14}, + issn = {2041-1723}, + url = {https://www.nature.com/articles/s41467-023-44046-9}, + doi = {10.1038/s41467-023-44046-9}, + abstract = {Abstract + Observations are increasingly used to detect critical slowing down (CSD) to measure stability changes in key Earth system components. However, most datasets have non-stationary missing-data distributions, biases and uncertainties. Here we show that, together with the pre-processing steps used to deal with them, these can bias the CSD analysis. We present an uncertainty quantification method to address such issues. We show how to propagate uncertainties provided with the datasets to the CSD analysis and develop conservative, surrogate-based significance tests on the CSD indicators. We apply our method to three observational sea-surface temperature and salinity datasets and to fingerprints of the Atlantic Meridional Overturning Circulation derived from them. We find that the properties of these datasets and especially the specific gap filling procedures can in some cases indeed cause false indication of CSD. However, CSD indicators in the North Atlantic are still present and significant when accounting for dataset uncertainties and non-stationary observational coverage.}, + language = {en}, + number = {1}, + urldate = {2024-02-13}, + journal = {Nature Communications}, + author = {Ben-Yami, Maya and Skiba, Vanessa and Bathiany, Sebastian and Boers, Niklas}, + month = dec, + year = {2023}, + pages = {8344}, + file = {Ben-Yami et al. - 2023 - Uncertainties in critical slowing down indicators .pdf:/home/jan/Zotero/storage/SBRVGKQE/Ben-Yami et al. - 2023 - Uncertainties in critical slowing down indicators .pdf:application/pdf}, +} diff --git a/paper/paper.md b/paper/paper.md new file mode 100644 index 00000000..39b24329 --- /dev/null +++ b/paper/paper.md @@ -0,0 +1,250 @@ +--- +title: 'TransitionInTimeSeries.jl: A performant, extensible and reliable software for +reproducible detection and prediction of transitions in timeseries' +tags: + - Julia + - nonlinear dynamics + - timeseries analysis + - change point detection + - resilience loss + - critical slowing down + - early warning signals +authors: + - name: Jan Swierczek-Jereczek + orcid: 0000-0003-2213-0423 + affiliation: "1, 2" + - name: George Datseris + orcid: 0000-0003-0872-7098 + affiliation: 3 +affiliations: +- name: Department of Earth Physics and Astrophysics, Complutense University of Madrid. + index: 1 +- name: Geosciences Institute, CSIC-UCM. + index: 2 +- name: Department of Mathematics and Statistics, University of Exeter. + index: 3 +date: 13 February 2024 +bibliography: paper.bib +--- + +# Summary + +Transitions of nonlinear dynamical systems can significantly impact individuals +and society. Examples of this are ubiquitous and include the onset of cardiac arrhythmia +[@tse_mechanisms_2016], the deglaciation of Earth about 20,000 years ago [@wolff_changes_2010] +and the recent price collapse of many cryptocurrencies [@ismail_detecting_2020]. The systems +displaying such transitions are usually monitored by measuring state variables +that are believed to be representative of the underlying process. Researchers analyze the +resulting timeseries with various methods to detect past transitions and predict +future ones. + +# Statement of need + +Over the last decades, methods to detect and predict transitions from timeseries have gained +a lot of attention, both inside and outside of the scientific community. For instance, recent +work predicting a collapse of the Atlantic Meridional Overturning Circulation between 2025 +and 2095 has led to no less than 870 news outlets and 4100 tweets [@ditlevsen_warning_2023], +largely because of the substantial implications of such a collapse for human societies. +A common concern in the scientific community is that published work on the topic is difficult +to reproduce, despite the impact it implies for humanity. +This can be largely addressed by a unifying software that is accessible, performant, +reproducible, reliable and extensible. Such a software does not exist yet, but here +we propose TransitionsInTimeseries.jl to fill this gap. +We believe this is a major step towards establishing a software as standard, widely used +by academics working on transitions in timeseries. + +# TransitionsInTimeseries.jl + +## Accessibility + +### Open-source + +TransitionsInTimeseries.jl is a free and open-source software, written in Julia and +developed on GitHub, which allows any user to track the full history of the changes made +to the software as well as to suggest new ones by opening a pull request or an issue. + +### Ease of use + +TransitionsInTimeseries.jl is accessible to any scientist thanks to the convenience functions +it provides to detect and predict transitions in timeseries +with only a few lines of code. A frequent prediction technique relies on observing, prior to +a transition, an increase of the variance and the AR1 regression coefficient of the detrended +timeseries, which is a consequence of Critical Slowing Down +(CSD, [@scheffer_early-warning_2009]) and is here measured by Kendall's $\tau$ coefficient. +To assess whether this increase is significant, one can perform a statistical test, for +instance by performing the same computations on 1,000 surrogates of the original timeseries +[@haaga_timeseriessurrogatesjl_2022]. The increase in variance and AR1 coefficient can be +considered significant if the original timeseries classifies in the uppermost 5% of the +surrogates, corresponding to a p-value $p<0.05$. All these steps can be performed, along with a +visualisation of the results within a few lines only: + +```julia +# Loading and preprocessing the data needs to be done by the user +time, data = load_data() + +# Choose the indicators and how to measure their change over time +indicators = (var, ar1_whitenoise) +change_metrics = (kendalltau, kendalltau) + +# Configuration with adequate parameters of the sliding window over a segment +config = SegmentedWindowConfig(indicators, change_metrics, [time[1]], [time[end]]; + width_ind = length(residual) ÷ 2, whichtime = last, min_width_cha = 100) + +# Compute the metrics over sliding windows and their significance +results = estimate_indicator_changes(config, data, time) +signif = SurrogatesSignificance(n = 1000, tail = :right, rng = Xoshiro(1995)) +flags = significant_transitions(results, signif) + +# Visualize the results +fig = plot_changes_significance(results, signif) +``` + +We apply this code to data generated by a Ricker model presenting an abrupt transition +at $t = 860$, which is used in the first tutorial of `ewstools` [@bury_ewstools_2023], +the most recent software covering similar functionalities. +The results are shown in [Fig. 1](@figure1) and display, as expected from CSD theory, an +increase in both variance and AR1 coefficient, which is exactly the same as computed +by `ewstools`. However, calling `signif.pvalues` shows that the increase in variance is not +significant ($p = 0.284$), whereas the increase in AR1 coefficient is ($p = 0.001$). + +![Output of plotting function in usage example.\label{fig: fig1}](figures/figure1.png) + +We believe that a concise and unambiguous code will greatly reduce the programming effort of +many researchers and ease the code reviewing process. Finally, the code +documentation provides a thorough API description as well as additional examples, +showcasing that the simplicity of the code also applies to real-world applications. + +## Performance + +TransitionsInTimeseries.jl is written in Julia, which offers both a simple syntax and good +performance. Additionally, all performance-relevant steps have been optimized and +parallelized when possible, as, for instance, the significance testing relying on surrogates. +In the final section of this article, we present a comparison to `ewstools`, showing that +TransitionsInTimeseries.jl offers a significant speed-up in all the studied cases. + +## Reproducibility + +Some steps of a transition analysis involve random number generators, which need +to be handled with care in parallelized codes. This is done in TransitionsInTimeseries.jl, +which offers the possibility of seeding a random number generator by using the +keyword argument `rng`, as done in the example shown above. Furthermore, +TransitionsInTimeseries.jl follows the guidelines of semantic versioning which, +along with Julia's integrated package manager, ensures that the same code is used for both +results generation and peer reviewing. + +## Reliability + +In the high-impact context mentioned in the introduction, it is crucial to avoid errors. +TransitionsInTimeseries.jl is therefore tested via continuous integration on a large test +suite, thus providing a reliable research framework. Furthermore, a centralized code base +implies that any new user is a new test, thus increasing the reliability of the code over +time. Finally, the robustness of the results with respect to a parameter, e.g. the width +of the sliding window, can be easily studied thanks to the simple syntax, thus contributing +to the reliability of the results. + +## Extensibility + +An important aspect of the modularity mentioned above, is that self-written functions can be +passed as indicators or change metrics. Thus, researchers can easily +test new methods without any programming overhead, nor modification of the source code. To +illustrate this, the code shown above can include the skewness as indicator of the +transition by modifying a few lines: + +```julia +skewness(x::Vector) = mean( (x .- mean(x))^3 ) / mean( (x .- mean(x))^2 )^1.5 +indicators = (var, ar1_whitenoise, skewness) +change_metrics = (kendalltau, kendalltau, kendalltau) +``` + +There is no complexity restriction on the self-programmed functions, as long as they comply +with the structure of taking a vector as input and returning a scalar as output. + +## Integration + +TransitionsInTimeseries.jl is designed to be well integrated into the Julia ecosystem. +Functions can be imported from other packages and subsequently passed as indicators or +change metrics. For instance, the skewness implemented above can be loaded from StatsBase.jl +instead. TransitionsInTimeseries.jl therefore offers an extremely wide and +potentially unlimited library of indicators. Furthermore, TimeseriesSurrogates.jl +[@haaga_timeseriessurrogatesjl_2022] is used to create surrogates of the timeseries, +thus offering optimized routines with numerous surrogate types. + + +## Versatility + +### Choosing a pipeline + +TransitionsInTimeseries.jl covers methods for prediction as well as detection of transitions, +which is unprecedented to our knowledge. This relies on the definition of different analysis pipelines, which +consist in a `ChangesConfig` determining the behavior of `estimate_indicator_changes` via +multiple dispatch. For instance, a detection +task can be performed by replacing the `SegmentedWindowConfig` by a `SlidingWindowConfig` +in the code above: + +```julia +# Here the data should not be detrended +time, data = load_data() + +indicators = (nothing, nothing) +change_metrics = (difference_of_mean(), difference_of_max()) +config = SlidingWindowConfig(indicators, change_metrics; + width_cha = 50, whichtime = midpoint) +results = estimate_indicator_changes(config, data, time) +``` + +We here skip the computation of indicators and compare the difference in mean and maximum +values between the two halves of the sliding window, which gives a particularly high value +in the case of an abrupt transition and is therefore suited for some detection tasks. +Most importantly, this examples shows that the user can choose the type of analysis pipeline, +along with its underlying parameters (e.g. sliding window width). Similarly, different +ways of testing for significance are provided and can be interchangeably used. + +### Creating your own pipeline + +Besides choosing among the already provided analysis pipelines, +the user can implement their own one by defining a new `ChangesConfig` and +the corresponding behavior of `estimate_indicator_changes`. This makes it particularly +easy to leverage pre-existing functionalities of TransitionsInTimeseries.jl +with a minimal restriction on the structure. As explained in the devdocs, the latter eases +the integration of new methods into a unified framework. This also holds for the +significance pipeline and makes TransitionsInTimeseries.jl particularly versatile. + +# Comparison to already existing alternatives + +`earlywarnings` [@dakos_methods_2012] and `spatialwarnings` are toolboxes written in R +providing many tools to predict transitions. +These are early and valuable efforts but are (1) restricted to +prediction tasks, (2) written in a less performant language, (3) not parallelised, (4) not +designed for convenient reproducibility and (5) not extensible. + +`ewstools` [@bury_ewstools_2023] is a Python/TensorFlow package offering similar +functionalities as `earlywarnings`, as well as a deep-learning approach to predicting +transitions [@bury_deep_2021]. This effort addresses some drawbacks of `earlywarnings`, +mainly (4) and to a lesser extent (2) and (3). This is a great step forward but does not +provide a generic and extensible framework for researchers to test new methods on both +detection and prediction tasks. We believe that this is now covered by +TransitionsInTimeseries.jl. + +Using TransitionsInTimeseries.jl, we reproduced the computations showcased in Tutorial 1 +and Tutorial 2 of the `ewstools` documentation, along with the block bootstrapping. We +performed each computation 100 times and show the resulting run times in [Fig. 2](@figure2). +It appears that all computation are faster in TransitionsInTimeseries, with a speed-up factor +ranging from 0 to 3 orders of magnitude. The implementation of the deep-learning classifiers +for transition prediction developed in [@bury_deep_2021], as well as dealing with +multidimensional timeseries, are part of future developments of TransitionsInTimeseries.jl. + +![Performance comparison between `ewstools` and TransitionsInTimeseries.jl.\label{fig: fig1}](figures/figure2.png) + +# Documentation + +The documentation of TransitionsInTimseries.jl is available at +[https://docs.juliahub.com/General/TransitionsInTimeseries/stable/] + +# Acknowledgements + +Jan Swierczek-Jereczek is funded by CriticalEarth, grant no. 956170, an H2020 Research +Infrastructure of the European Commission. George Datseris is funded by UKRI's Engineering and +Physical Sciences Research Council, grant no. EP/Y01653X/1 (grant agreement for a EU +Marie Sklodowska-Curie Postdoctoral Fellowship). + +# References \ No newline at end of file