Skip to content

Commit

Permalink
Merge pull request #268 from LAMPSPUC/fix-explanatories
Browse files Browse the repository at this point in the history
fix explanatory
  • Loading branch information
guilhermebodin authored Apr 30, 2021
2 parents b5bfa5f + a803510 commit 809189e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StateSpaceModels"
uuid = "99342f36-827c-5390-97c9-d7f9ee765c78"
authors = ["raphaelsaavedra <[email protected]>, guilhermebodin <[email protected]>, mariohsouto"]
version = "0.5.14"
version = "0.5.15"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
13 changes: 2 additions & 11 deletions src/models/basicstructural_explanatory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ function default_filter(model::BasicStructuralExplanatory)
Fl = typeof_model_elements(model)
steadystate_tol = Fl(1e-5)
a1 = zeros(Fl, num_states(model))
P1 = zeros(Fl, num_states(model), num_states(model))
P1[1:13, 1:13] = Fl(1e6) .* Matrix{Fl}(I, 13, 13)
return UnivariateKalmanFilter(a1, P1, 13, steadystate_tol)
P1 = Fl(1e6) .* Matrix{Fl}(I, num_states(model), num_states(model))
return UnivariateKalmanFilter(a1, P1, num_states(model), steadystate_tol)
end

function initial_hyperparameters!(model::BasicStructuralExplanatory)
Expand Down Expand Up @@ -127,14 +126,6 @@ function fill_model_system!(model::BasicStructuralExplanatory)
return model
end

function fill_model_filter!(filter::KalmanFilter, model::BasicStructuralExplanatory)
for i in axes(model.exogenous, 2)
filter.kalman_state.a[i + 13] = get_constrained_value(model, get_beta_name(model, i))
end
return filter
end


function fill_H_in_time(model::BasicStructuralExplanatory, H::Fl) where Fl
return fill_system_matrice_with_value_in_time(model.system.H, H)
end
Expand Down
11 changes: 1 addition & 10 deletions src/models/locallevelexplanatory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ end
function default_filter(model::LocalLevelExplanatory)
Fl = typeof_model_elements(model)
a1 = zeros(Fl, num_states(model))
# P1 is identity on sigma \eta and 0 otherwise.
P1 = zeros(Fl, num_states(model), num_states(model))
P1[1] = Fl(1e6)
P1 = Fl(1e6) .* Matrix{Fl}(I, num_states(model), num_states(model))
steadystate_tol = Fl(1e-5)
return UnivariateKalmanFilter(a1, P1, num_states(model), steadystate_tol)
end
Expand Down Expand Up @@ -110,13 +108,6 @@ function fill_model_system!(model::LocalLevelExplanatory)
return model
end

function fill_model_filter!(filter::KalmanFilter, model::LocalLevelExplanatory)
for i in axes(model.exogenous, 2)
filter.kalman_state.a[i + 1] = get_constrained_value(model, get_beta_name(model, i))
end
return filter
end

function fill_H_in_time(model::LocalLevelExplanatory, H::Fl) where Fl
return fill_system_matrice_with_value_in_time(model.system.H, H)
end
Expand Down
7 changes: 2 additions & 5 deletions test/models/basicstructural_explanatory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
# For a fixed forecasting explanatory the variance must not decrease
forec = forecast(model, ones(10, 2))
@test monotone_forecast_variance(forec)
kf = kalman_filter(model);
ks = kalman_smoother(model);
a = get_predictive_state(kf)
@test a[1, 14] a[end, 14] atol=1e-3
@test a[1, 15] a[end, 15] atol=1e-3
kf = kalman_filter(model)
ks = kalman_smoother(model)
@test_throws AssertionError simulate_scenarios(model, 10, 1000, ones(5, 2))
scenarios = simulate_scenarios(model, 10, 1000, ones(10, 2))
test_scenarios_adequacy_with_forecast(forec, scenarios)
Expand Down
3 changes: 0 additions & 3 deletions test/models/locallevelexplanatory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,4 @@
@test monotone_forecast_variance(forec)
kf = kalman_filter(model)
ks = kalman_smoother(model)
a = get_predictive_state(kf)
@test a[1, 2] a[end, 2] atol=1e-3
@test a[1, 3] a[end, 3] atol=1e-3
end

2 comments on commit 809189e

@guilhermebodin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/35757

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.15 -m "<description of version>" 809189e704ca51277935dd9fac121443a3839e79
git push origin v0.5.15

Please sign in to comment.