lss
- class quantecon.lss.LinearStateSpace(A, C, G, H=None, mu_0=None, Sigma_0=None)[source]
Bases:
object
A class that describes a Gaussian linear state space model of the form:
\[ \begin{align}\begin{aligned}x_{t+1} = A x_t + C w_{t+1}\\y_t = G x_t + H v_t\end{aligned}\end{align} \]where \({w_t}\) and \({v_t}\) are independent and standard normal with dimensions k and l respectively. The initial conditions are \(\mu_0\) and \(\Sigma_0\) for \(x_0 \sim N(\mu_0, \Sigma_0)\). When \(\Sigma_0=0\), the draw of \(x_0\) is exactly \(\mu_0\).
- Parameters:
- Aarray_like or scalar(float)
Part of the state transition equation. It should be n x n
- Carray_like or scalar(float)
Part of the state transition equation. It should be n x m
- Garray_like or scalar(float)
Part of the observation equation. It should be k x n
- Harray_like or scalar(float), optional(default=None)
Part of the observation equation. It should be k x l
- mu_0array_like or scalar(float), optional(default=None)
This is the mean of initial draw and is n x 1
- Sigma_0array_like or scalar(float), optional(default=None)
This is the variance of the initial draw and is n x n and also should be positive definite and symmetric
- Attributes:
- A, C, G, H, mu_0, Sigma_0see Parameters
- n, k, m, lscalar(int)
The dimensions of x_t, y_t, w_t and v_t respectively
Methods
convert
(x)Convert array_like objects (lists of lists, floats, etc.) into well formed 2D NumPy arrays
geometric_sums
(beta, x_t)Forecast the geometric sums
impulse_response
([j])Pulls off the imuplse response coefficients to a shock in \(w_{t}\) for \(x\) and \(y\)
Create a generator to calculate the population mean and variance-covariance matrix for both \(x_t\) and \(y_t\) starting at the initial condition (self.mu_0, self.Sigma_0).
replicate
([T, num_reps, random_state])Simulate num_reps observations of \(x_T\) and \(y_T\) given \(x_0 \sim N(\mu_0, \Sigma_0)\).
simulate
([ts_length, random_state])Simulate a time series of length ts_length, first drawing
Compute the moments of the stationary distributions of \(x_t\) and \(y_t\) if possible.
- convert(x)[source]
Convert array_like objects (lists of lists, floats, etc.) into well formed 2D NumPy arrays
- geometric_sums(beta, x_t)[source]
Forecast the geometric sums
\[ \begin{align}\begin{aligned}S_x := E \Big[ \sum_{j=0}^{\infty} \beta^j x_{t+j} | x_t \Big]\\S_y := E \Big[ \sum_{j=0}^{\infty} \beta^j y_{t+j} | x_t \Big]\end{aligned}\end{align} \]- Parameters:
- betascalar(float)
Discount factor, in [0, 1)
- betaarray_like(float)
The term x_t for conditioning
- Returns:
- S_xarray_like(float)
Geometric sum as defined above
- S_yarray_like(float)
Geometric sum as defined above
- impulse_response(j=5)[source]
Pulls off the imuplse response coefficients to a shock in \(w_{t}\) for \(x\) and \(y\)
Important to note: We are uninterested in the shocks to v for this method
\(x\) coefficients are \(C, AC, A^2 C...\)
\(y\) coefficients are \(GC, GAC, GA^2C...\)
- Parameters:
- jScalar(int)
Number of coefficients that we want
- Returns:
- xcoeflist(array_like(float, 2))
The coefficients for x
- ycoeflist(array_like(float, 2))
The coefficients for y
- moment_sequence()[source]
Create a generator to calculate the population mean and variance-covariance matrix for both \(x_t\) and \(y_t\) starting at the initial condition (self.mu_0, self.Sigma_0). Each iteration produces a 4-tuple of items (mu_x, mu_y, Sigma_x, Sigma_y) for the next period.
- Yields:
- mu_xarray_like(float)
An n x 1 array representing the population mean of x_t
- mu_yarray_like(float)
A k x 1 array representing the population mean of y_t
- Sigma_xarray_like(float)
An n x n array representing the variance-covariance matrix of x_t
- Sigma_yarray_like(float)
A k x k array representing the variance-covariance matrix of y_t
- replicate(T=10, num_reps=100, random_state=None)[source]
Simulate num_reps observations of \(x_T\) and \(y_T\) given \(x_0 \sim N(\mu_0, \Sigma_0)\).
- Parameters:
- Tscalar(int), optional(default=10)
The period that we want to replicate values for
- num_repsscalar(int), optional(default=100)
The number of replications that we want
- random_stateint or np.random.RandomState/Generator, optional
Random seed (integer) or np.random.RandomState or Generator instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is used.
- Returns:
- xarray_like(float)
An n x num_reps array, where the j-th column is the j_th observation of \(x_T\)
- yarray_like(float)
A k x num_reps array, where the j-th column is the j_th observation of \(y_T\)
- simulate(ts_length=100, random_state=None)[source]
Simulate a time series of length ts_length, first drawing
\[x_0 \sim N(\mu_0, \Sigma_0)\]- Parameters:
- ts_lengthscalar(int), optional(default=100)
The length of the simulation
- random_stateint or np.random.RandomState/Generator, optional
Random seed (integer) or np.random.RandomState or Generator instance to set the initial state of the random number generator for reproducibility. If None, a randomly initialized RandomState is used.
- Returns:
- xarray_like(float)
An n x ts_length array, where the t-th column is \(x_t\)
- yarray_like(float)
A k x ts_length array, where the t-th column is \(y_t\)
- stationary_distributions()[source]
Compute the moments of the stationary distributions of \(x_t\) and \(y_t\) if possible. Computation is by solving the discrete Lyapunov equation.
- Returns:
- mu_xarray_like(float)
An n x 1 array representing the stationary mean of \(x_t\)
- mu_yarray_like(float)
An k x 1 array representing the stationary mean of \(y_t\)
- Sigma_xarray_like(float)
An n x n array representing the stationary var-cov matrix of \(x_t\)
- Sigma_yarray_like(float)
An k x k array representing the stationary var-cov matrix of \(y_t\)
- Sigma_yxarray_like(float)
An k x n array representing the stationary cov matrix between \(y_t\) and \(x_t\).
- quantecon.lss.simulate_linear_model(A, x0, v, ts_length)[source]
This is a separate function for simulating a vector linear system of the form
\[x_{t+1} = A x_t + v_t\]given \(x_0\) = x0
Here \(x_t\) and \(v_t\) are both n x 1 and \(A\) is n x n.
The purpose of separating this functionality out is to target it for optimization by Numba. For the same reason, matrix multiplication is broken down into for loops.
- Parameters:
- Aarray_like or scalar(float)
Should be n x n
- x0array_like
Should be n x 1. Initial condition
- vnp.ndarray
Should be n x ts_length-1. Its t-th column is used as the time t shock \(v_t\)
- ts_lengthint
The length of the time series
- Returns:
- xnp.ndarray
Time series with ts_length columns, the t-th column being \(x_t\)