codecogs equations

måndag 24 juni 2019

Sampling: simple stable Autoregressive

I want to try out the convex hull inclusivity tester on data that is less random. One way to get such data is to sample a stable ARMA process. In fourier space, an ARMA can be expressed as a quotient of two polynomials:



P contains the poles, and Q contains the zeroes, or nills. In this post, I use only Q = 1.
The criterion for stability is that all roots of P is in the unit circle. To get a uniform sampling from the unit circle, we can sample an angle from a uniform distribution, and an absolute value from a triangle distribution (since the density must increase linearly with the absolute value). The code:

def poles(k):
"""
Generates k pairs of poles in the unit circle
Returns the resulting polynomial coefficients
"""
pol = np.array([1])
for _ in range(k):
theta = np.random.random()*np.pi
r = np.random.random()**0.5 # to get uniform over area
coeffs = np.array([1, -2*np.cos(theta)*r, r**2])
pol = np.convolve(pol, coeffs) # polynomial multiplication
return pol
def main():
ar = poles(5)
ps = ArmaProcess(ar, [1])
y = ps.generate_sample(1000)
plt.plot(y)
plt.show()
view raw poles.py hosted with ❤ by GitHub
This output format fits perfectly into the ArmaProcess object from statsmodels.

Random stable AR process from 5 pairs of poles.

Inga kommentarer:

Skicka en kommentar