https://github.com/dmetivie/smoothperiodicstatsmodels.jl
A Julia package for time series and other models with smoothly varying periodic parameters
Science Score: 49.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
Found .zenodo.json file -
✓DOI references
Found 1 DOI reference(s) in README -
✓Academic publication links
Links to: springer.com -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.1%) to scientific vocabulary
Keywords
Repository
A Julia package for time series and other models with smoothly varying periodic parameters
Basic Info
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
SmoothPeriodicStatsModels
This package is primarily built to be an extension of the StochasticWeatherGenerators package. See the tutorial for an example of usage.
It builds several smooth versions of statistical models for time series, currently including:
- AR(1) Auto-Regressive model of order 1
- Mixture Models
- Auto-Regressive Periodic Hidden Markov Model. For now, it only has Bernoulli mixture emission distributions, i.e., conditionally independent distributions.
Smooth means that temporal coefficients of the models e.g., $p(t)\in [0,1]$ for Bernoulli parameter and $t\in [1,T]$ have a periodic functional form to enforce smoothness i.e., $p(t)\simeq p(t+1)$. Note that the package PeriodicHiddenMarkovModels.jl also deals with Periodic HMM, but right now, it does not enforce smoothness; hence if you don't have many observations, you can have $p(t)$ very different from $p(t+1)$. Moreover, this causes identifiability issues of the hidden states.
The HMM part of this package could be moved at some point to PeriodicHiddenMarkovModels.jl, making use under the hood of the very nice and flexible HiddenMarkovModels.jl package.
This is inspired by seasonal Hidden Markov Models; see A. Touron (2019) and used in the paper Interpretable Seasonal Multisite Hidden Markov Model for stochastic rain generation in France.
Example
This example shows how to use the ARPeriodicHMM model, which is a periodic HMM with multivariate Bernoulli emission distributions of dimension $D=6$ and autoregressive dependence on past observations. This model assumes conditional independence, i.e., given the hidden states and the past observations, the multivariate Bernoulli distribution is independent (conditional independence),
math
\mathbb{P}(Y_n = y_t \mid Z_n = k, Y_{n-1} = y_{n-1}) = \prod_{j=1}^D \mathbb{P}\left(Y_{n}^{(j)} = y_{n}^{(j)}\mid Z_n = k, Y_{n-1}^{(j)} = y_{n-1}^{(j)}\right).
Under the hood, to deal with arbitrary autoregressive orders, the past observations are encoded in a variable $H$ of dimension $D \times (2^p)$, where $p$ is the autoregressive order (see the paper for a more precise definition).
Set up
julia
using SmoothPeriodicStatsModels
using Random
```julia Random.seed!(2020) K = 3 # Number of hidden states T = 11 # Period N = 49586 # Length of observation D = 6 # Dimension of observed variables autoregressiveorder = 1
sizeorder = 2^autoregressiveorder degreeofP = 1 sizedegreeofP = 2*degreeof_P + 1
transθ = 4*(rand(K, K - 1, sizedegreeofP) .- 1/2) Bernoulliθ = 2*(rand(K, D, sizeorder, sizedegreeofP) .- 1/2) hmm = Trig2ARPeriodicHMM([1/3, 1/6, 1/2], transθ, Bernoulli_θ, T) ```
Simulations
julia
z_ini = 1
y_past = rand(Bool, autoregressive_order, D)
n2t = SmoothPeriodicStatsModels.n_to_t(N,T)
z, y = rand(hmm, n2t; y_ini=y_past, z_ini=z_ini, seq=true)
Fit
```julia transθguess = rand(K, K-1, sizedegreeofP) Bernoulliθguess = zeros(K, D, sizeorder, sizedegreeofP) transθguess[:,:,1] .= transθ[:,:,1] # cheating on initial guess to recover very good MLE maxima Bernoulliθguess[:,:,:,1] = Bernoulliθ[:,:,:,1] hmmguess = Trig2ARPeriodicHMM([1/4, 1/4, 1/2], transθguess, Bernoulliθguess, T)
@time "FitMLE SHMM (Baum Welch)" hmmfit, θqfit, θyfit, hist, histoA, histoB = fitmle(hmmguess, transθguess, Bernoulliθguess, y, ypast, maxiter=10000, robust=true; display=:iter, silence=true, tol=1e-3, θ_iters=true, n2t=n2t);
EM converged in 317 iterations, logtot = -194299.4177103428
FitMLE SHMM (Baum Welch): 72.532794 seconds (344.65 M allocations: 27.641 GiB, 3.59% gc time)
```
Plots
Code for the plot
```julia using LaTeXStrings, Plots using Distributions: succprob default(fontfamily="Computer Modern", linewidth=2, label=nothing, grid=true, framestyle=:default, legendfontsize=14, foreground_color_legend=nothing, background_color_legend=nothing, tickfontsize=14, xlabelfontsize=14, ylabelfontsize=14) ``` ```julia begin pA = [plot() for k in 1:K] for k in 1:K [plot!(pA[k], hmm.A[k, l, :], c=l, label=L"Q_{%$(k)\to %$(l)}", legend=:topleft) for l in 1:K] [plot!(pA[k], hmm_fit.A[k, l, :], c=l, label=:none, legend=:topleft, s = :dash) for l in 1:K] hline!(pA[k], [0.5], c=:black, label=:none, s=:dot) ylims!(0,1) xlabel!(pA[k], L"t") end pallA = plot(pA..., size=(1000, 500), bottom_margin=3Plots.mm) end ``` ```julia begin mm = 1 # H = 1 <=> {Y_{t-1} = 0} pB = [plot() for j in 1:D] for j in 1:D [plot!(pB[j], succprob.(hmm.B[k, :, j, mm]), c=k, label=:none) for k in 1:K] [plot!(pB[j], succprob.(hmm_fit.B[k, :, j, mm]), c=k, label=:none, s = :dash) for k in 1:K] hline!(pB[j], [0.5], c=:black, label=:none, s=:dot) ylims!(pB[j], (0, 1)) xlabel!(pB[j], L"t") annotate!(pB[j], (0.5, 0.93), L"j=%$(j)") j==2 ? title!(pB[j], L"\mathbb{P}(Y_t^{(j)}=1|Z=k, Y_{t-1}^{(j)} = 0)") : nothing end pallB = plot(pB..., size=(1000, 500), bottom_margin=3Plots.mm) end begin mm = 2 # H = 2 <=> {Y_{t-1} = 1} pB = [plot() for j in 1:D] for j in 1:D [plot!(pB[j], succprob.(hmm.B[k, :, j, mm]), c=k, label=:none) for k in 1:K] [plot!(pB[j], succprob.(hmm_fit.B[k, :, j, mm]), c=k, label=:none, s = :dash) for k in 1:K] hline!(pB[j], [0.5], c=:black, label=:none, s=:dot) ylims!(pB[j], (0, 1)) xlabel!(pB[j], L"t") j==2 ? title!(pB[j], L"\mathbb{P}(Y_t^{(j)}=1|Z=k, Y_{t-1}^{(j)} = 1)") : nothing annotate!(pB[j], (0.5, 0.93), L"j=%$(j)") end pallB = plot(pB..., size=(1000, 500), bottom_margin=3Plots.mm) end ```Transition matrix:
Emission distributions:
Owner
- Name: David Métivier
- Login: dmetivie
- Kind: user
- Location: Montpellier, France
- Company: INRAe, MISTEA
- Website: http://www.cmap.polytechnique.fr/~david.metivier/
- Repositories: 5
- Profile: https://github.com/dmetivie
I am a research scientist with a physics background. Now, I do statistics to tackle environmental, and climate change problems. Julia enthusiast!
GitHub Events
Total
- Delete event: 1
- Issue comment event: 2
- Push event: 8
- Pull request event: 7
- Create event: 1
Last Year
- Delete event: 1
- Issue comment event: 2
- Push event: 8
- Pull request event: 7
- Create event: 1
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 1
- Total pull requests: 23
- Average time to close issues: less than a minute
- Average time to close pull requests: 2 months
- Total issue authors: 1
- Total pull request authors: 3
- Average comments per issue: 1.0
- Average comments per pull request: 0.0
- Merged pull requests: 16
- Bot issues: 0
- Bot pull requests: 22
Past Year
- Issues: 1
- Pull requests: 7
- Average time to close issues: less than a minute
- Average time to close pull requests: 2 days
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 1.0
- Average comments per pull request: 0.0
- Merged pull requests: 7
- Bot issues: 0
- Bot pull requests: 7
Top Authors
Issue Authors
- JuliaTagBot (1)
Pull Request Authors
- github-actions[bot] (15)
- dependabot[bot] (7)
- dmetivie (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- julia 4 total
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
juliahub.com: SmoothPeriodicStatsModels
A Julia package for time series and other models with smoothly varying periodic parameters
- Documentation: https://docs.juliahub.com/General/SmoothPeriodicStatsModels/stable/
- License: MIT
-
Latest release: 2.0.3
published 9 months ago
Rankings
Dependencies
- actions/checkout v3 composite
- julia-actions/cache v1 composite
- julia-actions/julia-buildpkg v1 composite
- julia-actions/julia-runtest v1 composite
- julia-actions/setup-julia v1 composite
- JuliaRegistries/TagBot v1 composite