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

WIP: Fix single precision #197

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/models/arima.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function default_filter(model::ARIMA)
num_arma_states = max(model.order.p, model.order.q + 1)
r = model.order.d + num_arma_states
a1 = zeros(Fl, r)
P1 = 1e6 .* Matrix{Fl}(I, r, r)
P1 = Fl(1e6) .* Matrix{Fl}(I, r, r)
skip_llk_instants = model.order.d
steadystate_tol = Fl(1e-5)
return UnivariateKalmanFilter(a1, P1, skip_llk_instants, steadystate_tol)
Expand Down Expand Up @@ -303,4 +303,4 @@ function reinstantiate(model::ARIMA, y::Vector{Fl}) where Fl
order = (model.order.p, model.order.d, model.order.q)
return ARIMA(y, order)
end
has_exogenous(::ARIMA) = false
has_exogenous(::ARIMA) = false
4 changes: 2 additions & 2 deletions src/models/basicstructural.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function default_filter(model::BasicStructural)
Fl = typeof_model_elements(model)
steadystate_tol = Fl(1e-5)
a1 = zeros(Fl, num_states(model))
P1 = 1e6 .* Matrix{Fl}(I, num_states(model), num_states(model))
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::BasicStructural)
Expand Down Expand Up @@ -87,4 +87,4 @@ end
function reinstantiate(model::BasicStructural, y::Vector{Fl}) where Fl
return BasicStructural(y, model.seasonality)
end
has_exogenous(::BasicStructural) = false
has_exogenous(::BasicStructural) = false
2 changes: 1 addition & 1 deletion src/models/damped_lineartrend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
function default_filter(::DampedLinearTrend{Fl}) where Fl
steadystate_tol = 1e-5
raphaelsaavedra marked this conversation as resolved.
Show resolved Hide resolved
a1 = zeros(Fl, 2)
P1 = 1e6 .* Matrix{Fl}(I, 2, 2)
P1 = Fl(1e6) .* Matrix{Fl}(I, 2, 2)
return UnivariateKalmanFilter(a1, P1, 0, steadystate_tol)
end
function initial_hyperparameters!(model::DampedLinearTrend{Fl}) where Fl
Expand Down
2 changes: 1 addition & 1 deletion src/models/locallineartrend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function default_filter(model::LocalLinearTrend)
Fl = typeof_model_elements(model)
steadystate_tol = 1e-5
raphaelsaavedra marked this conversation as resolved.
Show resolved Hide resolved
a1 = zeros(Fl, 2)
P1 = 1e6 .* Matrix{Fl}(I, 2, 2)
P1 = Fl(1e6) .* Matrix{Fl}(I, 2, 2)
return UnivariateKalmanFilter(a1, P1, 2, steadystate_tol)
end
function initial_hyperparameters!(model::LocalLinearTrend)
Expand Down
11 changes: 9 additions & 2 deletions test/models/basicstructural.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
log_air_passengers = log.(air_passengers.passengers)

@test has_fit_methods(BasicStructural)

model = BasicStructural(log_air_passengers, 12)
fit!(model)
# Runned on Python statsmodels
Expand All @@ -15,4 +15,11 @@
# simualting
scenarios = simulate_scenarios(model, 10, 10_000)
test_scenarios_adequacy_with_forecast(forec, scenarios)
end

@testset "Basic structural with single precision" begin
log_ap32 = Float32.(log_air_passengers)
model = BasicStructural(log_ap32, 12)
@test model.system.Z == Float32[1.0; 0.0; 1.0; zeros(10)]
fit!(model)
end
end