
    M/PhV                     V    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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
           	      R   |r%|t          j        |           nt          |          }t          | ||||||          }
|
j        } |
j        }t          |
          }|Qt          |
          }||_        |
j        r|j	        st          d          |
j        r|j        st          d          t          | ||
j        |
j        |
j        |
j        |
j                  }|	i }	|	                    dd            |j        d
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`.dispr   start_params)r   statespace_results )np	ones_liker   r   endogr   r   paramsr   is_stationary
ValueErrorr   is_invertibler   r   r   r   
setdefaultfitr   )r   r   r   r   include_constantr   r   r   r   
fit_kwargsr   pspmodres_ssress                   k/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/arima/estimators/statespace.py
statespacer'      s   |  K&*lr|E"""T8J8J  Dn13+	- - -D
 JE9D4   A %%% 	$ 	NR-= 	N M N N N % 	Ob.> 	O N O O O %d$*!%!4'+'@(,(B$($:	< < <C
 
&!$$$SW==,=*==F }AH
$   C
 c6M    )	Nr   r	   TTTFNN)__doc__numpyr   statsmodels.tools.toolsr   r   "statsmodels.tsa.statespace.sarimaxr   #statsmodels.tsa.arima.specificationr   statsmodels.tsa.arima.paramsr   r'   r   r(   r&   <module>r/      s         7 7 7 7 7 7 7 7 6 6 6 6 6 6 D D D D D D 6 6 6 6 6 6 (1=A@DFJj j j j j jr(   