Solutions
DifferenceEquations.StateSpaceSolution — Type
StateSpaceSolutionSolution type returned by solve for all state-space problems.
Fields
u: State trajectory asVector{Vector{T}}.t: Time values.z: Observation trajectory asVector{Vector{T}}, ornothing.W: Noise sequence asVector{Vector{T}}, ornothing(e.g., forKalmanFilter).P: Posterior covariances asVector{Matrix{T}}(KalmanFilteronly), ornothing.logpdf: Log-likelihood value. Zero when noobservablesare provided.retcode:ReturnCode.Success. Errors are thrown as exceptions, not encoded in the return code.prob: The original problem.alg: The algorithm used.
Symbolic Indexing
Access time series by symbol name:
sol[:x] # state variable time series (requires `syms`)
sol[:output] # observation time series (requires `obs_syms`)Standard Indexing
sol[i] # state at time step i (same as sol.u[i])
sol[end] # final stateFields
| Field | Type | Description |
|---|---|---|
u | Vector{Vector{T}} | State trajectory |
t | Range | Time values |
z | Vector{Vector{T}} or nothing | Observations |
W | Vector{Vector{T}} or nothing | Noise sequence (DirectIteration only) |
P | Vector{Matrix{T}} or nothing | Posterior covariances (KalmanFilter only) |
logpdf | Real | Log-likelihood (0.0 if no observables; may be a Dual number under ForwardDiff) |
retcode | ReturnCode.T | ReturnCode.Success (errors are thrown as exceptions, not encoded in the return code) |
prob | Problem | Original problem |
alg | Algorithm | Algorithm used |
Symbolic Indexing
If syms or obs_syms were provided when constructing the problem, the solution supports symbolic indexing:
prob = LinearStateSpaceProblem(A, B, u0, (0, 10); C, syms=(:x, :y), obs_syms=(:obs1, :obs2))
sol = solve(prob)
# Access state variables by name
sol[:x] # vector of :x values across all time steps
sol[:obs1] # vector of :obs1 observations across all time stepsStandard Indexing
Solutions support standard Julia indexing to access states at specific time steps:
sol = solve(prob)
sol[1] # state at t=0 (initial condition)
sol[end] # state at the final time step
sol.u[3] # state at the third time index
sol.z[2] # observation at the second time index (if C was provided)DataFrame Conversion
The state trajectory can be converted to a DataFrame. Column names come from syms if provided. Note that only the state variables (not observations) appear in the DataFrame.
using DifferenceEquations, LinearAlgebra, DataFrames
A = [0.95 6.2; 0.0 0.2]
B = [0.0; 0.01;;]
C = [0.09 0.67; 1.00 0.00]
prob = LinearStateSpaceProblem(A, B, zeros(2), (0, 5); C,
syms = (:capital, :productivity), obs_syms = (:output, :investment))
sol = solve(prob)
DataFrame(sol)6×3 DataFrame
| Row | timestamp | capital | productivity |
|---|---|---|---|
| Int64 | Float64 | Float64 | |
| 1 | 0 | 0.0 | 0.0 |
| 2 | 1 | 0.0 | -0.00609116 |
| 3 | 2 | -0.0377652 | 0.00527124 |
| 4 | 3 | -0.00319523 | 0.0144129 |
| 5 | 4 | 0.0863248 | -0.00377662 |
| 6 | 5 | 0.0585935 | -0.0108113 |