Outputs of a statespace system
outputs_STSP_cpp.Rd
This internal helper function computes the outputs and states for a statespace system of the form $$a_{t+1} = A a_t + B u_t, \; y_t = C a_t + D u_t$$
Arguments
- A
\((s,s)\) matrix.
- B
\((s,n)\) matrix.
- C
\((m,s)\) matrix.
- D
\((m,n)\) matrix.
- u
\((n,N)\) matrix with the inputs/disturbances: \((u_1,u_2,\ldots,u_N)\).
- a
\((s,N+1)\) matrix. This matrix is overwritten with the (computed) states: \((a_1,a_2,\ldots,a_N,a_{N+1})\). On input
a[,1]
must hold the initial state \(a_1\).- y
\((m,N)\) matrix. This matrix is overwritten with (computed) outputs: \((y_1,y_2,\ldots,y_N)\).
Note
Use this procedure with care!
The procedure does not check the input arguments.
The procedure overwrites the input arguments
a
andu
.The data matrices are organized columnwise (to avoid memory shuffling)!
See also
outputs_ARMA_cpp
, residuals_ARMA_cpp
, cll_theta_ARMA_cpp
,
outputs_STSP_cpp
, residuals_STSP_cpp
, cll_theta_STSP_cpp
and
solve_de
, solve_inverse_de
and ll
.
Examples
# generate a random statespace model (3 outputs, 2 inputs and 4 states)
m = 3
n = 2
s = 4
model = test_stspmod(dim = c(m, n), s = s, digits = 2)
# generate random noise sequence (sample size N = 10)
n.obs = 10
u = matrix(rnorm(n.obs*n), nrow = n, ncol = n.obs)
print(u)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.6608268 1.973914 0.2354302 -0.8402714 1.1646030 -0.02291834
#> [2,] 1.2236039 2.072861 -0.4070931 -0.6996284 -0.3120939 0.43262238
#> [,7] [,8] [,9] [,10]
#> [1,] 0.27630991 -0.4755849 0.7693238 0.4517465
#> [2,] -0.06727034 -0.6866931 0.6912570 0.4445293
# generate matrix for the state sequence
a = matrix(0, nrow = s, ncol = n.obs+1)
a[,1] = rnorm(s) # random initial state a[1]
print(a)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,] 0.003780549 0 0 0 0 0 0 0 0 0 0
#> [2,] 0.637364872 0 0 0 0 0 0 0 0 0 0
#> [3,] 0.649775552 0 0 0 0 0 0 0 0 0 0
#> [4,] -0.806978707 0 0 0 0 0 0 0 0 0 0
# generate matrix for the outputs
y = matrix(0, nrow = m, ncol = n.obs)
# call outputs_STSP_cpp()
outputs_STSP_cpp(model$sys$A, model$sys$B, model$sys$C, model$sys$D, u, a, y)
print(u)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.6608268 1.973914 0.2354302 -0.8402714 1.1646030 -0.02291834
#> [2,] 1.2236039 2.072861 -0.4070931 -0.6996284 -0.3120939 0.43262238
#> [,7] [,8] [,9] [,10]
#> [1,] 0.27630991 -0.4755849 0.7693238 0.4517465
#> [2,] -0.06727034 -0.6866931 0.6912570 0.4445293
print(a) # a is overwritten with the computed states
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.003780549 1.851140674 -1.37841443 -3.9348659 -7.8430227 -11.6527278
#> [2,] 0.637364872 -0.388257448 1.67204528 1.0499707 3.4914483 0.5246119
#> [3,] 0.649775552 3.491592639 4.43244276 6.4804504 9.3259936 21.8985763
#> [4,] -0.806978707 0.002310544 -0.05564513 0.2959016 -0.3714579 -1.8704692
#> [,7] [,8] [,9] [,10] [,11]
#> [1,] -23.941100 -38.84891 -62.36087 -134.81683 -173.80340
#> [2,] 9.665598 11.48839 19.95334 53.30300 41.51877
#> [3,] 30.963632 67.85477 105.83304 191.51137 366.62189
#> [4,] 2.685993 -11.55248 14.00840 -33.17766 17.05150
print(y) # y is overwritten with the computed outputs
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 1.0288442 7.7915364 -1.1305329 -8.218414 -14.405891 -22.23845 -46.25018
#> [2,] 0.9014999 4.2552733 0.6892649 2.650351 2.748217 14.44811 11.99803
#> [3,] -0.2131480 0.9464061 1.7437085 6.425427 8.805214 25.76432 28.39758
#> [,8] [,9] [,10]
#> [1,] -73.43075 -112.62910 -262.24134
#> [2,] 32.64877 52.77545 76.76601
#> [3,] 70.16839 95.04417 192.38061