Autoregressive Model¶
New in version 0.1.
Changed in version 0.2.
This function generates data as autoregressive model (AR model) according to following equation
\(x(k) = c + \sum\limits_{n=1}^{\infty} a_{i} x(k-i) + v(k)\),
where \(k\) is discrete time index, \(c\) is an constant, \(a_i\) is parameters of model and \(v(k)\) is noise.
The AR model is also known as stochastic difference equation.
Example Usage¶
Let us consider AR model as follows
\(x(k) = 1.79 x(k-1) - 1.85 x(k-2) + 1.27 x(k-3) - 0.41 x(k-4) + v(k)\).
This AR can be simulated with following code (1000 samples).
import signalz
# AR model parameters
a = [-0.41, 1.27, -1.85, 1.79]
# number of samples
N = 1000
# get AR data
x = signalz.autoregressive_model(N, a, noise="white")
The next example shows, how to introduce parameter changes during the data generation.
import signalz
# number of samples
N = 1000
# AM model default parameters
a = [-0.41, 1.27, -1.85, 1.79]
# parameters for all samples
A = np.ones((N,4))
A = A*a
# change of parameters starting from time index 500
A[500:] = a + np.array([0.01, 0.02, 0.01, -0.02])
# get AR data
x = signalz.autoregressive_model(N, A, noise="white")
Function Documentation¶
-
signalz.generators.autoregressive_model.
autoregressive_model
(n, a, const=0, noise='white', initials='none')[source]¶ Autoregressive model (stochastic difference equation)
Args:
- n - length of the output data (int) - how many samples will be on output
- a - coefficients of the model (1d array, 2d array), in case of a vector are used the same parameters for whole generation. In case of a matrix, every row represents parameters for one time sample.
Kwargs:
- const - constant of the model (float), default is 0
- noise - model input (str or 1d array), default is “white”,
possible options are:
- “white” - input noise has zero mean value and unit standard deviation
- “none” - input noise are zeros
- manually created array of inputs of length n
- initials - initial values (1d array) of the same size as a
Returns:
- x - output of the AR model (1d array)