Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
abcsds committed Dec 27, 2024
1 parent 9ec7ffd commit 3d1d3f2
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
matrix:
version:
- '1.11'
- '1.6'
- '1'
- 'pre'
os:
- ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /tmp
COPY . /tmp

# Preinstall the dependencies in the global environment
RUN julia --project=. -e "using Pkg; Pkg.instantiate(); Pkg.precompile()"
RUN julia --project=. -e "using Pkg; Pkg.instantiate(); Pkg.precompile(); Pkg.test();"

# Set the default working directory for the container
WORKDIR /workdir
Expand Down
5 changes: 1 addition & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name = "DFA"
uuid = "68b8aea9-720c-4092-afc2-f92dd305eeec"
uuid = "2556a7c9-976d-46bb-b923-66b4a6f0a5bd"
authors = ["afternone", "Alberto Barradas <[email protected]>"]
version = "v1.0.0-DEV"

[deps]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
Statistics = "1.11.1"
julia = "1"

[extras]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ scales, fluc = dfa(x, boxmax=1000, boxmin=4, boxratio=1.2, overlap=0.5)
```
To estimates the scaling exponent:
```
intercept, α = polyfit(log10(scales), log10(fluc)) # α is scaling exponent
intercept, α = polyfit(log10.(scales), log10.(fluc)) # α is scaling exponent
```
To plot F(n):
```
Expand All @@ -53,8 +53,8 @@ scatter(scales, fluc, "o")
```
To plot F(n) with fitted line:
```
log_scales = log10(scales)
plot(log_scales, log10(fluc), "o", log_scales, α.*log_scales.+intercept)
log_scales = log10.(scales)
plot(log_scales, log10.(fluc), "o", log_scales, α.*log_scales.+intercept)
```

## References
Expand Down
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[deps]
DFA = "2556a7c9-976d-46bb-b923-66b4a6f0a5bd"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
59 changes: 50 additions & 9 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
CurrentModule = DFA
```

<!-- '''@setup
using Random: seed!
seed!(137)
''' -->
# DFA

Documentation for [DFA](https://github.com/abcsds/DFA.jl).
Expand All @@ -20,29 +24,35 @@ pkg> add https://github.com/abcsds/DFA.jl

## Usage

### Basic Example
### Basic usage

We'll perform a DFA and estimate the scaling exponent for a random time series.

```julia
using DFA

x = rand(10000)

scales, fluc = dfa(x)
```
log_scales = log10.(scales)
log_fluc = log10.(fluc)
intercept, α = polyfit(log_scales, log_fluc)
α

### Advanced Example
# output

To perform a DFA on `x` with `boxmax=1000`, `boxmin=4`, `boxratio=1.2`, `overlap=0.5`:
0.49706362711274654

```julia
scales, fluc = dfa(x, boxmax=1000, boxmin=4, boxratio=1.2, overlap=0.5)
```


To estimate the scaling exponent:

```julia
intercept, α = polyfit(log10(scales), log10(fluc)) # α is the scaling exponent
α

# output

0.49706362711274654
```

To plot F(n):
Expand All @@ -61,6 +71,37 @@ plot(log_scales, log10(fluc), seriestype=:scatter, label="DFA")
plot!(log_scales, α .* log_scales .+ intercept, label="Fit")
```


### Advanced Example

To perform a DFA on heart rate variability data `x`, two different box sizes are commonly used for extracting two coefficients, α1 and α2. The first box size is 4 ≤ n ≤ 16, and the second box size is 16 ≤ n ≤ 64. The scaling exponent α1 is used to quantify the short-term correlation properties of the time series, while α2 is used to quantify the long-term correlation properties of the time series.

```julia
using HTTP

url = "https://physionet.org/files/rr-interval-healthy-subjects/1.0.0/000.txt"
hrv = parse.(Float64, filter!(e->e!="", split(String(HTTP.get(url).body), r"[^\d.]")))
x = hrv

scales, fluc = dfa(x, boxmax=64, boxmin=4, boxratio=2, overlap=0.0 )
log_scales = log10.(scales)
log_fluc = log10.(fluc)
intercept, α1 = polyfit(log_scales, log_fluc)

scales, fluc = dfa(x, boxmax=16, boxmin=4, boxratio=2, overlap=0.0 )
log_scales = log10.(scales)
log_fluc = log10.(fluc)
intercept, α2 = polyfit(log_scales, log_fluc)

println("Physionet rr-interval-healthy-subjects/1.0.0/000 α1: $α1")
println("Physionet rr-interval-healthy-subjects/1.0.0/000 α2: $α2")
(α1, α2)

# output

(1.096221478218021, 1.0773259128065056)
```

## Functions

### `dfa`
Expand Down Expand Up @@ -105,5 +146,5 @@ e220.
```

```@autodocs
Modules = [DFA Plots]
Modules = [DFA]
```
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SignalAnalysis = "df1fea92-c066-49dd-8b36-eace3378ea47"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
18 changes: 9 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import HTTP
intercept, α = polyfit(log10.(scales), log10.(fluc))
@test intercept -0.645847540086 atol=1e-12
@test α 0.509373252211 atol=1e-12
println("Simple Normal distribution: $intercept, ")
# println("Simple Normal distribution: $intercept, $α")
end

# Test wite noise
Expand All @@ -35,7 +35,7 @@ import HTTP
intercept, α = polyfit(log10.(scales), log10.(fluc))
@test intercept -1.1746914232962604 atol=1e-12
@test α 0.5237515930298794 atol=1e-12
println("Uniform distribution: $intercept, ")
# println("Uniform distribution: $intercept, $α")
end

# Test random walk / brownian motion
Expand All @@ -47,7 +47,7 @@ import HTTP
intercept, α = polyfit(log10.(scales), log10.(fluc))
@test intercept -1.4091958750176548 atol=1e-12
@test α 1.5477976383996574 atol=1e-12
println("Brownian motion: $intercept, ")
# println("Brownian motion: $intercept, $α")
end

# Test pink noise
Expand All @@ -59,7 +59,7 @@ import HTTP
intercept, α = polyfit(log10.(scales), log10.(fluc))
@test intercept -1.2717558431479488 atol=1e-12
@test α 1.0161132560075559 atol=1e-12
println("Pink noise: $intercept, ")
# println("Pink noise: $intercept, $α")
end

# Test wite noise
Expand All @@ -72,7 +72,7 @@ import HTTP
intercept, α = polyfit(log10.(scales), log10.(fluc))
@test intercept 0.10576185464214086 atol=1e-12
@test α 1.5734083037634519 atol=1e-12
println("Under scale (300) and translate(sin(2πx/100)): $intercept, ")
# println("Under scale (300) and translate(sin(2πx/100)): $intercept, $α")
end

@testset "DFA.transforms.translate" begin
Expand All @@ -83,7 +83,7 @@ import HTTP
intercept, α = polyfit(log10.(scales), log10.(fluc))
@test intercept -2.6458475400862542 atol=1e-12
@test α 0.5093732522114474 atol=1e-12
println("Under translate(300): $intercept, ")
# println("Under translate(300): $intercept, $α")
end
end

Expand Down Expand Up @@ -160,7 +160,7 @@ import HTTP
intercept, α = polyfit(log_scales, log_fluc)
@test intercept 0.6476733308961827
@test α 1.0377546755013551 atol=1e-12
println("Physionet rr-interval-healthy-subjects/1.0.0/000: $intercept, ")
# println("Physionet rr-interval-healthy-subjects/1.0.0/000: $intercept, $α")

Plots.plot(log_scales, log_fluc, label="DFA", xlabel="Scale Log10", ylabel="Fluctuation Log10", seriestype=:scatter)
Plots.plot!(log_scales, intercept .+ α .* log_scales, label="DFA Fit")
Expand Down Expand Up @@ -195,8 +195,8 @@ import HTTP
Plots.plot!(log_scales, intercept .+ α1 .* log_scales, label="DFA Fit α1")
Plots.plot!(log_scales, intercept .+ α2 .* log_scales, label="DFA Fit α2")
Plots.savefig("DFA.png")
println("Physionet rr-interval-healthy-subjects/1.0.0/000 α1: $α1")
println("Physionet rr-interval-healthy-subjects/1.0.0/000 α2: $α2")
# println("Physionet rr-interval-healthy-subjects/1.0.0/000 α1: $α1")
# println("Physionet rr-interval-healthy-subjects/1.0.0/000 α2: $α2")

end
end

0 comments on commit 3d1d3f2

Please sign in to comment.