This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Forward Kalman | |
function solve_kalman(m::AbstractFirstOrderExpectationalDifferenceModel, sol::FirstOrderSolution, Q, obs, Ω, x_0 = nothing) | |
@unpack n, n_x, n_y, n_p, n_ϵ, η = m | |
@unpack h_x, g_x, h_x_p, g_x_p, Σ, Σ_p = sol | |
(isnothing(x_0) || length(x_0) == n_x) || | |
throw(ArgumentError("Length of x_0 mismatches model")) | |
T = size(obs, 1) | |
n_z = size(Q, 1) | |
z = [zeros(n_z) for _ in 1:T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DifferentiableStateSpaceModels, ModelingToolkit, SparseArrays, LinearAlgebra, Parameters, Test, TimerOutputs, BenchmarkTools | |
using Turing, Zygote, ChainRules, Optim | |
Turing.setadbackend(:zygote) | |
# Generate fake data | |
H, mod_vals = Examples.rbc() | |
model = FirstOrderStateSpaceModel(H; mod_vals...) | |
p = [0.2, 0.02, 0.01] | |
θ_value = [0.5, 0.95] | |
solution, _ = solve_model!(model, θ = θ_value, p = p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DifferentiableStateSpaceModels, ModelingToolkit, SparseArrays, LinearAlgebra, Parameters, Test, TimerOutputs, BenchmarkTools | |
using Turing, Zygote, ChainRules | |
Turing.setadbackend(:zygote) | |
# Generate fake data | |
H, mod_vals = Examples.rbc() | |
model = FirstOrderStateSpaceModel(H; mod_vals...) | |
p = [0.2, 0.02, 0.01] | |
θ_value = [0.5, 0.95] | |
solution, _ = solve_model!(model, θ = θ_value, p = p) |