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

📝add outer docs #8

Merged
merged 1 commit into from
Nov 22, 2023
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ using StateSpaceModels
airp = CSV.File(StateSpaceModels.AIR_PASSENGERS) |> DataFrame
airpassengers = (airp.passengers).*1.0
log_air_passengers = log.(airpassengers)
steps_ahead = 30

log_air_passengers[60:72] .= NaN

Expand Down
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
25 changes: 25 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Documenter
using StateSpaceLearning

# Set up to run docstrings with jldoctest
DocMeta.setdocmeta!(
StateSpaceLearning, :DocTestSetup, :(using StateSpaceLearning); recursive=true
)

makedocs(;
modules=[StateSpaceLearning],
doctest=true,
clean=true,
format=Documenter.HTML(mathengine=Documenter.MathJax2()),
sitename="StateSpaceLearning.jl",
authors="André Ramos",
pages=[
"Home" => "index.md",
"manual.md"
],
)

deploydocs(
repo="github.com/LAMPSPUC/StateSpaceLearning.jl.git",
push_preview = true
)
20 changes: 20 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```@raw html
<div style="width:100%; height:150px;border-width:4px;border-style:solid;padding-top:25px;
border-color:#000;border-radius:10px;text-align:center;background-color:#99DDFF;
color:#000">
<h3 style="color: black;">Star us on GitHub!</h3>
<a class="github-button" href="https://github.com/LAMPSPUC/StateSpaceLearning.jl" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star LAMPSPUC/StateSpaceLearning.jl on GitHub" style="margin:auto">Star</a>
<script async defer src="https://buttons.github.io/buttons.js"></script>
</div>
```

# StateSpaceLearning.jl Documentation

StateSpaceLearning.jl is a package for modeling and forecasting time series in a high-dimension regression framework.

## Installation

This package is registered so you can simply `add` it using Julia's `Pkg` manager:
```julia
pkg> add StateSpaceLearning
```
117 changes: 117 additions & 0 deletions docs/src/manual.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Manual

## Quick Start Guide

Although StateSpaceLearning.jl has a lot of functionalities, different models and interfaces
users usuallly just want to fit a model and analyse the residuals, components and make some forecasts.
The following code is a quick start to perform these tasks

```julia
using StateSpaceLearning
using Plots

y = randn(100)

output = StateSpaceLearning.fit_model(y)

prediction = StateSpaceLearning.forecast(output, 12)

plot(y, w=2 , color = "Black", lab = "Historical", legend = :outerbottom)
plot!(output.fitted, w=2 , color = "Black", lab = "Fit In Sample", legend = :outerbottom)
plot!(vcat(ones(output.T).*NaN, prediction), lab = "Forcast", w=2, color = "blue")

```
### Completion of missing values
Quick example of completion of missing values for the air passengers time-series (artificial NaN values are added to the original time-series).

```julia

y = rand(144)

y[60:72] .= NaN

output = StateSpaceLearning.fit_model(y)

completed_values = output.fitted[60:72]

```

### Component extraction
Quick example of component extraction in a time series

```julia
using CSV
using DataFrames
using Plots
using StateSpaceModels

airp = CSV.File(StateSpaceModels.AIR_PASSENGERS) |> DataFrame
log_air_passengers = log.(airp.passengers)

output = StateSpaceLearning.fit_model(log_air_passengers)

μ₁ = output.components["μ₁"]["Values"]
ν₁ = output.components["ν₁"]["Values"]
γ₁ = output.components["γ₁"]["Values"]
ξ = output.components["ξ"]["Values"]
ζ = output.components["ζ"]["Values"]
ω = output.components["ω"]["Values"]

```

### Models

The package provides a variaty of pre-defined models. If there is any model that you wish was in the package, feel free to open an issue or pull request.

### Basic Structural Model
The basic structural state-space model consists of a trend (level + slope) and a seasonal
component. It is defined by:

```math
\begin{gather*}
\begin{aligned}
y_{t} &= \mu_{t} + \gamma_{t} + \varepsilon_{t} \quad &\varepsilon_{t} \sim \mathcal{N}(0, \sigma^2_{\varepsilon})\\
\mu_{t+1} &= \mu_{t} + \nu_{t} + \xi_{t} \quad &\xi_{t} \sim \mathcal{N}(0, \sigma^2_{\xi})\\
\nu_{t+1} &= \nu_{t} + \zeta_{t} \quad &\zeta_{t} \sim \mathcal{N}(0, \sigma^2_{\zeta})\\
\gamma_{t+1} &= -\sum_{j=1}^{s-1} \gamma_{t+1-j} + \omega_{t} \quad & \omega_{t} \sim \mathcal{N}(0, \sigma^2_{\omega})\\
\end{aligned}
\end{gather*}
```

#### References
* Durbin, James, & Siem Jan Koopman. (2012). "Time Series Analysis by State Space Methods: Second Edition." Oxford University Press.


### Local Level Model

The local level model is defined by:
```math
\begin{gather*}
\begin{aligned}
y_{t} &= \mu_{t} + \varepsilon_{t} \quad \varepsilon_{t} \sim \mathcal{N}(0, \sigma^2_{\varepsilon})\\
\mu_{t+1} &= \mu_{t} + \eta_{t} \quad \eta_{t} \sim \mathcal{N}(0, \sigma^2_{\eta})\\
\end{aligned}
\end{gather*}
```
#### References
* Durbin, James, & Siem Jan Koopman. (2012). "Time Series Analysis by State Space Methods: Second Edition." Oxford University Press. pp. 9

### Local Linear Trend
The linear trend model is defined by:
```math
\begin{gather*}
\begin{aligned}
y_{t} &= \mu_{t} + \gamma_{t} + \varepsilon_{t} \quad &\varepsilon_{t} \sim \mathcal{N}(0, \sigma^2_{\varepsilon})\\
\mu_{t+1} &= \mu_{t} + \nu_{t} + \xi_{t} \quad &\xi_{t} \sim \mathcal{N}(0, \sigma^2_{\xi})\\
\nu_{t+1} &= \nu_{t} + \zeta_{t} \quad &\zeta_{t} \sim \mathcal{N}(0, \sigma^2_{\zeta})\\
\end{aligned}
\end{gather*}
```
#### References
* Durbin, James, & Siem Jan Koopman. (2012). "Time Series Analysis by State Space Methods:
Second Edition." Oxford University Press. pp. 44

### Implementing a custom model

Users are able to implement any custom user-defined model. For that, it is necessary to modify "model_utils.jl" file. More specificly, it is necessary to modify "create_X" function to be able to create the corresponding high dimension regression matrix and "get_components_indexes" function to assess the correct compenents in the new proposed model.

Loading