Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes of typos, README and tests #77

Merged
merged 7 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
[![codecov](https://codecov.io/gh/JuliaDynamics/TransitionsInTimeseries.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/JuliaDynamics/TransitionsInTimeseries.jl)
[![Package Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/TransitionsInTimeseries)](https://pkgs.genieframework.com?packages=TransitionsInTimeseries)

A Julia package for estimating transitions (from one dynamic regime or stable state to another) in timeseries and testing the statistical significance of found transitions. It integrates with the entire Julia ecosystem of timeseries analysis, and hence offers thousands of metrics that can indicate transitions right out of the box. It also offers a variety of analysis pipelines for identifying transitions and a variety of statistical pipelines for testing for significance.

In contrast to other existing software with similar target application, TransitionsInTimeseries.jl defines a generic interface for how to find transitions and how to test for significance. Within this interface, it is easy to expand the software in three orthogonal ways:
TransitionsInTimeseries.jl is a free and open-source software to easily analyse transitions within timeseries in a reproducible, performant, extensible and reliable way. In contrast to other existing software with similar target application, TransitionsInTimeseries.jl defines a generic interface for how to find transitions and how to test for significance. Within this interface, it is easy to expand the software in three orthogonal ways:

1. Add new indicators that work with the existing analysis pipelines for finding transitions
2. Add new analysis pipelines for finding transitions
3. Add new ways for testing whether already found transitions are significant
1. Provide the analysis pipelines with new indicators, which can be either self-written or imported from other packages. In particular, the latter offers thousands of metrics that can indicate transitions right out of the box.
2. Add new analysis pipelines for finding transitions.
3. Add new ways for significance testing.

This package is currently under active development and not yet registered in the Julia general registry. To install it, first go into package-manager mode in the Julia REPL (press `]`) and then run
TransitionsInTimeseries is a registered Julia package and can be installed by running:
```
add https://github.com/JuliaDynamics/TransitionsInTimeseries.jl
] add TransitionsInTimeseries
```

All further information is provided in the documentation, which you can either find [online](https://juliadynamics.github.io/TransitionsInTimeseries.jl/dev/) or build locally by running the `docs/make.jl` file.
Expand Down
2 changes: 1 addition & 1 deletion paper/paper.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'TransitionInTimeSeries.jl: A performant, extensible and reliable software for
title: 'TransitionsInTimeseries.jl: A performant, extensible and reliable software for
reproducible detection and prediction of transitions in timeseries'
tags:
- Julia
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/slope_change.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function estimate_changes(config::ChangesConfig, x, t = eachindex(x))
width = config.width_ind, stride = config.stride_ind
)
end
p0 = guess_initial_p(x, t)
p0 = guess_initial_p(x_indicator, t_indicator)
fit = LsqFit.curve_fit(twolinear, t_indicator, x_indicator, p0)
pbest = LsqFit.coef(fit)
a, b, c, d = pbest
Expand Down
2 changes: 1 addition & 1 deletion src/significance/slope_significance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ function significant_transitions(res::SlopeChangeResults, signif::SlopeChangeSig
moe[2] ≤ signif.moe_slope &&
moe[4] ≤ signif.moe_slope)

slopeflag = abs(res.fitparams[2] - res.fitparams[4]) > moe_slope
slopeflag = abs(res.fitparams[2] - res.fitparams[4]) > signif.slope_diff
return [moeflag && slopeflag]
end
16 changes: 12 additions & 4 deletions test/change_metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using TransitionsInTimeseries, Test, Random, Distributions
@testset "ridge regression" begin
d = Normal() # define normal distribution
m, p = 10 .* rand(Xoshiro(124), d, 2) # slope and offset parameters
t = 0:0.1:100
t = 0:1:100
x = m .* t .+ p
x_noisy = x + 0.1 .* rand(d, length(x))

Expand All @@ -12,11 +12,19 @@ using TransitionsInTimeseries, Test, Random, Distributions
m_hat_noisy = rr(x_noisy)
@test isapprox(m_hat, m, atol = 1e-5)
@test isapprox(m_hat_noisy, m, atol = 1e-2)

rr = RidgeRegressionSlope()
m_hat = rr(x)
m_hat_noisy = rr(x_noisy)
@test isapprox(m_hat, m, atol = 1e-5)
@test isapprox(m_hat_noisy, m, atol = 1e-2)
end

@testset "correlations" begin
x = 0:0.01:2π
y = sin.(x)
x = collect(1:5)
y = [1, 2, 3, 5, 4]
@test spearman(x) == 1
# TODO: expand this when kendalltau fixed
@test kendalltau(x) == 1
@test isapprox(spearman(y), cov(x, y) / (std(x) * std(y)))
@test kendalltau(y) == 0.8
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ testfile(file, testname=defaultname(file)) = @testset "$testname" begin; include
testfile("indicators.jl")
testfile("change_metrics.jl")
testfile("full_analysis.jl")
testfile("slope_change.jl")
end
13 changes: 10 additions & 3 deletions test/slope_change.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,30 @@ end

@testset "indicator" begin
y = cumsum(x)
config = SlopeChangeConfig(indicators = y -> y[2] - y[1], width_ind = 2)
config = SlopeChangeConfig(indicators = y -> y[2] - y[1], width_ind = 2, whichtime = last)
res = estimate_changes(config, y, t)
@test tcross ≈ t1[end] atol = 1e-1
a, b, c, d = res.fitparams

tcross = first(res.t_change)
@test tcross ≈ t1[end] atol = 2e-1
@test b ≈ 1 atol = 1e-1
@test d ≈ -1 atol = 1e-1
end

@testset "significance" begin
function fakedata(σ = 0.5)
x1 = σ*randn(rng, 100)
x2 = σ*randn(rng, 100) .+ range(0, 5; length = 100)
# 1st: slope = 0, 2nd: slope = 0.05
return vcat(x1, x2)
end

x = fakedata()
for (flag, σ) in zip((true, false), (0.5, 5.0))
x = fakedata(σ)
res = estimate_changes(SlopeChangeConfig(), x)
signif = SlopeChangeSignificance(; moe_slope = 0.1, moe_offset = 1.0)
signif = SlopeChangeSignificance(; moe_slope = 0.1, moe_offset = 1.0,
slope_diff = 0.03) # according to only 0.05 slope difference in data
out = significant_transitions(res, signif)
@test first(out) == flag
end
Expand Down
Loading