Skip to content

Commit

Permalink
quantecon.arma: Import scipy.signal functions only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Dec 12, 2018
1 parent a8e2ddc commit e265b25
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions quantecon/arma.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
import numpy as np
from numpy import conj, pi
from scipy.signal import dimpulse, freqz, dlsim
from .util import check_random_state


Expand Down Expand Up @@ -61,7 +60,6 @@ class ARMA:
processing we desire. Corresponds with the theta values
"""

def __init__(self, phi, theta=0, sigma=1):
self._phi, self._theta = phi, theta
self.sigma = sigma
Expand Down Expand Up @@ -165,6 +163,7 @@ def impulse_response(self, impulse_length=30):
We take psi[0] as unity.
"""
from scipy.signal import dimpulse
sys = self.ma_poly, self.ar_poly, 1
times, psi = dimpulse(sys, n=impulse_length)
psi = psi[0].flatten() # Simplify return value into flat array
Expand Down Expand Up @@ -205,6 +204,7 @@ def spectral_density(self, two_pi=True, res=1200):
The frequency response
"""
from scipy.signal import freqz
w, h = freqz(self.ma_poly, self.ar_poly, worN=res, whole=two_pi)
spect = h * conj(h) * self.sigma**2

Expand Down Expand Up @@ -249,6 +249,7 @@ def simulation(self, ts_length=90, random_state=None):
A simulation of the model that corresponds to this class
"""
from scipy.signal import dlsim
random_state = check_random_state(random_state)

sys = self.ma_poly, self.ar_poly, 1
Expand Down

0 comments on commit e265b25

Please sign in to comment.