
p7]c           @` s`  d  Z  d d l m Z m Z m Z d d l m Z d d l Z d d l	 m
 Z
 d d l m Z d d l m Z d d l m Z d d	 l m Z d d l j j Z d d
 l m Z d d l m Z d d l m Z m Z m Z d d l m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% d e f d     YZ& d e f d     YZ' d e f d     YZ( e j) e( e'  d S(   s<   
SARIMAX Model

Author: Chad Fulton
License: Simplified-BSD
i    (   t   divisiont   absolute_importt   print_function(   t   warnN(   t   long(   t   Bunch(   t   _is_using_pandas(   t   cache_readonly(   t   ValueWarning(   t   lagmati   (   t   Initialization(   t   MLEModelt
   MLEResultst   MLEResultsWrapper(   t   companion_matrixt   difft   is_invertiblet   constrain_stationary_univariatet!   unconstrain_stationary_univariatet   prepare_exogt   SARIMAXc           B` s  e  Z d  Z e d d d f d d d d f e e e e e e e e e d  Z d   Z d   Z d   Z	 e d  Z
 e d    Z e d	    Z e d
    Z e d    Z e d    Z e d e d   Z e d    Z e e d   Z d d d d d d d d d g	 Z e d    Z e d    Z e d    Z e d    Z e d    Z e d  Z d   Z d    Z e e d!  Z RS("   s<2  
    Seasonal AutoRegressive Integrated Moving Average with eXogenous regressors
    model

    Parameters
    ----------
    endog : array_like
        The observed time-series process :math:`y`
    exog : array_like, optional
        Array of exogenous regressors, shaped nobs x k.
    order : iterable or iterable of iterables, optional
        The (p,d,q) order of the model for the number of AR parameters,
        differences, and MA parameters. `d` must be an integer
        indicating the integration order of the process, while
        `p` and `q` may either be an integers indicating the AR and MA
        orders (so that all lags up to those orders are included) or else
        iterables giving specific AR and / or MA lags to include. Default is
        an AR(1) model: (1,0,0).
    seasonal_order : iterable, optional
        The (P,D,Q,s) order of the seasonal component of the model for the
        AR parameters, differences, MA parameters, and periodicity.
        `d` must be an integer indicating the integration order of the process,
        while `p` and `q` may either be an integers indicating the AR and MA
        orders (so that all lags up to those orders are included) or else
        iterables giving specific AR and / or MA lags to include. `s` is an
        integer giving the periodicity (number of periods in season), often it
        is 4 for quarterly data or 12 for monthly data. Default is no seasonal
        effect.
    trend : str{'n','c','t','ct'} or iterable, optional
        Parameter controlling the deterministic trend polynomial :math:`A(t)`.
        Can be specified as a string where 'c' indicates a constant (i.e. a
        degree zero component of the trend polynomial), 't' indicates a
        linear trend with time, and 'ct' is both. Can also be specified as an
        iterable defining the polynomial as in `numpy.poly1d`, where
        `[1,1,0,1]` would denote :math:`a + bt + ct^3`. Default is to not
        include a trend component.
    measurement_error : boolean, optional
        Whether or not to assume the endogenous observations `endog` were
        measured with error. Default is False.
    time_varying_regression : boolean, optional
        Used when an explanatory variables, `exog`, are provided provided
        to select whether or not coefficients on the exogenous regressors are
        allowed to vary over time. Default is False.
    mle_regression : boolean, optional
        Whether or not to use estimate the regression coefficients for the
        exogenous variables as part of maximum likelihood estimation or through
        the Kalman filter (i.e. recursive least squares). If
        `time_varying_regression` is True, this must be set to False. Default
        is True.
    simple_differencing : boolean, optional
        Whether or not to use partially conditional maximum likelihood
        estimation. If True, differencing is performed prior to estimation,
        which discards the first :math:`s D + d` initial rows but results in a
        smaller state-space formulation. If False, the full SARIMAX model is
        put in state-space form so that all datapoints can be used in
        estimation. Default is False.
    enforce_stationarity : boolean, optional
        Whether or not to transform the AR parameters to enforce stationarity
        in the autoregressive component of the model. Default is True.
    enforce_invertibility : boolean, optional
        Whether or not to transform the MA parameters to enforce invertibility
        in the moving average component of the model. Default is True.
    hamilton_representation : boolean, optional
        Whether or not to use the Hamilton representation of an ARMA process
        (if True) or the Harvey representation (if False). Default is False.
    concentrate_scale : boolean, optional
        Whether or not to concentrate the scale (variance of the error term)
        out of the likelihood. This reduces the number of parameters estimated
        by maximum likelihood by one, but standard errors will then not
        be available for the scale parameter.
    **kwargs
        Keyword arguments may be used to provide default values for state space
        matrices or for Kalman filtering options. See `Representation`, and
        `KalmanFilter` for more details.

    Attributes
    ----------
    measurement_error : boolean
        Whether or not to assume the endogenous
        observations `endog` were measured with error.
    state_error : boolean
        Whether or not the transition equation has an error component.
    mle_regression : boolean
        Whether or not the regression coefficients for
        the exogenous variables were estimated via maximum
        likelihood estimation.
    state_regression : boolean
        Whether or not the regression coefficients for
        the exogenous variables are included as elements
        of the state space and estimated via the Kalman
        filter.
    time_varying_regression : boolean
        Whether or not coefficients on the exogenous
        regressors are allowed to vary over time.
    simple_differencing : boolean
        Whether or not to use partially conditional maximum likelihood
        estimation.
    enforce_stationarity : boolean
        Whether or not to transform the AR parameters
        to enforce stationarity in the autoregressive
        component of the model.
    enforce_invertibility : boolean
        Whether or not to transform the MA parameters
        to enforce invertibility in the moving average
        component of the model.
    hamilton_representation : boolean
        Whether or not to use the Hamilton representation of an ARMA process.
    trend : str{'n','c','t','ct'} or iterable
        Parameter controlling the deterministic
        trend polynomial :math:`A(t)`. See the class
        parameter documentation for more information.
    polynomial_ar : array
        Array containing autoregressive lag polynomial
        coefficients, ordered from lowest degree to highest.
        Initialized with ones, unless a coefficient is
        constrained to be zero (in which case it is zero).
    polynomial_ma : array
        Array containing moving average lag polynomial
        coefficients, ordered from lowest degree to highest.
        Initialized with ones, unless a coefficient is
        constrained to be zero (in which case it is zero).
    polynomial_seasonal_ar : array
        Array containing seasonal moving average lag
        polynomial coefficients, ordered from lowest degree
        to highest. Initialized with ones, unless a
        coefficient is constrained to be zero (in which
        case it is zero).
    polynomial_seasonal_ma : array
        Array containing seasonal moving average lag
        polynomial coefficients, ordered from lowest degree
        to highest. Initialized with ones, unless a
        coefficient is constrained to be zero (in which
        case it is zero).
    polynomial_trend : array
        Array containing trend polynomial coefficients,
        ordered from lowest degree to highest. Initialized
        with ones, unless a coefficient is constrained to be
        zero (in which case it is zero).
    k_ar : int
        Highest autoregressive order in the model, zero-indexed.
    k_ar_params : int
        Number of autoregressive parameters to be estimated.
    k_diff : int
        Order of intergration.
    k_ma : int
        Highest moving average order in the model, zero-indexed.
    k_ma_params : int
        Number of moving average parameters to be estimated.
    seasonal_periods : int
        Number of periods in a season.
    k_seasonal_ar : int
        Highest seasonal autoregressive order in the model, zero-indexed.
    k_seasonal_ar_params : int
        Number of seasonal autoregressive parameters to be estimated.
    k_seasonal_diff : int
        Order of seasonal intergration.
    k_seasonal_ma : int
        Highest seasonal moving average order in the model, zero-indexed.
    k_seasonal_ma_params : int
        Number of seasonal moving average parameters to be estimated.
    k_trend : int
        Order of the trend polynomial plus one (i.e. the constant polynomial
        would have `k_trend=1`).
    k_exog : int
        Number of exogenous regressors.

    Notes
    -----
    The SARIMA model is specified :math:`(p, d, q) \times (P, D, Q)_s`.

    .. math::

        \phi_p (L) \tilde \phi_P (L^s) \Delta^d \Delta_s^D y_t = A(t) +
            \theta_q (L) \tilde \theta_Q (L^s) \zeta_t

    In terms of a univariate structural model, this can be represented as

    .. math::

        y_t & = u_t + \eta_t \\
        \phi_p (L) \tilde \phi_P (L^s) \Delta^d \Delta_s^D u_t & = A(t) +
            \theta_q (L) \tilde \theta_Q (L^s) \zeta_t

    where :math:`\eta_t` is only applicable in the case of measurement error
    (although it is also used in the case of a pure regression model, i.e. if
    p=q=0).

    In terms of this model, regression with SARIMA errors can be represented
    easily as

    .. math::

        y_t & = \beta_t x_t + u_t \\
        \phi_p (L) \tilde \phi_P (L^s) \Delta^d \Delta_s^D u_t & = A(t) +
            \theta_q (L) \tilde \theta_Q (L^s) \zeta_t

    this model is the one used when exogenous regressors are provided.

    Note that the reduced form lag polynomials will be written as:

    .. math::

        \Phi (L) \equiv \phi_p (L) \tilde \phi_P (L^s) \\
        \Theta (L) \equiv \theta_q (L) \tilde \theta_Q (L^s)

    If `mle_regression` is True, regression coefficients are treated as
    additional parameters to be estimated via maximum likelihood. Otherwise
    they are included as part of the state with a diffuse initialization.
    In this case, however, with approximate diffuse initialization, results
    can be sensitive to the initial variance.

    This class allows two different underlying representations of ARMA models
    as state space models: that of Hamilton and that of Harvey. Both are
    equivalent in the sense that they are analytical representations of the
    ARMA model, but the state vectors of each have different meanings. For
    this reason, maximum likelihood does not result in identical parameter
    estimates and even the same set of parameters will result in different
    loglikelihoods.

    The Harvey representation is convenient because it allows integrating
    differencing into the state vector to allow using all observations for
    estimation.

    In this implementation of differenced models, the Hamilton representation
    is not able to accomodate differencing in the state vector, so
    `simple_differencing` (which performs differencing prior to estimation so
    that the first d + sD observations are lost) must be used.

    Many other packages use the Hamilton representation, so that tests against
    Stata and R require using it along with simple differencing (as Stata
    does).

    If `filter_concentrated = True` is used, then the scale of the model is
    concentrated out of the likelihood. A benefit of this is that there the
    dimension of the parameter vector is reduced so that numerical maximization
    of the log-likelihood function may be faster and more stable. If this
    option in a model with measurement error, it is important to note that the
    estimated measurement error parameter will be relative to the scale, and
    is named "snr.measurement_error" instead of "var.measurement_error". To
    compute the variance of the measurement error in this case one would
    multiply `snr.measurement_error` parameter by the scale.


    Detailed information about state space models can be found in [1]_. Some
    specific references are:

    - Chapter 3.4 describes ARMA and ARIMA models in state space form (using
      the Harvey representation), and gives references for basic seasonal
      models and models with a multiplicative form (for example the airline
      model). It also shows a state space model for a full ARIMA process (this
      is what is done here if `simple_differencing=False`).
    - Chapter 3.6 describes estimating regression effects via the Kalman filter
      (this is performed if `mle_regression` is False), regression with
      time-varying coefficients, and regression with ARMA errors (recall from
      above that if regression effects are present, the model estimated by this
      class is regression with SARIMA errors).
    - Chapter 8.4 describes the application of an ARMA model to an example
      dataset. A replication of this section is available in an example
      IPython notebook in the documentation.

    References
    ----------
    .. [1] Durbin, James, and Siem Jan Koopman. 2012.
       Time Series Analysis by State Space Methods: Second Edition.
       Oxford University Press.
    i   i    c         K` s	  | d |  _  | |  _ | |  _ | |  _ |	 |  _ |
 |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 |  j r |  j r t d   n  t | d t t t j f  r t j d t j | d  f |  _ n t j d | d f |  _ |  j j   |  _ t | d t t t j f  r>t j d t j | d  f |  _ n t j d | d f |  _ |  j j   |  _ t | d t t t j f  rt j d d g |  j  d d g | d f |  _ nu t j d d g |  j  t | d  f |  _ xD t t | d   D], } | d |  j  } | d | |  j | <qW|  j j   |  _ t | d t t t j f  rt j d d g |  j  d d g | d f |  _ nu t j d d g |  j  t | d  f |  _ xD t t | d   D], } | d |  j  } | d | |  j | <qW|  j j   |  _ | |  _ | d  k sC| d k rXt j d  |  _  n~ | d k rwt j d |  _  n_ | d	 k rt j d" |  _  n@ | d
 k rt j d# |  _  n! t j! |  d k j" t  |  _  |  j  j   |  _# t |  j j$ d d  |  _% t t j& |  j  d  |  _' t | d  |  _( t |  j j$ d d  |  _) t t j& |  j  d  |  _* t |  j j$ d d  |  _+ t t j& |  j  d  |  _, t | d  |  _- t |  j j$ d d  |  _. t t j& |  j  d  |  _/ |  j( |  _0 |  j- |  _1 |  j rZ|  j pG|  j0 |  j1 k oEd k n rZt d   n  t t j& |  j    |  _2 t3 |  j% |  j+ |  j) |  j. d  |  _4 |  j4 d k r|  j% |  j+ d k r|  j rd |  _4 qn  t5 |  \ |  _6 } |  j o| d  k	 o|  j6 d k |  _ |  j o:| d  k	 o:|  j6 d k |  _7 |  j7 rd|  j4 d k rdt8 |  _ n  |  j4 } |  j s| |  j  |  j1 |  j0 7} n  |  j7 r| |  j6 7} n  | } |  j r| |  j4 8} n  t |  j4 d k  } | d k |  _9 |  j7 r|  j r| |  j6 7} n  |  j7 r.| j: d d  n  |  j' |  j* |  j, |  j/ |  j2 |  j t |  j  |  _; |  j r|  j; |  j6 7_; n  | |  _< | |  _= t> | d   st j? |  } n  |  j0 |  _@ |  j1 |  _A |  j r|  j0 d k s|  j1 d k rd |  _0 d |  _1 n  |  j0 |  j  |  j1 |  _B t |  |  _C | |  _D | |  _E | j: d |  tF tG |   jH | d | d | d | | |  j rt8 |  jI _J n  |  j6 d k st |  j   d k rtK |  jI _L n  |  jM |  jI d <|  jN |  jI d <|  jO |  jI d <|  jP |  jI d <|  j r*	d |  jI d$ <n  |  jQ d d d d d d d d d d  d! g tR | jS    7_Q |  jI jT d  k r	|  jU   n  d  S(%   Ni   s   Models with time-varying regression coefficients must integrate the coefficients as part of the state vector, so that `mle_regression` must be set to False.i    g      ?i   i   t   nt   ct   tt   cts   The Hamilton representation is only available for models in which there is no differencing integrated into the state vector. Set `simple_differencing` to True or set `hamilton_representation` to Falset   initial_varianceg    _Bt   loglikelihood_burnt   exogt   k_statest   k_posdeft   designt   state_interceptt
   transitiont	   selectiont	   state_covt   ordert   seasonal_ordert   trendt   measurement_errort   time_varying_regressiont   mle_regressiont   simple_differencingt   enforce_stationarityt   enforce_invertibilityt   hamilton_representationt   concentrate_scale(   i    i   (   i   i   (   R"   i    i    (V   t   seasonal_periodsR&   R'   R(   R)   R*   R+   R,   R-   R#   R$   t
   ValueErrort
   isinstancet   intR   t   npt   integert   r_t   onest   polynomial_art   copyt   _polynomial_art   polynomial_mat   _polynomial_mat   polynomial_seasonal_art   lent   ranget   _polynomial_seasonal_art   polynomial_seasonal_mat   _polynomial_seasonal_maR%   t   Nonet   polynomial_trendt   arrayt   astypet   _polynomial_trendt   shapet   k_art   sumt   k_ar_paramst   k_difft   k_mat   k_ma_paramst   k_seasonal_art   k_seasonal_ar_paramst   k_seasonal_difft   k_seasonal_mat   k_seasonal_ma_paramst   _k_difft   _k_seasonal_difft   k_trendt   maxt   _k_orderR   t   k_exogt   state_regressiont   Truet   state_errort
   setdefaultt   k_paramst
   orig_endogt	   orig_exogR   t
   asanyarrayt   orig_k_difft   orig_k_seasonal_difft   _k_states_difft   nobsR   R   t   superR   t   __init__t   ssmt   filter_concentratedt   Falset   _time_invariantt   initial_designt   initial_state_interceptt   initial_transitiont   initial_selectiont
   _init_keyst   listt   keyst   initializationt   initialize_default(   t   selft   endogR   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R-   t   kwargst   it   tmpR   t   k_diffuse_statesR   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRe   *  s   												&&-(-(	!#	%	'(					)								$	c         C` sm   t  t |   j   } xQ | j   D]C \ } } | d  k r" t |  j |  r" t |  j |  | | <q" q" W| S(   N(   Rd   R   t   _get_init_kwdst   itemsRA   t   hasattrRf   t   getattr(   Rs   t   kwdst   keyt   value(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRy   -  s
    c         C` s-  t  t |   j   \ } } |  j r]|  j d k sB |  j d k r]| j d } t | j   |  j |  j |  j	  } | d  k	 r t | j   |  j |  j |  j	  } n  |  j j | |  \ |  j _ |  j _ |  j j j d } |  j j d  k	 r|  j j | | |  j j d <n  |  j d  k	 r]|  j rC|  j | |  |  _ qZ|  j | | |  _ q]n  | j d |  _ t j d |  j d  } t j |  j |  j f  |  _ d } xv |  j j   d D]a } | d k rt j |  j  |  j d  d   | f <n | | |  j d  d   | f <| d 7} qW| | f S(   Ni    t
   row_labelsi   (   Rd   R   t   prepare_dataR)   R`   Ra   RF   R   R7   R.   RA   t   datat   _convert_endog_exogRt   R   R   t   _cachet   _indext   _index_generatedRc   R2   t   aranget   zerosRT   t   _trend_dataRB   t   nonzeroR5   (   Rs   Rt   R   t   orig_lengtht
   new_lengtht
   time_trendRv   t   k(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR   6  s6    	'!	(c         C` s  t  t |   j   t j |  j  d d |  _ t j |  j  d d |  _ t j |  j	  d d |  _
 t j |  j  d d |  _ |  j } | |  j |  j } |  j } |  j s t j d | |  | f |  _ n t j d | | |  f |  _ | d 7} | |  j |  j } d } |  j sFt j d | |  | f |  _ n t j d | | |  f |  _ |  j r|  j rt j |  j  } d | d |  j | d |  j f |  _ n  d S(   s   
        Initialize the SARIMAX model.

        Notes
        -----
        These initialization steps must occur following the parent class
        __init__ function calls.
        i    i   R    R!   R   R"   N(   Rd   R   t
   initializeR2   R   R6   t   _polynomial_ar_idxR9   t   _polynomial_ma_idxR;   t   _polynomial_seasonal_ar_idxR?   t   _polynomial_seasonal_ma_idxRb   RG   RM   R,   t   s_t   transition_ar_params_idxRK   RP   t   selection_ma_params_idxt   design_ma_params_idxRX   R'   t   diag_indicesR   RW   t   _exog_variance_idx(   Rs   t	   start_rowt   end_rowt   colt   idx(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR   e  s2    						"
	"c         C` s   | d k r |  j j } n  t |  j d | } |  j r | j d |  j f d  | j |  j |  j |  j f d  | j |  j |  j |  j |  j |  j	 f d  n | j d d  | |  j _
 d S(   s   Initialize defaultt   approximate_diffuse_variancei    t   approximate_diffuset
   stationaryN(   RA   Rf   R   R
   R   R*   t   setRb   RV   RW   Rq   (   Rs   R   t   init(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRr     s    			
c         C` s   t  j d g |  j d g |  j d d g |  j d g |  j d g |  j d f } t |  d k ry t  j d } n  |  j r|  j d k r t  j	 t  j
 t  j | |  j  | j d |  j f  j |  j f j d d d  d d  f } q|  j j d d d  d d  f } n  | S(   s   Initial design matrixi   i    N(   R2   R4   RR   R.   RS   RZ   RV   R<   RX   t   c_t   reshapet   repeatRc   RF   t   TR   RA   (   Rs   R   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRj     s     %	(c         C` sF   |  j  d k r- t j |  j |  j f  } n t j |  j f  } | S(   s   Initial state intercept vectori    (   RT   R2   R   R   Rc   (   Rs   R   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRk     s    c   	      C` s  t  j |  j |  j f  } |  j r |  j } t  j |  j  | | d  | d  f <|  j |  j } |  j d k r |  j n d } n |  j } d } |  j d k r
t |  j  | | |  | |  f <|  j	 r
t  j
 t |  j   | | |  | |  f <q
n  |  j d k rt |  j  j } d | d <x t |  j  D] } |  j | |  j } |  j | d |  j } | | | |  | |  f <x9 t | d |  j  D]! } d | | | |  j d f <qWd | | |  j f <qEWn  |  j d k rt  j |  j  } d | | <|  j d k rs|  j } |  j } d g |  j d d g |  j | d |  j  | |  f <n  |  j } d | d |  j  | f <n  | S(   s   Initial transition matrixNi    i   i(   i    i(   R2   R   R   RX   RW   t   eyeRV   RA   R   R,   t	   transposeRS   R.   R   R=   RR   Rb   t   triu_indices(	   Rs   R    t   startt   endt   seasonal_companiont   dRv   R   t   column(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRl     sD    	
("
%	.

		&	c         C` sB  |  j  o |  j s |  j d k r t j d g |  j d g |  j d k d g |  j d d g d |  j |  j f d d  d f } t
 |  d k r t j |  j |  j f  } q q>t j |  j d f  } ni t j |  j |  j f  } |  j d k rd | d <n  x/ t |  j d d  D] } d | | | f <q"W| S(   s   Initial selection matrixi    i   Ni(   i    i    (   RX   R'   R   R2   R4   Rb   RV   R(   RW   RA   R<   R   R   R=   (   Rs   R!   Rv   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRm      s     $%
!c         C` s   i t  t f d 6S(   Nt   fit(   t   SARIMAXResultst   SARIMAXResultsWrapper(   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   _res_classes9  s    c         C` s'  d | } t  | | |  } | d k r/ d n t | j   d  d }	 | d k r[ d n t | j   d  d }
 d  } | | | d k rX| d k r |  | } t |  | d d } t j j |  j |  } | t j | |  } n  |  | } t j	 | j
 d d f  } | d k rz| d  k r;t d   n  t j | | d  | d k r]| n d   d  d   f f } n  | d k r| j   d d d } t j | t |  |  | d   | f f } n  | d k r$| j   d d d } t j | t | |  | | d   | f f } n  t j j |  j |  } | t j | |  } n  g  } g  } g  } g  } d } | d k r| | | | !} | | 7} n  | d k r| | |	 | !} | |	 7} n  | d k r| | |
 | !} | |
 7} n  | d  k	 r| |
 d j   } n  | | | | f S(   Ni   i    i   t   trimt   boths-   Trend data must be provided if `k_trend` > 0.(   RU   R<   R   RA   R	   R2   t   linalgt   pinvt   dott   emptyRF   R/   R   t   mean(   Rt   RG   R6   RK   R9   RT   t
   trend_dataR   t   rt   k_params_art   k_params_mat	   residualst   Yt   Xt	   params_art   colst   paramst   params_trendt	   params_mat   params_variancet   offset(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   _conditional_sum_squares=  sV    
,,

?/3	c      
   C` s  |  j  } |  j r |  j d k s1 |  j d k r t |  j |  j |  j |  j  } |  j d k	 r t |  j |  j |  j |  j  } n d } | d | j	 d  d d  f } n3 |  j j
   } |  j d k	 r |  j j
   n d } | j   } t j t j |   r]t j |  j   } | | } | d k	 rA| | } n  | d k	 r]| | } q]n  g  } |  j d k rt j j |  j |  } | t j | |  } n  |  j rg  } n  |  j | |  j |  j |  j |  j |  j |  \ } } } }	 |  j d k o$|  j o$t t j d | f  }
 |
 rDt d  | d 9} n  |  j d k os|  j ost t j d | f  } | rt d  | d 9} n  |  j | |  j |  j  |  j! |  j"  \ } } } } |  j d k o|  j ot t j d | f  } | rt d  | d 9} n  |  j! d k oE|  j oEt t j d | f  } | ret d  | d 9} n  g  } |  j r|  j# rd g |  j } n  |  j$ r*t% |	  t& k r*t' |	  d k r*t% |  t& k ot' |  d k s| }	 q*|  j d k rt j( | |  }	 q*t j( | |  |  j) }	 n  |  j* r9d n g  } t j+ t, t j- |	  d   }	 |  j. rrg  }	 n  t j | | | | | | | | |	 f	 S(	   sG   
        Starting parameters for maximum likelihood estimation
        i    Ni   s\   Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.sP   Non-invertible starting MA parameters found. Using zeros as starting parameters.sS   Non-stationary starting seasonal autoregressive Using zeros as starting parameters.sS   Non-invertible starting seasonal moving average Using zeros as starting parameters.g|=(/   R   R)   RR   RS   R   Rt   R.   R   RA   RF   R7   t   squeezeR2   t   anyt   isnanRW   R   R   R   RX   R   RG   R6   RK   R9   RT   R*   R   R4   R   R+   RM   R;   RP   R?   R'   RZ   t   typeRo   R<   t   innerRc   R&   t
   atleast_1dRU   RC   R-   (   Rs   R   Rt   R   t   maskt   params_exogR   R   R   R   t
   invalid_art
   invalid_mat   _t   params_seasonal_art   params_seasonal_mat   params_seasonal_variancet   invalid_seasonal_art   invalid_seasonal_mat   params_exog_variancet   params_measurement_variance(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   start_params|  s    	
&$
		!	
	
	
	
	!		c         C` s  d } |  j  d k rU |  j  d k r9 | r0 d n d } qU | rE d n d |  j  } n  d } |  j d k r |  j d k r | r d n d	 |  j } q | r d
 n d |  j |  j f } n  |  j } | r
|  j  d k r
|  j d k r
| r d n d | | |  j j f S| r?|  j  d k r?| r+d n d | |  j j f S| rt|  j d k rt| r`d n d | |  j j f S|  j j Sd S(   s   Names of endogenous variablest    i    i   s   \Deltat   Ds	   \Delta^%ds   D%ds	   \Delta_%ds   DS%ds   \Delta_%d^%ds   D%dS%ds   %s%s %ss   %s.%s.%ss   %s %ss   %s.%sN(   RJ   RO   R.   R)   R   t   ynames(   Rs   t   latexR   t   seasonal_difft
   endog_diff(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   endog_names	  s.    	$R%   R   t   art   mat   seasonal_art   seasonal_mat   exog_variancet   measurement_variancet   variancec         C` s_   |  j  } g  |  j D] } | | d k r | ^ q } d | k r[ |  j r[ | j d  n  | S(   s   
        List of parameters actually included in the model, in sorted order.

        TODO Make this an OrderedDict with slice or indices as the values.
        i    R   (   t   model_orderst   params_completeR(   t   remove(   Rs   R   R#   R   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   param_terms-  s    	c         C` s:   |  j  } |  j } g  | D] } | | D] } | ^ q' q S(   sq   
        List of human readable parameter names (for parameters actually
        included in the model).
        (   R   t   model_names(   Rs   t   params_sort_orderR   t   paramt   name(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   param_namesA  s    		c         C` s   i |  j  d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j |  j d 6|  j |  j d 6|  j r| |  j r| |  j n d	 d
 6t |  j	  d 6t |  j
 o |  j  d 6S(   sE   
        The orders of each of the polynomials in the model.
        R%   R   R   R   R   R   t
   reduced_art
   reduced_mai    R   R   R   (   RT   RW   RG   RK   RM   RP   RX   R'   R1   R&   RZ   R-   (   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR   M  s    





"c         C` s   |  j  d t  S(   sH   
        The plain text names of all possible model parameters.
        R   (   t   _get_model_namesRh   (   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR   a  s    c         C` s   |  j  d t  S(   sC   
        The latex names of all possible model parameters.
        R   (   R   RY   (   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   model_latex_namesh  s    c         C` s  i d  d 6d  d 6d  d 6d  d 6d  d 6d  d 6d  d 6d  d 6d  d	 6d  d
 6d  d 6} |  j d k r | rn d n d } g  | d <xs |  j j   d D][ } | d k r | d j d  q | d k r | d j d  q | d j | |  q Wn  |  j d k r|  j | d <n  |  j d k rx| r.d n d } g  | d <x7 |  j j   d d D] } | d j | |  qVWn  |  j	 d k r| rd n d } g  | d <x7 |  j
 j   d d D] } | d j | |  qWn  |  j d k rB| rd n d } g  | d <x7 |  j j   d d D] } | d j | |  q Wn  |  j d k r| r]d n d } g  | d <x7 |  j j   d d D] } | d j | |  qWn  |  j d k s|  j d k r5t j |  j |  j  }	 }	 | rd n d } g  | d <x4 |	 j   d d D] } | d j | |  qWn  |  j	 d k sS|  j d k rt j |  j
 |  j  }
 | rwd n d } g  | d <x4 |
 j   d d D] } | d j | |  qWn  |  j r'|  j r'|  j s| rd n d } n | rd  n d! } g  |  j D] } | | ^ q
| d	 <n  |  j rp|  j sN| rEd" n d# } n | rZd$ n d% } | g | d
 <n  |  j r|  j r| rd& n d' } | g | d <n  | S((   NR%   R   R   R   R   R   R   R   R   R   R   i    s   t_%ds   trend.%dt	   intercepti   t   drifts	   $\phi_%d$s   ar.L%ds   $\theta_%d$s   ma.L%ds   $\tilde \phi_%d$s   ar.S.L%ds   $\tilde \theta_%d$s   ma.S.L%ds	   $\Phi_%d$s   ar.R.L%ds   $\Theta_%d$s   ma.R.L%ds   $\sigma_\text{%s}^2$s   var.%ss%   $\sigma_\text{%s}^2 / \sigma_\zeta^2$s   snr.%ss   $\sigma_\eta^2$s   var.measurement_errors    $\sigma_\eta^2 / \sigma_\zeta^2$s   snr.measurement_errors   $\sigma_\zeta^2$t   sigma2(   RA   RT   RB   R   t   appendRW   t
   exog_namesRG   R6   RK   R9   RM   R;   RP   R?   R2   t   polymulRX   R'   R-   R&   RZ   (   Rs   R   t   namest   trend_templateRv   t   ar_templatet   ma_templatet   seasonal_ar_templatet   seasonal_ma_templatet   reduced_polynomial_art   reduced_polynomial_mat   exog_var_templatet	   exog_namet   meas_var_tplt   var_tpl(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR   o  s    







		'		c         C` s  t  j | d d } t  j | j | j  } d } } |  j d k rw | |  j 7} | | | !| | | +| |  j 7} n  |  j r | |  j 7} | | | !| | | +| |  j 7} n  |  j d k r| |  j 7} |  j	 r t
 | | | ! | | | +n | | | !| | | +| |  j 7} n  |  j d k r~| |  j 7} |  j rZt
 | | | ! | | | +n | | | !| | | +| |  j 7} n  |  j d k r| |  j 7} |  j	 rt
 | | | ! | | | +n | | | !| | | +| |  j 7} n  |  j d k rK| |  j 7} |  j r't
 | | | ! | | | +n | | | !| | | +| |  j 7} n  |  j r|  j r| |  j 7} | | | !d | | | +| |  j 7} n  |  j r| | d | | <| d 7} | d 7} n  |  j r|  j r| | d | | <n  | S(   s  
        Transform unconstrained parameters used by the optimizer to constrained
        parameters used in likelihood evaluation.

        Used primarily to enforce stationarity of the autoregressive lag
        polynomial, invertibility of the moving average lag polynomial, and
        positive variance parameters.

        Parameters
        ----------
        unconstrained : array_like
            Unconstrained parameters used by the optimizer.

        Returns
        -------
        constrained : array_like
            Constrained parameters used in likelihood evaluation.

        Notes
        -----
        If the lag polynomial has non-consecutive powers (so that the
        coefficient is zero on some element of the polynomial), then the
        constraint function is not onto the entire space of invertible
        polynomials, although it only excludes a very small portion very close
        to the invertibility boundary.
        t   ndmini   i    i   (   R2   RC   R   RF   t   dtypeRT   R(   RW   RI   R*   R   RL   R+   RM   RN   RQ   RX   R'   R&   RZ   R-   (   Rs   t   unconstrainedt   constrainedR   R   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   transform_params  s\    
						
c         C` s  t  j | d d } t  j | j | j  } d } } |  j d k rw | |  j 7} | | | !| | | +| |  j 7} n  |  j r | |  j 7} | | | !| | | +| |  j 7} n  |  j d k r| |  j 7} |  j	 r t
 | | | ! | | | +n | | | !| | | +| |  j 7} n  |  j d k r~| |  j 7} |  j rZt
 | | | ! | | | +n | | | !| | | +| |  j 7} n  |  j d k r| |  j 7} |  j	 rt
 | | | ! | | | +n | | | !| | | +| |  j 7} n  |  j d k rK| |  j 7} |  j r't
 | | | ! | | | +n | | | !| | | +| |  j 7} n  |  j r|  j r| |  j 7} | | | !d | | | +| |  j 7} n  |  j r| | d | | <| d 7} | d 7} n  |  j r|  j r| | d | | <n  | S(   s  
        Transform constrained parameters used in likelihood evaluation
        to unconstrained parameters used by the optimizer

        Used primarily to reverse enforcement of stationarity of the
        autoregressive lag polynomial and invertibility of the moving average
        lag polynomial.

        Parameters
        ----------
        constrained : array_like
            Constrained parameters used in likelihood evaluation.

        Returns
        -------
        constrained : array_like
            Unconstrained parameters used by the optimizer.

        Notes
        -----
        If the lag polynomial has non-consecutive powers (so that the
        coefficient is zero on some element of the polynomial), then the
        constraint function is not onto the entire space of invertible
        polynomials, although it only excludes a very small portion very close
        to the invertibility boundary.
        R	  i   i    g      ?(   R2   RC   R   RF   R
  RT   R(   RW   RI   R*   R   RL   R+   RM   RN   RQ   RX   R'   R&   RZ   R-   (   Rs   R  R  R   R   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   untransform_paramsI  s\    
						
c         C` s%  t  t |   j | d | d t } d } d } d } d } d } d }	 d }
 d } d } d } } | |  j 7} | | | !} | |  j 7} |  j r | |  j 7} | | | !} | |  j 7} n  | |  j 7} | | | !} | |  j 7} | |  j	 7} | | | !} | |  j	 7} | |  j
 7} | | | !} | |  j
 7} | |  j 7} | | | !}	 | |  j 7} |  j r|  j r| |  j 7} | | | !}
 | |  j 7} n  |  j r| | } | d 7} | d 7} n  |  j r|  j r| | } n  |  j d k rJ|  j j | j k r| |  j |  j <qJ|  j j j | j  } | | |  j <| |  _ n  |  j d k r|  j j | j k r| |  j |  j <q|  j j j | j  } | | |  j <| |  _ n  |  j d k r|  j } |  j j | j k r| |  j | <q|  j j j | j  } | | | <| |  _ n  |  j d k r|  j } |  j j | j k r\|	 |  j | <q|  j j j | j  } |	 | | <| |  _ n  |  j d k rt  j! |  j |  j  } n
 |  j } |  j d k rt  j! |  j |  j  } n	 |  j } |  j r*t  j" |  j# |  d d d  f |  j$ d <n  |  j d k rt  j" |  j% |  j | j  } |  j& s| |  j$ d |  j' d d  f <q|  j& r| t  j( |  } n  |  j r|  j$ j) | d d d  f 7_) q| d d d  f |  j$ d <n  |  j r| |  j$ d <n  |  j d k s*|  j d k rA| d |  j$ |  j* <n> |  j$ j+ j | j k s|  j$ d	 j j | j  |  j$ d	 <n  |  j d k s|  j d k r|  j& s| d |  j$ |  j, <q| d |  j$ |  j- <n  |  j. d k r!|  j s| |  d <n  |  j r!|  j r!|
 |  j$ |  j/ <q!n  | S(   s  
        Update the parameters of the model

        Updates the representation matrices to fill in the new parameter
        values.

        Parameters
        ----------
        params : array_like
            Array of new parameters.
        transformed : boolean, optional
            Whether or not `params` is already transformed. If set to False,
            `transform_params` is called. Default is True..

        Returns
        -------
        params : array_like
            Array of parameters.
        t   transformedt   complex_stepi    i   Nt   obs_interceptR   t   obs_covR    R"   (   R  i    i    (   R"   i    i    (0   Rd   R   t   updateRh   RA   RT   R(   RW   RI   RL   RN   RQ   RX   R'   R&   RZ   R-   RG   R8   R
  R   t   realRD   RK   R:   R   RM   R   R>   RP   R   R@   R2   R   R   R   Rf   R   R,   Rb   RH   R  R   R    R   R   R   R   (   Rs   R   R  R  R   R   R   R   R   R   R   R   R   R   R   R6   R9   R   R;   R?   R  R  R   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR    s    	
		

		

		/!	"		% 			(   t   __name__t
   __module__t   __doc__RA   Rh   RY   Re   Ry   R   R   Rr   t   propertyRj   Rk   Rl   Rm   R   t   staticmethodR   R   R   R   R   R   R   R   R   R   R  R  R  (    (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR      sB    			/	8@=r	h	hR   c           B` s   e  Z d  Z d d  Z e d    Z e d    Z e d    Z e d    Z e d    Z	 e d    Z
 e d	    Z e d
    Z d d e d d d  Z d d d  Z e j j e _ RS(   sg  
    Class to hold results from fitting an SARIMAX model.

    Parameters
    ----------
    model : SARIMAX instance
        The fitted model instance

    Attributes
    ----------
    specification : dictionary
        Dictionary including all attributes from the SARIMAX model instance.
    polynomial_ar : array
        Array containing autoregressive lag polynomial coefficients,
        ordered from lowest degree to highest. Initialized with ones, unless
        a coefficient is constrained to be zero (in which case it is zero).
    polynomial_ma : array
        Array containing moving average lag polynomial coefficients,
        ordered from lowest degree to highest. Initialized with ones, unless
        a coefficient is constrained to be zero (in which case it is zero).
    polynomial_seasonal_ar : array
        Array containing seasonal autoregressive lag polynomial coefficients,
        ordered from lowest degree to highest. Initialized with ones, unless
        a coefficient is constrained to be zero (in which case it is zero).
    polynomial_seasonal_ma : array
        Array containing seasonal moving average lag polynomial coefficients,
        ordered from lowest degree to highest. Initialized with ones, unless
        a coefficient is constrained to be zero (in which case it is zero).
    polynomial_trend : array
        Array containing trend polynomial coefficients, ordered from lowest
        degree to highest. Initialized with ones, unless a coefficient is
        constrained to be zero (in which case it is zero).
    model_orders : list of int
        The orders of each of the polynomials in the model.
    param_terms : list of str
        List of parameters actually included in the model, in sorted order.

    See Also
    --------
    statsmodels.tsa.statespace.kalman_filter.FilterResults
    statsmodels.tsa.statespace.mlemodel.MLEResults
    t   opgc   
      K` s  t  t |   j | | | | |  t j |  _ |  j j   |  _ t	 i |  j j
 d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d	 6|  j j d
 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j d 6|  j j  d 6  |  _! |  j j" |  _# |  j j$ |  _% |  j j& |  _' |  j j( |  _) |  j j* |  _+ t j, |  j% |  j)  |  _- t j, |  j' |  j+  |  _. |  j j/ |  _/ |  j j0 |  _0 d } } x |  j0 D] } | d k rN|  j j }	 n^ | d k ri|  j j }	 nC | d k r|  j j1 }	 n( | d k r|  j j2 }	 n |  j/ | }	 | |	 7} t3 |  d | |  j4 | | ! | |	 7} q-W|  j5 j6 d d g  d  S(    NR.   R&   R'   R)   R*   R+   R,   R-   R#   R$   RJ   RO   RG   RK   RM   RP   RI   RL   R%   RT   RW   R(   RX   i    R   R   R   R   s
   _params_%sR]   R^   (7   Rd   R   Re   R2   t   inft   df_residt   modelRy   t
   _init_kwdsR   R.   R&   R'   R)   R*   R+   R,   R-   R#   R$   RJ   RO   RG   RK   RM   RP   RI   RL   R%   RT   RW   R(   RX   t   specificationRE   RB   R8   R6   R:   R9   R>   R;   R@   R?   R   t   polynomial_reduced_art   polynomial_reduced_maR   R   RN   RQ   t   setattrR   t   _data_attr_modelt   extend(
   Rs   R  R   t   filter_resultst   cov_typeRu   R   R   R   R   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRe     sl    


c         C` s   t  j |  j  d S(   sQ   
        (array) Roots of the reduced form autoregressive lag polynomial
        i(   R2   t   rootsR   (   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   arroots  s    c         C` s   t  j |  j  d S(   sQ   
        (array) Roots of the reduced form moving average lag polynomial
        i(   R2   R'  R!  (   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   maroots  s    c         C` s7   |  j  } | j s d St j | j | j  d t j S(   sj   
        (array) Frequency of the roots of the reduced form autoregressive
        lag polynomial
        Ni   (   R(  t   sizeR2   t   arctan2t   imagR  t   pi(   Rs   t   z(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   arfreq  s    		c         C` s7   |  j  } | j s d St j | j | j  d t j S(   sj   
        (array) Frequency of the roots of the reduced form moving average
        lag polynomial
        Ni   (   R)  R*  R2   R+  R,  R  R-  (   Rs   R.  (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   mafreq  s    		c         C` s   |  j  S(   s   
        (array) Autoregressive parameters actually estimated in the model.
        Does not include seasonal autoregressive parameters (see
        `seasonalarparams`) or parameters whose values are constrained to be
        zero.
        (   t
   _params_ar(   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   arparams  s    c         C` s   |  j  S(   s   
        (array) Seasonal autoregressive parameters actually estimated in the
        model. Does not include nonseasonal autoregressive parameters (see
        `arparams`) or parameters whose values are constrained to be zero.
        (   t   _params_seasonal_ar(   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   seasonalarparams  s    c         C` s   |  j  S(   s   
        (array) Moving average parameters actually estimated in the model.
        Does not include seasonal moving average parameters (see
        `seasonalmaparams`) or parameters whose values are constrained to be
        zero.
        (   t
   _params_ma(   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   maparams#  s    c         C` s   |  j  S(   s   
        (array) Seasonal moving average parameters actually estimated in the
        model. Does not include nonseasonal moving average parameters (see
        `maparams`) or parameters whose values are constrained to be zero.
        (   t   _params_seasonal_ma(   Rs   (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   seasonalmaparams-  s    c         K` s  | d
 k r |  j j d } n  |  j j | | | d t \ } } }	 }
 |	 rB|  j j |  j j d k rB|  j j j j	 d |	 } t
 j | |  j j f  } |  j j d k rM| d
 k r t d   n  t
 j |  } |	 |  j j f } | j	 | k s%t d t |  t | j	  f   n  t
 j |  j j j j | j f j } n  |  j j   } | | d <t | |  } | j |  j  x |  j j j   D] } | d k rqn  t | j |  } | j	 d d k rt | j	  d	 k r| d
 d
  |	 d
  f | | <q;| d
 d
  d
 d
  |	 d
  f | | <qqWn. |  j j d k rp| d
 k	 rpt d t  n  t  t! |   j" d | d | d | d | d | |  S(   sE  
        In-sample prediction and out-of-sample forecasting

        Parameters
        ----------
        start : int, str, or datetime, optional
            Zero-indexed observation number at which to start forecasting, ie.,
            the first forecast is start. Can also be a date string to
            parse or a datetime type. Default is the the zeroth observation.
        end : int, str, or datetime, optional
            Zero-indexed observation number at which to end forecasting, ie.,
            the first forecast is start. Can also be a date string to
            parse or a datetime type. However, if the dates index does not
            have a fixed frequency, end must be an integer index if you
            want out of sample prediction. Default is the last observation in
            the sample.
        exog : array_like, optional
            If the model includes exogenous regressors, you must provide
            exactly enough out-of-sample values for the exogenous variables if
            end is beyond the last observation in the sample.
        dynamic : boolean, int, str, or datetime, optional
            Integer offset relative to `start` at which to begin dynamic
            prediction. Can also be an absolute date string to parse or a
            datetime type (these are not interpreted as offsets).
            Prior to this observation, true endogenous values will be used for
            prediction; starting with this observation and continuing through
            the end of prediction, forecasted endogenous values will be used
            instead.
        full_results : boolean, optional
            If True, returns a FilterResults instance; if False returns a
            tuple with forecasts, the forecast errors, and the forecast error
            covariance matrices. Default is False.
        **kwargs
            Additional arguments may required for forecasting beyond the end
            of the sample. See `FilterResults.predict` for more details.

        Returns
        -------
        forecast : array
            Array of out of sample forecasts.
        i    t   silents~   Out-of-sample forecasting in a model with a regression component requires additional exogenous values via the `exog` argument.sP   Provided exogenous values are not of the appropriate shape. Required %s, got %s.R   t   obsii   i   Ns_   Exogenous array provided to predict, but additional data not required. `exog` argument ignored.R   R   t   dynamict   index(#   RA   R  R   t   _get_prediction_indexRY   RW   RT   R   R]   RF   R2   R   t   k_endogR/   RC   t   strR   R^   R   R  R7   R   R  R   R%  t   shapesRp   R|   Rf   R<   R   R   Rd   R   t   get_prediction(   Rs   R   R   R;  R<  R   Ru   t   _startt   _endt   _out_of_samplet   prediction_indexRc   Rt   t   required_exog_shapet   model_kwargsR  R   t   mat(    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRA  6  sD    +*"	(
$4
g?c         C` sh  d } |  j  j |  j  j |  j  j d k r |  j  j |  j  j k rS |  j  j } n t |  j j   d d  } |  j  j |  j  j k r |  j  j } n t |  j	 j   d d  } |  j  j
 r d n	 |  j  j } d | | | f } n  d } |  j  j |  j  j |  j  j d k } | r'|  j  j |  j  j k rQt |  j  j |  j  j  }	 n t |  j j   d d  }	 |  j  j |  j  j k rt |  j  j |  j  j  }
 n t |  j j   d d  }
 |  j  j } |  j  j
 rd } n  d t |	  | t |
  |  j  j f } | d k s'| d 7} q'n  d |  j  j j | | f } t t |   j d | d	 | d
 |  S(   NR   i    i   s   (%s, %d, %s)s   (%s, %d, %s, %d)t   xs   %s%s%st   alphaR   t
   model_name(   R  RG   RJ   RK   RI   t   tupleR6   R   RL   R9   R)   RM   RO   RP   R1   R.   R;   R?   R?  t	   __class__R  Rd   R   t   summary(   Rs   RJ  R   R#   t   order_art   order_maRJ   R$   t   has_seasonalt   order_seasonal_art   order_seasonal_maRO   RK  (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyRN    sB    &
			N(   R  R  R  Re   R   R(  R)  R/  R0  R2  R4  R6  R8  RA   Rh   RA  RN  R   (    (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR   p  s   *Q
	
	^;R   c           B` s>   e  Z i  Z e j e j e  Z i  Z e j e j e  Z RS(    (	   R  R  t   _attrst   wrapt   union_dictsR   t   _wrap_attrst   _methodst   _wrap_methods(    (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyR     s   	(*   R  t
   __future__R    R   R   t   warningsR   t   numpyR2   t   statsmodels.compat.pythonR   t   statsmodels.tools.toolsR   t   statsmodels.tools.dataR   t   statsmodels.tools.decoratorsR   t   statsmodels.tools.sm_exceptionsR   t   statsmodels.base.wrappert   baset   wrapperRU  t   statsmodels.tsa.tsatoolsR	   Rq   R
   t   mlemodelR   R   R   t   toolsR   R   R   R   R   R   R   R   R   t   populate_wrapper(    (    (    sA   lib/python2.7/site-packages/statsmodels/tsa/statespace/sarimax.pyt   <module>   s0   .      X d