U
    KvfV                  	   @   sN   d Z ddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ dddZdS )zX
State space approach to estimating SARIMAX models.

Author: Chad Fulton
License: BSD-3
    N)add_constantBunch)SARIMAX)SARIMAXSpecification)SARIMAXParamsr   r   r   r   r   r   r   TFc
              	   C   s   |r|dkrt | nt|}t| ||||||d}
|
j} |
j}t|
d}|dk	rt|
d}||_|
jrv|j	svt
d|
jr|jst
dt| ||
j|
j|
j|
j|
jd}|	dkri }	|	dd |jf d|i|	}|j|_t|
|d	}||fS )
a	  
    Estimate SARIMAX parameters using state space methods.

    Parameters
    ----------
    endog : array_like
        Input time series array.
    order : tuple, optional
        The (p,d,q) order of the model for the number of AR parameters,
        differences, and MA parameters. Default is (0, 0, 0).
    seasonal_order : tuple, optional
        The (P,D,Q,s) order of the seasonal component of the model for the
        AR parameters, differences, MA parameters, and periodicity. Default
        is (0, 0, 0, 0).
    include_constant : bool, optional
        Whether to add a constant term in `exog` if it's not already there.
        The estimate of the constant will then appear as one of the `exog`
        parameters. If `exog` is None, then the constant will represent the
        mean of the process.
    enforce_stationarity : bool, optional
        Whether or not to transform the AR parameters to enforce stationarity
        in the autoregressive component of the model. Default is True.
    enforce_invertibility : bool, optional
        Whether or not to transform the MA parameters to enforce invertibility
        in the moving average component of the model. Default is True.
    concentrate_scale : bool, 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.
    start_params : array_like, optional
        Initial guess of the solution for the loglikelihood maximization. The
        AR polynomial must be stationary. If `enforce_invertibility=True` the
        MA poylnomial must be invertible. If not provided, default starting
        parameters are computed using the Hannan-Rissanen method.
    fit_kwargs : dict, optional
        Arguments to pass to the state space model's `fit` method.

    Returns
    -------
    parameters : SARIMAXParams object
    other_results : Bunch
        Includes two components, `spec`, containing the `SARIMAXSpecification`
        instance corresponding to the input arguments; and
        `state_space_results`, corresponding to the results from the underlying
        state space model and Kalman filter / smoother.

    Notes
    -----
    The primary reference is [1]_.

    References
    ----------
    .. [1] Durbin, James, and Siem Jan Koopman. 2012.
       Time Series Analysis by State Space Methods: Second Edition.
       Oxford University Press.
    N)exogorderseasonal_orderenforce_stationarityenforce_invertibilityconcentrate_scale)specz]Given starting parameters imply a non-stationary AR process with `enforce_stationarity=True`.z^Given starting parameters imply a non-invertible MA process with `enforce_invertibility=True`.Zdispr   start_params)r   Zstatespace_results)npZ	ones_liker   r   endogr	   r   paramsr   Zis_stationary
ValueErrorr   Zis_invertibler   r
   r   r   
setdefaultZfitr   )r   r	   r
   r   Zinclude_constantr   r   r   r   Z
fit_kwargsr   pspmodZres_ssres r   O/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/tsa/arima/estimators/statespace.py
statespace   sJ    >   


r   )	Nr   r   TTTFNN)__doc__Znumpyr   Zstatsmodels.tools.toolsr   r   Z"statsmodels.tsa.statespace.sarimaxr   Z#statsmodels.tsa.arima.specificationr   Zstatsmodels.tsa.arima.paramsr   r   r   r   r   r   <module>   s               