Solutions

DifferenceEquations.StateSpaceSolutionType
StateSpaceSolution

Solution type returned by solve for all state-space problems.

Fields

  • u: State trajectory as Vector{Vector{T}}.
  • t: Time values.
  • z: Observation trajectory as Vector{Vector{T}}, or nothing.
  • W: Noise sequence as Vector{Vector{T}}, or nothing (e.g., for KalmanFilter).
  • P: Posterior covariances as Vector{Matrix{T}} (KalmanFilter only), or nothing.
  • logpdf: Log-likelihood value. Zero when no observables are 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 state
source

Fields

FieldTypeDescription
uVector{Vector{T}}State trajectory
tRangeTime values
zVector{Vector{T}} or nothingObservations
WVector{Vector{T}} or nothingNoise sequence (DirectIteration only)
PVector{Matrix{T}} or nothingPosterior covariances (KalmanFilter only)
logpdfRealLog-likelihood (0.0 if no observables; may be a Dual number under ForwardDiff)
retcodeReturnCode.TReturnCode.Success (errors are thrown as exceptions, not encoded in the return code)
probProblemOriginal problem
algAlgorithmAlgorithm 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 steps

Standard 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
Rowtimestampcapitalproductivity
Int64Float64Float64
100.00.0
210.0-0.00609116
32-0.03776520.00527124
43-0.003195230.0144129
540.0863248-0.00377662
650.0585935-0.0108113