pydse package¶
Subpackages¶
Submodules¶
pydse.arma module¶
All functionality related to ARMA models.
-
class
pydse.arma.
ARMA
(A, B=None, C=None, TREND=None, rand_state=None)[source]¶ Bases:
pydse.utils.UnicodeMixin
A(L)y(t) = B(L)e(t) + C(L)u(t) - TREND(t)
- L: Lag/Shift operator,
- A: (axpxp) tensor to define auto-regression,
- B: (bxpxp) tensor to define moving-average,
- C: (cxpxm) tensor for external input,
- e: (txp) matrix of unobserved disturbance (white noise),
- y: (txp) matrix of observed output variables,
- u: (mxt) matrix of input variables,
- TREND: (txp) matrix like y or a p-dim vector.
If B is net set, fall back to VAR, i.e. B(L) = I.
-
est_params
(y)[source]¶ Maximum likelihood estimation of the ARMA model’s coefficients.
Parameters: y – output series Returns: optimization result ( OptimizeResult
)
-
fix_constants
(fuzz=1e-05, prec=1)[source]¶ Fix some coefficients as constants depending on their value.
Coefficient with a absolute difference of
fuzz
to a value of precisionprec
are considered constants.For example:
- 1.1 is constant since abs(1.1 - round(1.1, prec)) < fuzz
- 0.01 is non constant since abs(0.01 - round(0.01, prec)) > fuzz
-
forecast
(y, horizon=0, u=None)[source]¶ Calculate an one-step-ahead forecast.
Parameters: - y – output time series
- horizon – number of predictions after y[T_max]
- u – external input time series
Returns: predicted time series as array
-
non_consts
¶ Parameters of the ARMA model that are non-constant.
Returns: array
-
plot_forecast
(all_y, horizon=0, u=None)[source]¶ Calculate an one-step-ahead forecast and plot prediction and truth.
Parameters: - y – output time series
- horizon – number of predictions after y[T_max]
- u – external input time series
Returns: predicted time series as array
-
simulate
(y0=None, u0=None, u=None, sampleT=100, noise=None)[source]¶ Simulate an ARMA model.
Parameters: - y0 – lagged values of y prior to t=0 in reversed order
- u0 – lagged values of u prior to t=0 in reversed order
- u – external input time series
- sampleT – length of the sample to simulate
- noise – tuple (w0, w) of a random noise time series. w0 are the lagged values of w prior to t=0 in reversed order. By default a normal distribution for the white noise is assumed.
Returns: simulated time series as array
-
pydse.arma.
minic
(ar_lags, ma_lags, y, crit=u'BIC')[source]¶ Minimum information criterion method to fit ARMA.
Use the Akaike information criterion (AIC) or Bayesian information criterion (BIC) to determine the most promising AR and MA lags for an ARMA model.
This method only works for scalar time series, i.e. dim(y[0]) = 1.
Parameters: - ar_lags – list of AR lags to consider
- ma_lags – list of MA lags to consider
- y – target vector or scalar time series
- crit – information criterion (‘BIC’ or ‘AIC’)
Returns: tuple of AR lags and MA lags
pydse.stats module¶
General statistical functions and related tools.
-
pydse.stats.
aic
(L, k)[source]¶ Akaike information criterion.
Parameters: - L – maximized value of the negative log likelihood function
- k – number of free parameters
Returns: AIC
pydse.utils module¶
Various different utilities and tools.
-
class
pydse.utils.
UnicodeMixin
[source]¶ Bases:
object
Mixin class to handle defining the proper __str__/__unicode__ methods in Python 2 or 3.
-
pydse.utils.
atleast_2d
(arr)[source]¶ Ensure that an array has at least dimension 2.
Parameters: arr – array Returns: array with dimension of at least 2
-
pydse.utils.
make_lag_arr
(lags, fuzz=0.01)[source]¶ Create a lag polynomial that can be used as 1-dim A and B for ARMA.
This function creates a lag polynomial, i.e. 1-dim lag matrix, and sets to parameters that are to be estimated to the
fuzz
value. Checkfix_constants
for further information.Parameters: - lags – list of lags
- fuzz – fill value to mark non-constant lags
Returns: tuple of the lag array and its shape