Skip to content

Commit 483222c

Browse files
Merge pull request #31 from LAMPSPUC/fix_docs_add_yml_format
fix docs, add yml for julia formatting
2 parents 8935f7e + 5ea7d34 commit 483222c

24 files changed

+1534
-749
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "blue" # Optional predefined style

.github/workflows/format-check.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Format suggestions
2+
on:
3+
pull_request:
4+
# this argument is not required if you don't use the `suggestion-label` input
5+
types: [ opened, reopened, synchronize, labeled, unlabeled ]
6+
jobs:
7+
code-style:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: julia-actions/julia-format@v3
11+
with:
12+
version: '1' # Set `version` to '1.0.54' if you need to use JuliaFormatter.jl v1.0.54 (default: '1')
13+
suggestion-label: 'format-suggest' # leave this unset or empty to show suggestions for all PRs

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StateSpaceLearning"
22
uuid = "971c4b7c-2c4e-4bac-8525-e842df3cde7b"
33
authors = ["andreramosfc <[email protected]>"]
4-
version = "1.0.0"
4+
version = "1.0.1"
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# StateSpaceLearning
22

3-
| **Build Status** | **Coverage** | **Documentation** |
3+
| **Build Status** | **Coverage** | **Documentation** | **CodeStyle** |
44
|:-----------------:|:-----------------:|:-----------------:|
5-
| [![ci](https://github.com/LAMPSPUC/StateSpaceLearning.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/LAMPSPUC/StateSpaceLearning.jl/actions/workflows/ci.yml) | [![codecov](https://codecov.io/gh/LAMPSPUC/StateSpaceLearning.jl/graph/badge.svg?token=VDpuXvPSI2)](https://codecov.io/gh/LAMPSPUC/StateSpaceLearning.jl) | [![](https://img.shields.io/badge/docs-latest-blue.svg)]( https://lampspuc.github.io/StateSpaceLearning.jl/)
5+
| [![ci](https://github.com/LAMPSPUC/StateSpaceLearning.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/LAMPSPUC/StateSpaceLearning.jl/actions/workflows/ci.yml) | [![codecov](https://codecov.io/gh/LAMPSPUC/StateSpaceLearning.jl/graph/badge.svg?token=VDpuXvPSI2)](https://codecov.io/gh/LAMPSPUC/StateSpaceLearning.jl) | [![](https://img.shields.io/badge/docs-latest-blue.svg)]( https://lampspuc.github.io/StateSpaceLearning.jl/) | [![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
66

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

@@ -20,10 +20,10 @@ model = StructuralModel(y)
2020
fit!(model)
2121

2222
# Point Forecast
23-
prediction = StateSpaceLearning.forecast(output, 12) #Gets a 12 steps ahead prediction
23+
prediction = StateSpaceLearning.forecast(model, 12) #Gets a 12 steps ahead prediction
2424

2525
# Scenarios Path Simulation
26-
simulation = StateSpaceLearning.simulate(output, 12, 1000) #Gets 1000 scenarios path of 12 steps ahead predictions
26+
simulation = StateSpaceLearning.simulate(model, 12, 1000) #Gets 1000 scenarios path of 12 steps ahead predictions
2727
```
2828

2929
## StructuralModel Arguments

docs/make.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ using Documenter
33
include("../src/StateSpaceLearning.jl")
44

55
# Set up to run docstrings with jldoctest
6-
DocMeta.setdocmeta!(StateSpaceLearning, :DocTestSetup, :(using StateSpaceLearning);
7-
recursive=true)
6+
DocMeta.setdocmeta!(
7+
StateSpaceLearning, :DocTestSetup, :(using StateSpaceLearning); recursive=true
8+
)
89

910
makedocs(;
10-
modules=[StateSpaceLearning],
11-
doctest=true,
12-
clean=true,
13-
checkdocs=:none,
14-
format=Documenter.HTML(; mathengine=Documenter.MathJax2()),
15-
sitename="StateSpaceLearning.jl",
16-
authors="André Ramos",
17-
pages=["Home" => "index.md", "manual.md"],)
11+
modules=[StateSpaceLearning],
12+
doctest=true,
13+
clean=true,
14+
checkdocs=:none,
15+
format=Documenter.HTML(; mathengine=Documenter.MathJax2()),
16+
sitename="StateSpaceLearning.jl",
17+
authors="André Ramos",
18+
pages=["Home" => "index.md", "manual.md"],
19+
)
1820

19-
deploydocs(; repo="github.com/LAMPSPUC/StateSpaceLearning.jl.git",
20-
push_preview=true)
21+
deploydocs(; repo="github.com/LAMPSPUC/StateSpaceLearning.jl.git", push_preview=true)

docs/src/manual.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ model = StructuralModel(y)
1616
fit!(model)
1717

1818
# Point Forecast
19-
prediction = StateSpaceLearning.forecast(output, 12) #Gets a 12 steps ahead prediction
19+
prediction = StateSpaceLearning.forecast(model, 12) #Gets a 12 steps ahead prediction
2020

2121
# Scenarios Path Simulation
22-
simulation = StateSpaceLearning.simulate(output, 12, 1000) #Gets 1000 scenarios path of 12 steps ahead predictions
22+
simulation = StateSpaceLearning.simulate(model, 12, 1000) #Gets 1000 scenarios path of 12 steps ahead predictions
2323
```
2424

2525
## StructuralModel Arguments
Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
function evaluate_SSL(initialization_df::DataFrame, results_df::DataFrame, input::Dict,
2-
outlier::Bool, α::Float64, H::Int64, sample_size::Int64,
3-
information_criteria::String)
1+
function evaluate_SSL(
2+
initialization_df::DataFrame,
3+
results_df::DataFrame,
4+
input::Dict,
5+
outlier::Bool,
6+
α::Float64,
7+
H::Int64,
8+
sample_size::Int64,
9+
information_criteria::String,
10+
)
411
normalized_y = input["normalized_train"]
512
y_train = input["train"]
613
y_test = input["test"]
@@ -10,13 +17,26 @@ function evaluate_SSL(initialization_df::DataFrame, results_df::DataFrame, input
1017
T = length(normalized_y)
1118
normalized_y = normalized_y[max(1, T - sample_size + 1):end]
1219

13-
model = StateSpaceLearning.StructuralModel(normalized_y; level=true,
14-
stochastic_level=true, trend=true,
15-
stochastic_trend=true, seasonal=true,
16-
stochastic_seasonal=true, freq_seasonal=12,
17-
outlier=outlier, ζ_ω_threshold=12)
18-
StateSpaceLearning.fit!(model; α=α, information_criteria=information_criteria, ϵ=0.05,
19-
penalize_exogenous=true, penalize_initial_states=true)
20+
model = StateSpaceLearning.StructuralModel(
21+
normalized_y;
22+
level=true,
23+
stochastic_level=true,
24+
trend=true,
25+
stochastic_trend=true,
26+
seasonal=true,
27+
stochastic_seasonal=true,
28+
freq_seasonal=12,
29+
outlier=outlier,
30+
ζ_ω_threshold=12,
31+
)
32+
StateSpaceLearning.fit!(
33+
model;
34+
α=α,
35+
information_criteria=information_criteria,
36+
ϵ=0.05,
37+
penalize_exogenous=true,
38+
penalize_initial_states=true,
39+
)
2040

2141
normalized_prediction = StateSpaceLearning.forecast(model, H)
2242
prediction = de_normalize(normalized_prediction, max_y, min_y)
@@ -25,11 +45,17 @@ function evaluate_SSL(initialization_df::DataFrame, results_df::DataFrame, input
2545
smape = sMAPE(y_test, prediction)
2646

2747
results_df = vcat(results_df, DataFrame([[mase], [smape]], [:MASE, :sMAPE]))
28-
initialization_df = vcat(initialization_df,
29-
DataFrame([[model.output.residuals_variances["ξ"]],
30-
[model.output.residuals_variances["ω"]],
31-
[model.output.residuals_variances["ε"]],
32-
[model.output.residuals_variances["ζ"]]],
33-
[, , , ]))
48+
initialization_df = vcat(
49+
initialization_df,
50+
DataFrame(
51+
[
52+
[model.output.residuals_variances["ξ"]],
53+
[model.output.residuals_variances["ω"]],
54+
[model.output.residuals_variances["ε"]],
55+
[model.output.residuals_variances["ζ"]],
56+
],
57+
[, , , ],
58+
),
59+
)
3460
return initialization_df, results_df
35-
end
61+
end

paper_tests/m4_test/m4_test.jl

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ function append_results(filepath, results_df)
2929
return CSV.write(filepath, results_df)
3030
end
3131

32-
function run_config(results_table::DataFrame, outlier::Bool, information_criteria::String,
33-
α::Float64, save_init::Bool, sample_size::Int64)
32+
function run_config(
33+
results_table::DataFrame,
34+
outlier::Bool,
35+
information_criteria::String,
36+
α::Float64,
37+
save_init::Bool,
38+
sample_size::Int64,
39+
)
3440
NAIVE_sMAPE = 14.427 #M4 Paper
3541
NAIVE_MASE = 1.063 #M4 Paper
3642

@@ -47,9 +53,16 @@ function run_config(results_table::DataFrame, outlier::Bool, information_criteri
4753
initialization_df = DataFrame()
4854
end
4955

50-
initialization_df, results_df = evaluate_SSL(initialization_df, results_df,
51-
dict_vec[i], outlier, α, H,
52-
sample_size, information_criteria)
56+
initialization_df, results_df = evaluate_SSL(
57+
initialization_df,
58+
results_df,
59+
dict_vec[i],
60+
outlier,
61+
α,
62+
H,
63+
sample_size,
64+
information_criteria,
65+
)
5366

5467
if i in [10000, 20000, 30000, 40000, 48000]
5568
!save_init ? append_results(filepath, results_df) : nothing
@@ -61,13 +74,24 @@ function run_config(results_table::DataFrame, outlier::Bool, information_criteri
6174

6275
mase = trunc(mean(results_df[:, :MASE]); digits=3)
6376
smape = trunc(mean(results_df[:, :sMAPE]); digits=3)
64-
owa = trunc(mean([mean(results_df[:, :sMAPE]) / NAIVE_sMAPE,
65-
mean(results_df[:, :MASE]) / NAIVE_MASE]); digits=3)
66-
name = outlier ? "SSL-O ($(information_criteria), α = $(α))" :
67-
"SSL ($(information_criteria), α = $(α))"
68-
results_table = vcat(results_table,
69-
DataFrame("Names" => ["$name"], "MASE" => [mase],
70-
"sMAPE" => [smape], "OWA" => [owa]))
77+
owa = trunc(
78+
mean([
79+
mean(results_df[:, :sMAPE]) / NAIVE_sMAPE,
80+
mean(results_df[:, :MASE]) / NAIVE_MASE,
81+
]);
82+
digits=3,
83+
)
84+
name = if outlier
85+
"SSL-O ($(information_criteria), α = $(α))"
86+
else
87+
"SSL ($(information_criteria), α = $(α))"
88+
end
89+
results_table = vcat(
90+
results_table,
91+
DataFrame(
92+
"Names" => ["$name"], "MASE" => [mase], "sMAPE" => [smape], "OWA" => [owa]
93+
),
94+
)
7195
return results_table
7296
end
7397

@@ -78,13 +102,15 @@ function main()
78102
for information_criteria in ["aic", "bic"]
79103
for α in vcat([0.0], collect(0.1:0.2:0.9), [1.0])
80104
@info "Running SSL with outlier = $outlier, information_criteria = $information_criteria, α = "
81-
results_table = run_config(results_table, outlier, information_criteria, α,
82-
false, 60)
105+
results_table = run_config(
106+
results_table, outlier, information_criteria, α, false, 60
107+
)
83108
end
84109
end
85110
end
86-
return CSV.write("paper_tests/m4_test/metrics_results/SSL_METRICS_RESULTS.csv",
87-
results_table)
111+
return CSV.write(
112+
"paper_tests/m4_test/metrics_results/SSL_METRICS_RESULTS.csv", results_table
113+
)
88114
end
89115

90116
function create_dirs()
@@ -114,4 +140,4 @@ create_dirs()
114140

115141
main()
116142

117-
run_config(DataFrame(), false, "aic", 0.1, true, 2794)#max sample size
143+
run_config(DataFrame(), false, "aic", 0.1, true, 2794)#max sample size

paper_tests/m4_test/prepare_data.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ function build_train_test_dict(df_train::DataFrame, df_test::DataFrame)
3636
push!(dict_vec, train_test_dict[key])
3737
end
3838
return dict_vec
39-
end
39+
end

0 commit comments

Comments
 (0)