https://github.com/baggepinnen/singularspectrumanalysis.jl
A package for performing Singular Spectrum Analysis (SSA) and time-series decomposition
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.0%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
A package for performing Singular Spectrum Analysis (SSA) and time-series decomposition
Basic Info
Statistics
- Stars: 65
- Watchers: 5
- Forks: 5
- Open Issues: 4
- Releases: 11
Topics
Metadata Files
README.md
SingularSpectrumAnalysis
A package for performing Singular Spectrum Analysis (SSA) https://en.wikipedia.org/wiki/Singularspectrumanalysis
Simple Usage
The example below creates a simulated signal that has two strong seasonal components. The main entry function is analyze(y,L) that returns the trend and seasonal components. y is the signal to decompose and L is a window length to use for the internal embedding.
```julia
using SingularSpectrumAnalysis, Plots
generate some data
L = 20 # Window length K = 100 N = KL; # number of datapoints t = 1:N; # Time vector T = 20; # period of main oscillation y = sin.(2pi/Tt); # Signal y .+= (0.5sin.(2pi/T4t)).^2 # Add another frequency e = 0.1randn(N); # Add some noise yn = y+e;
plot(ys)
yt, ys = analyze(yn, L, robust=true) # trend and seasonal components
plot(yt, lab="Trend")
plot!(ys, lab="Season")
``
Therobust` keyword makes the analysis robust against large, sparse outliers, at the expense of longer computational time.
ESPRIT
esprit(x, L, r; fs=1, robust=false)Estimatesr(positive) frequencies present in signalxusing a lag-correlation matrix of sizeL.
Advanced usage
Internally a Hankel matrix is formed and the SVD of this is calculated. The singular values of the SVD can be plotted to manually determine which singular value belongs to the trend, and which pairs belong to seasonal components (these are always pairs).
julia
USV = hsvd(yn,L,robust=false) # Perform svd on the trajectory matrix, robust uses a robust version of svd, resistant to outliers
plot(USV, cumulative=false) # Plot normalized singular values
```julia seasonalgroupings = [1:2, 4:5] # Determine pairs of singular values corresponding to seasonal components trendi = 3 # If some singular value lacks a buddy, this is a trend component
trendi, seasonalgroupings = autogroup(USV) # This uses a heuristic
pairplot(USV,seasonalgroupings) # plot phase plots for all seasonal components yrt, yrs = reconstruct(USV, trendi, seasonal_groupings) # Reconstruct the underlying signal without noise, based on all identified components with significant singular values yr = sum([yrt yrs],dims = 2) # Form full reconstruction plot([y ys yr], lab=["y" "ys" "ys" "yr"]) ```
Forecasting
We provide the function fit_trend(yt, order) to fit an n:th order polynomial to the trend:
julia
yt, ys = analyze(yn, L)
A,x = fit_trend(yt, 1)
This returns the regressor matrix A and the polynomial coefficients x. This fit can be used to forecast the trend. To forecast the seasonal components, we make use of the package ControlSystemIdentification.jl to fit AR(na) models. We create a simulated signal to test with:
julia
using Random
Random.seed!(0)
L = 20
K = 10
N = K*L;
t = 1:N;
T = 20;
y = sin.(2pi/T*t); # Add seasons
y .+= (0.5sin.(2pi/T*4*t)).^2 # Add seasons
y .+= LinRange(0,1,N) # Add trend
e = 0.1randn(N);
yn = y+e; # Add noise
Next, we use SSA to find the trend and the seasonal components
julia
yt, ys = analyze(yn, L) # trend and seasons
using ControlSystemIdentification
pd = PredictionData(yt, ys, trend_order=1, ar_order=2)
yth = trend(pd)
ysh = seasons(pd)
Next, we visualize the trends and seasonal components estimated by both SSA and AR models.
julia
plot(ys, layout=size(ys,2), lab="SSA", title="Estimated seasonal components")
plot!(ysh, lab="AR")
julia
plot(yt, lab="SSA", title="Estimated trend")
plot!(yth, lab="Polyfit")
julia
yr = yt+sum(ys, dims=2)
plot(yn, lab="Measured", title="Full reconstructions")
plot!(yr, lab="SSA")
plot!(+(yth, ysh...), subplot=1, lab="AR", l=(:dash,))
To perform n-step prediction, use the function pred:
julia
pd = pred(pd,2) # Predict two steps
yth = trend(pd)
ysh = seasons(pd)
The example above is implemented in forecast.jl.
Missing data / outliers
See the keyword argument robust. The robust estimation is handled by TotalLeastSquares.jl which performs a robust PCA of the Hankel matrix. This factorization handles large but sparse outliers very well. To indicate that a value is missing, you can set it to some large value that is very far from the other values and it will be identified as an outlier by the robust factorization. To obtain the inferred values for the missing data, call the low-level function directly
julia
X = hankel(y,L) # Form trajectory matrix
X̂, E = rpca(X)
ŷ = unhankel(X̂)
Where ŷ is a clean version of the signal. The sparse matrix E contains the estimated noise values. See also function lowrankfilter which packages this procedure.
See further documentation and examples here.
Advanced low-level usage
See the implementation of functions hsvd and reconstruct
Reading
See http://www.jds-online.com/files/JDS-396.pdf for an easy-to-read introduction to SSA
Owner
- Name: Fredrik Bagge Carlson
- Login: baggepinnen
- Kind: user
- Location: Lund, Sweden
- Website: baggepinnen.github.io
- Twitter: baggepinnen
- Repositories: 59
- Profile: https://github.com/baggepinnen
Control systems, system identification, signal processing and machine learning
GitHub Events
Total
- Watch event: 3
- Fork event: 1
Last Year
- Watch event: 3
- Fork event: 1
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 64
- Total Committers: 7
- Avg Commits per committer: 9.143
- Development Distribution Score (DDS): 0.469
Top Committers
| Name | Commits | |
|---|---|---|
| Fredrik Bagge Carlson | b****n@g****m | 34 |
| Fredrik Bagge Carlson | c****b@u****g | 23 |
| github-actions[bot] | 4****]@u****m | 3 |
| Elliot Saba | s****t@g****m | 1 |
| Tony Kelman | t****y@k****t | 1 |
| H.F | J****L@u****m | 1 |
| Julia TagBot | 5****t@u****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 13
- Total pull requests: 13
- Average time to close issues: 24 days
- Average time to close pull requests: 13 days
- Total issue authors: 12
- Total pull request authors: 6
- Average comments per issue: 4.23
- Average comments per pull request: 0.69
- Merged pull requests: 10
- Bot issues: 0
- Bot pull requests: 6
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 3.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- Roh-codeur (2)
- StefanPofahl (2)
- mthelm85 (1)
- KevinG1002 (1)
- aka-commit (1)
- finmod (1)
- rustyconover (1)
- PBSoundy (1)
- daxiawj (1)
- jane2L (1)
- JuliaTagBot (1)
- baggepinnen (1)
Pull Request Authors
- github-actions[bot] (6)
- baggepinnen (3)
- JiangXL (1)
- tkelman (1)
- staticfloat (1)
- JuliaTagBot (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- julia 1 total
- Total dependent packages: 1
- Total dependent repositories: 0
- Total versions: 10
juliahub.com: SingularSpectrumAnalysis
A package for performing Singular Spectrum Analysis (SSA) and time-series decomposition
- Documentation: https://docs.juliahub.com/General/SingularSpectrumAnalysis/stable/
- License: MIT
-
Latest release: 0.5.1
published over 3 years ago
Rankings
Dependencies
- julia-actions/setup-julia latest composite
- JuliaRegistries/TagBot v1 composite
- actions/checkout v2 composite
- codecov/codecov-action v1 composite
- julia-actions/julia-processcoverage v1 composite
- julia-actions/julia-runtest latest composite
- julia-actions/setup-julia latest composite