
    M/Ph                     |    d Z ddlZddlZddlmZ ddlmZ ddl	m
Z
mZmZmZmZmZ ddlmZmZ  G d d          ZdS )	zB
SARIMAX specification class.

Author: Chad Fulton
License: BSD-3
    N)_is_using_pandas)TimeSeriesModel)is_invertibleconstrain_stationary_univariate!unconstrain_stationary_univariateprepare_exogprepare_trend_specprepare_trend_data)standardize_lag_ordervalidate_basicc                      e Zd 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e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 Zd#dZ	 	 	 d$dZd Zd Zd Zd%dZd  Zd! ZdS )&SARIMAXSpecificationa%  
    SARIMAX specification.

    Parameters
    ----------
    endog : array_like, optional
        The observed time-series process :math:`y`.
    exog : array_like, optional
        Array of exogenous regressors.
    order : tuple, optional
        The (p,d,q) order of the model for the autoregressive, differences, and
        moving average components. d is always an integer, while p and q may
        either be integers or lists of integers. May not be used in combination
        with the arguments `ar_order`, `diff`, or `ma_order`.
    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). D and s are always integers, while P and Q
        may either be integers or lists of positive integers. May not be used
        in combination with the arguments `seasonal_ar_order`, `seasonal_diff`,
        or `seasonal_ma_order`.
    ar_order : int or list of int
        The autoregressive order of the model. May be an integer, in which case
        all autoregressive lags up to and including it will be included.
        Alternatively, may be a list of integers specifying which lag orders
        are included. May not be used in combination with `order`.
    diff : int
        The order of integration of the model. May not be used in combination
        with `order`.
    ma_order : int or list of int
        The moving average order of the model. May be an integer or
        list of integers. See the documentation for `ar_order` for details.
        May not be used in combination with `order`.
    seasonal_ar_order : int or list of int
        The seasonal autoregressive order of the model. May be an integer or
        list of integers. See the documentation for `ar_order` for examples.
        Note that if `seasonal_periods = 4` and `seasonal_ar_order = 2`, then
        this implies that the overall model will include lags 4 and 8.
        May not be used in combination with `seasonal_order`.
    seasonal_diff : int
        The order of seasonal integration of the model. May not be used in
        combination with `seasonal_order`.
    seasonal_ma_order : int or list of int
        The moving average order of the model. May be an integer or
        list of integers. See the documentation for `ar_order` and
        `seasonal_ar_order` for additional details. May not be used in
        combination with `seasonal_order`.
    seasonal_periods : int
        Number of periods in a season. May not be used in combination with
        `seasonal_order`.
    enforce_stationarity : bool, optional
        Whether or not to require the autoregressive parameters to correspond
        to a stationarity process. This is only possible in estimation by
        numerical maximum likelihood.
    enforce_invertibility : bool, optional
        Whether or not to require the moving average parameters to correspond
        to an invertible process. This is only possible in estimation by
        numerical maximum likelihood.
    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 by one.
        This is only applicable when considering estimation by numerical
        maximum likelihood.
    dates : array_like of datetime, optional
        If no index is given by `endog` or `exog`, an array-like object of
        datetime objects can be provided.
    freq : str, optional
        If no index is given by `endog` or `exog`, the frequency of the
        time-series may be specified here as a Pandas offset or offset string.
    missing : str
        Available options are 'none', 'drop', and 'raise'. If 'none', no nan
        checking is done. If 'drop', any observations with nans are dropped.
        If 'raise', an error is raised. Default is 'none'.

    Attributes
    ----------
    order : tuple, optional
        The (p,d,q) order of the model for the autoregressive, differences, and
        moving average components. d is always an integer, while p and q may
        either be integers or lists of integers.
    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). D and s are always integers, while P and Q
        may either be integers or lists of positive integers.
    ar_order : int or list of int
        The autoregressive order of the model. May be an integer, in which case
        all autoregressive lags up to and including it will be included. For
        example, if `ar_order = 3`, then the model will include lags 1, 2,
        and 3. Alternatively, may be a list of integers specifying exactly
        which lag orders are included. For example, if `ar_order = [1, 3]`,
        then the model will include lags 1 and 3 but will exclude lag 2.
    diff : int
        The order of integration of the model.
    ma_order : int or list of int
        The moving average order of the model. May be an integer or
        list of integers. See the documentation for `ar_order` for examples.
    seasonal_ar_order : int or list of int
        The seasonal autoregressive order of the model. May be an integer or
        list of integers. See the documentation for `ar_order` for examples.
        Note that if `seasonal_periods = 4` and `seasonal_ar_order = 2`, then
        this implies that the overall model will include lags 4 and 8.
    seasonal_diff : int
        The order of seasonal integration of the model.
    seasonal_ma_order : int or list of int
        The moving average order of the model. May be an integer or
        list of integers. See the documentation for `ar_order` and
        `seasonal_ar_order` for additional details.
    seasonal_periods : int
        Number of periods in a season.
    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.
    ar_lags : list of int
        List of included autoregressive lags. If `ar_order` is a list, then
        `ar_lags == ar_order`. If `ar_lags = [1, 2]`, then the overall model
        will include the 1st and 2nd autoregressive lags.
    ma_lags : list of int
        List of included moving average lags. If `ma_order` is a list, then
        `ma_lags == ma_order`. If `ma_lags = [1, 2]`, then the overall model
        will include the 1st and 2nd moving average lags.
    seasonal_ar_lags : list of int
        List of included seasonal autoregressive lags. If `seasonal_ar_order`
        is a list, then `seasonal_ar_lags == seasonal_ar_order`. If
        `seasonal_periods = 4` and `seasonal_ar_lags = [1, 2]`, then the
        overall model will include the 4th and 8th autoregressive lags.
    seasonal_ma_lags : list of int
        List of included seasonal moving average lags. If `seasonal_ma_order`
        is a list, then `seasonal_ma_lags == seasonal_ma_order`. See the
        documentation to `seasonal_ar_lags` for examples.
    max_ar_order : int
        Largest included autoregressive lag.
    max_ma_order : int
        Largest included moving average lag.
    max_seasonal_ar_order : int
        Largest included seasonal autoregressive lag.
    max_seasonal_ma_order : int
        Largest included seasonal moving average lag.
    max_reduced_ar_order : int
        Largest lag in the reduced autoregressive polynomial. Equal to
        `max_ar_order + max_seasonal_ar_order * seasonal_periods`.
    max_reduced_ma_order : int
        Largest lag in the reduced moving average polynomial. Equal to
        `max_ma_order + max_seasonal_ma_order * seasonal_periods`.
    enforce_stationarity : bool
        Whether or not to transform the AR parameters to enforce stationarity
        in the autoregressive component of the model. This is only possible
        in estimation by numerical maximum likelihood.
    enforce_invertibility : bool
        Whether or not to transform the MA parameters to enforce invertibility
        in the moving average component of the model. This is only possible
        in estimation by numerical maximum likelihood.
    concentrate_scale : bool
        Whether or not to concentrate the variance (scale term) out of the
        log-likelihood function. This is only applicable when considering
        estimation by numerical maximum likelihood.
    is_ar_consecutive
    is_ma_consecutive
    is_integrated
    is_seasonal
    k_exog_params
    k_ar_params
    k_ma_params
    k_seasonal_ar_params
    k_seasonal_ma_params
    k_params
    exog_names
    ar_names
    ma_names
    seasonal_ar_names
    seasonal_ma_names
    param_names

    Examples
    --------
    >>> SARIMAXSpecification(order=(1, 0, 2))
    SARIMAXSpecification(endog=y, order=(1, 0, 2))

    >>> spec = SARIMAXSpecification(ar_order=1, ma_order=2)
    SARIMAXSpecification(endog=y, order=(1, 0, 2))

    >>> spec = SARIMAXSpecification(ar_order=1, seasonal_order=(1, 0, 0, 4))
    SARIMAXSpecification(endog=y, order=(1, 0, 0), seasonal_order=(1, 0, 0, 4))
    N   noneTc                 p   || _         || _        || _        || _        |d u}|d up|d up|d u}|d u}|d up|	d up|
d up|d u}|r|rt	          d          |r|rt	          d          |r|dn|}|dn|}|dn|}|||f}n|sd}|r|dn|}|	dn|	}	|
dn|
}
|dn|}||	|
|f}n|sd}t          |          dk    rt	          d          t          |          dk    rt	          d	          |r|d
         dk     rt	          d          |d
         t          |d
                   k    rt	          d          |d
         dk     rt	          d          |d
         t          |d
                   k    rt	          d          |d         dk     rt	          d          t          |d         d          t          |d
                   t          |d         d          f}t          |d         d          t          |d
                   t          |d         d          t          |d                   f}|rZ|d         d
k    rt	          d          |d         dk    s|d
         dk    s|d         dk    r|d         dk    rt	          d          || _        |\  | _	        | _
        | _        || _        |\  | _        | _        | _        | _        t#          | j	        t$                    r| j	        | _        n4t)          j        d
| j	        d
z                                             | _        t#          | j        t$                    r| j        | _        n4t)          j        d
| j        d
z                                             | _        t#          | j        t$                    r| j        | _        n4t)          j        d
| j        d
z                                             | _        t#          | j        t$                    r| j        | _        n4t)          j        d
| j        d
z                                             | _        | j        r| j        d         nd| _        | j        r| j        d         nd| _        | j        r| j        d         nd| _        | j        r| j        d         nd| _        | j        | j        | j        z  z   | _        | j        | j        | j        z  z   | _        tA          | j                  }tA          t)          j!        | j                  | j        z            }|"                    |          }|r%t          |          dk    rt	          d|z            tA          | j                  }tA          t)          j!        | j                  | j        z            }|"                    |          }|r%t          |          dk    rt	          d|z            || _#        tI          |          \  | _%        }tM          |d           } |r|t          | j%                  dk    ru| j%        d         d
k    rdt)          j'        |          }!t)          j(        |!d          }"|"dk    }#|#|!d         dk    z  }$|$}%t)          j)        |%          rt	          d          t)          j*        | j%        d
k              d         | _+        t          | j+                  | _,        t          | j+                  dk    rd | _-        d | _.        nt)          j/        | j+        t)          j        t          | j+                            k              r%| j+        d         | _-        | j+        d         | _.        n| j+        | _-        | j+        d         | _.        ta          |          \  | _1        }|d u }&|2|g n-t)          j2        t          |                    t(          j3        z  }|t          |          nt          |          }'| j-        x| 4                    |'|          }(||(}n]| rGtk          j6        |(|j7        | 8                                          }(tk          j9        |(|gd
          }nt(          j:        |(|f         }tw          |||||          | _<        |&rd n| j<        j=        | _=        | j<        j>        | _>        |rQ|&sO| j=        j?        d
k    r?| j=        j@        d
         d
k    r)t	          dt          | j=        j@                  z            |&rd n*t)          j)        t)          jB        | j=                            | _C        d S )NzCCannot specify both `order` and either of `ar_order` or `ma_order`.zpCannot specify both `seasonal_order` and any of `seasonal_ar_order`, `seasonal_ma_order`, or `seasonal_periods`.r   )r   r   r   )r   r   r   r      z9`order` argument must be an iterable with three elements.   zA`seasonal_order` argument must be an iterable with four elements.r   z%Cannot specify negative differencing.z'Cannot specify fractional differencing.z.Cannot specify negative seasonal differencing.z0Cannot specify fractional seasonal differencing.z-Cannot specify negative seasonal periodicity.AR   MAzseasonal ARzseasonal MAz,Seasonal periodicity must be greater than 1.zXMust include nonzero seasonal periodicity if including seasonal AR, MA, or differencing.zlInvalid model: autoregressive lag(s) %s are in both the seasonal and non-seasonal autoregressive components.zlInvalid model: moving average lag(s) %s are in both the seasonal and non-seasonal moving average components.)axiszuA constant trend was included in the model specification, but the `exog` data already contains a column of constants.)indexcolumns)exogdatesfreqmissingz8SARIMAX models require univariate `endog`. Got shape %s.)Denforce_stationarityenforce_invertibilityconcentrate_scaletrend_offset
ValueErrorlenintr   orderar_orderdiffma_orderseasonal_orderseasonal_ar_orderseasonal_diffseasonal_ma_orderseasonal_periods
isinstancelistar_lagsnparangetolistma_lagsseasonal_ar_lagsseasonal_ma_lagsmax_ar_ordermax_ma_ordermax_seasonal_ar_ordermax_seasonal_ma_ordermax_reduced_ar_ordermax_reduced_ma_ordersetarrayintersectiontrendr	   
trend_polyr   
asanyarrayptpanywheretrend_termsk_trendtrend_ordertrend_degreeallr   k_exogzerosnanconstruct_trend_datapd	DataFramer   construct_trend_namesconcatc_r   _modelendogr   ndimshapestrisnan_has_missing))selfrV   r   r&   r*   r'   r(   r)   r+   r,   r-   r.   rA   r   r    r!   r"   r   r   r   validate_specification	has_orderhas_specific_orderhas_seasonal_orderhas_specific_seasonal_orderr1   r6   duplicate_ar_lagsr5   r7   duplicate_ma_lags_exog_is_pandasxptp0col_is_constnz_const	col_const
faux_endognobs
trend_datas)                                            c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/arima/specification.py__init__zSARIMAXSpecification.__init__   s
    %9!%:"!2( %	&d2 3d$6F 3&d2 	+47'8'D (D'4D'@(D'8'D(D (8t'C 	$  	;+ 	; : ; ; ; 	8"= 	8 7 8 8 8
  	$,qq(H11$D$,qq(HtX.EE 	E ' 	*&.4E !.!6AAMM&.4E  &-3C //1ACNN# 	*)N u::?? * + + +~!## 4 5 5 5 " 	2Qx!|| !HIIIQx3uQx==(( !JKKKa 1$$  "2 3 3 3a Cq(9$:$:::  "2 3 3 3a 1$$  "1 2 2 2
 "%(D11aMM!%(D113
 "."3]CCq!""!."3]CCq!""	$ " 	3a A%%  ", - - -"a''>!+<+A+A"1%**q0AQ0F0F  "2 3 3 3
 
27/ty$-,"0	 	!3T5K		 dmT** 	D=DLL9Q(9::AACCDLdmT** 	D=DLL9Q(9::AACCDLd,d33 	C$($:D!! 	!T3a788??AA !d,d33 	C$($:D!! 	!T3a788??AA ! 15CDL,,!04CDL,,! *.)>ED!"%%A 	" *.)>ED!"%%A 	" &)>>? 	! &)>>? 	! dl##rx(=>>!%!6 7 8 8#001ABB! 	2c*;&<&<q&@&@ ;  11 2 2 2
 dl##rx(=>>!%!6 7 8 8#001ABB! 	2c*;&<&<q&@&@ ;  11 2 2 2 
/66 *$55" 	Et'7DO$$q((T_Q-?1-D-Dd##A6!!$$$D19L#qtqy1H I vi   E  "D E E E 8DOq$899!< 4+,,t  A%%#D $DVD$	#d6F2G2G(H(HHII 	5#/3D $ 0 4D#/D $ 0 4D )..T d]
=,BBBHSYY,?,?"&,HE "\s5zzzs4yy'224FFJ|! /\*DJ262L2L2N2NP P P
y*d!3!<<<uZ-.
 &e$e$.57 7 7'>TTT[->
K$	 # 	C: 	C
!##
(8(;a(?(? *,/
0@,A,AB C C C @DDBF28DJ+?+?$@$@ 	    c                 N    | j         dk    ot          | j        t                     S )z
        (bool) Is autoregressive lag polynomial consecutive.

        I.e. does it include all lags up to and including the maximum lag.
        r   )r:   r/   r'   r0   r\   s    rn   is_ar_consecutivez&SARIMAXSpecification.is_ar_consecutive  +     *a/ 4t}d333	5rp   c                 N    | j         dk    ot          | j        t                     S )z
        (bool) Is moving average lag polynomial consecutive.

        I.e. does it include all lags up to and including the maximum lag.
        r   )r;   r/   r)   r0   rr   s    rn   is_ma_consecutivez&SARIMAXSpecification.is_ma_consecutive  rt   rp   c                 .    | j         dk    p
| j        dk    S )zq
        (bool) Is the model integrated.

        I.e. does it have a nonzero `diff` or `seasonal_diff`.
        r   )r(   r,   rr   s    rn   is_integratedz"SARIMAXSpecification.is_integrated  s     y1}6 2Q 66rp   c                     | j         dk    S )z3(bool) Does the model include a seasonal component.r   )r.   rr   s    rn   is_seasonalz SARIMAXSpecification.is_seasonal  s     $))rp   c                 *    t          | j                  S )z?(int) Number of parameters associated with exogenous variables.)r$   
exog_namesrr   s    rn   k_exog_paramsz"SARIMAXSpecification.k_exog_params  s     4?###rp   c                 *    t          | j                  S )z9(int) Number of autoregressive (non-seasonal) parameters.)r$   r1   rr   s    rn   k_ar_paramsz SARIMAXSpecification.k_ar_params       4<   rp   c                 *    t          | j                  S )z9(int) Number of moving average (non-seasonal) parameters.)r$   r5   rr   s    rn   k_ma_paramsz SARIMAXSpecification.k_ma_params  r   rp   c                 *    t          | j                  S )z3(int) Number of seasonal autoregressive parameters.)r$   r6   rr   s    rn   k_seasonal_ar_paramsz)SARIMAXSpecification.k_seasonal_ar_params       4()))rp   c                 *    t          | j                  S )z3(int) Number of seasonal moving average parameters.)r$   r7   rr   s    rn   k_seasonal_ma_paramsz)SARIMAXSpecification.k_seasonal_ma_params  r   rp   c                 l    | j         | j        z   | j        z   | j        z   | j        z   }| j        s|dz  }|S )z'(int) Total number of model parameters.r   )r}   r   r   r   r   r!   )r\   k_paramss     rn   r   zSARIMAXSpecification.k_params  sL     &)99D<LL-.040IJ% 	MHrp   c                 &    | j         j        }|g n|S )z9(list of str) Names associated with exogenous parameters.)rU   r|   )r\   r|   s     rn   r|   zSARIMAXSpecification.exog_names  s     [+
'rrZ7rp   c                 $    d | j         D             S )z@(list of str) Names of (non-seasonal) autoregressive parameters.c                     g | ]}d |z  S )zar.L%d .0is     rn   
<listcomp>z1SARIMAXSpecification.ar_names.<locals>.<listcomp>      3331333rp   )r1   rr   s    rn   ar_nameszSARIMAXSpecification.ar_names       43dl3333rp   c                 $    d | j         D             S )z@(list of str) Names of (non-seasonal) moving average parameters.c                     g | ]}d |z  S )zma.L%dr   r   s     rn   r   z1SARIMAXSpecification.ma_names.<locals>.<listcomp>  r   rp   )r5   rr   s    rn   ma_nameszSARIMAXSpecification.ma_names  r   rp   c                 8    | j         fd| j        D             S )z:(list of str) Names of seasonal autoregressive parameters.c                      g | ]
}d |z  z  S )zar.S.L%dr   r   r   ss     rn   r   z:SARIMAXSpecification.seasonal_ar_names.<locals>.<listcomp>$  "    DDD
a!e$DDDrp   )r.   r6   r\   r   s    @rn   seasonal_ar_namesz&SARIMAXSpecification.seasonal_ar_names   *     !DDDDd.CDDDDrp   c                 8    | j         fd| j        D             S )z:(list of str) Names of seasonal moving average parameters.c                      g | ]
}d |z  z  S )zma.S.L%dr   r   s     rn   r   z:SARIMAXSpecification.seasonal_ma_names.<locals>.<listcomp>*  r   rp   )r.   r7   r   s    @rn   seasonal_ma_namesz&SARIMAXSpecification.seasonal_ma_names&  r   rp   c                     | j         | j        z   | j        z   | j        z   | j        z   }| j        s|                    d           |S )z,(list of str) Names of all model parameters.sigma2)r|   r   r   r   r   r!   append)r\   namess     rn   param_namesz SARIMAXSpecification.param_names,  sR     4=04=@'(*.*@A% 	#LL"""rp   c                 "   h d}| j         dk    }| j        dk    }| j        dk    }| j        r|                    dg           | j        r| j         dk    s| j        r"| j        dk    r|                    ddg           |s	| j        r|r|                    d           |s	| j	        r|r*|                    d           |                    d           |r|                    d           | j        d	u s| j
        r|                    d           |S )
a  
        (list of str) Estimators that could be used with specification.

        Note: does not consider the presense of `exog` in determining valid
        estimators. If there are exogenous variables, then feasible Generalized
        Least Squares should be used through the `gls` estimator, and the
        `valid_estimators` are the estimators that could be passed as the
        `arma_estimator` argument to `gls`.
        >   burg
statespaceinnovationsyule_walkerhannan_rissaneninnovations_mler   r   r   r   r   r   r   F)r8   r9   r.   r[   intersection_updater   r    rv   discardrs   r!   )r\   
estimatorshas_arhas_mahas_seasonals        rn   valid_estimatorsz%SARIMAXSpecification.valid_estimators5  sq   J J J
 "a'"a',1  	;**L>::: & 	N4+<q+@+@+ ,A040AA0E0E**,=|+LMMM  	./ 	.< 	.}--- 	'/ 	'< 	'}---v&&& 	20111 $--1G-0111rp   c                 X   | j         dk    }| j        dk    }| j        dk    }| j        }ddddddd}|d	k    r|rt	          d
||         z            |dvrT| j         dk    r| j        rt	          d||         z            | j        dk    r| j        rt	          d||         z            |dv rU|rt	          d||         z            | j        st	          d||         z            |rt	          d||         z            dS |dk    r:|rt	          d          | j        st	          d          |rt	          d          dS |dk    r|rt	          d          dS |dk    r0| j        du rt	          d          | j	        rt	          d          dS |d	k    rdS t	          d|z            )a  
        Validate an SARIMA estimator.

        Parameters
        ----------
        estimator : str
            Name of the estimator to validate against the current state of
            the specification. Possible values are: 'yule_walker', 'burg',
            'innovations', 'hannan_rissanen', 'innovoations_mle', 'statespace'.

        Notes
        -----
        This method will raise a `ValueError` if an invalid method is passed,
        and otherwise will return None.

        This method does not consider the presense of `exog` in determining
        valid estimators. If there are exogenous variables, then feasible
        Generalized Least Squares should be used through the `gls` estimator,
        and a "valid" estimator is one that could be passed as the
        `arma_estimator` argument to `gls`.

        This method only uses the attributes `enforce_stationarity` and
        `concentrate_scale` to determine the validity of numerical maximum
        likelihood estimators. These only include 'innovations_mle' (which
        does not support `enforce_stationarity=False` or
        `concentrate_scale=True`) and 'statespace' (which supports all
        combinations of each).

        Examples
        --------
        >>> spec = SARIMAXSpecification(order=(1, 0, 2))

        >>> spec.validate_estimator('yule_walker')
        ValueError: Yule-Walker estimator does not support moving average
                    components.

        >>> spec.validate_estimator('burg')
        ValueError: Burg estimator does not support moving average components.

        >>> spec.validate_estimator('innovations')
        ValueError: Burg estimator does not support autoregressive components.

        >>> spec.validate_estimator('hannan_rissanen')  # returns None
        >>> spec.validate_estimator('innovations_mle')  # returns None
        >>> spec.validate_estimator('statespace')       # returns None

        >>> spec.validate_estimator('not_an_estimator')
        ValueError: "not_an_estimator" is not a valid estimator.
        r   zYule-WalkerBurgInnovationszHannan-RissanenzInnovations MLEzState space)r   r   r   r   r   r   r   z8%s estimator does not support missing values in `endog`.)r   r   zG%s estimator cannot enforce a stationary autoregressive lag polynomial.zH%s estimator cannot enforce an invertible moving average lag polynomial.)r   r   z2%s estimator does not support seasonal components.zB%s estimator does not support non-consecutive autoregressive lags.z8%s estimator does not support moving average components.r   z;Innovations estimator does not support seasonal components.zKInnovations estimator does not support non-consecutive moving average lags.zAInnovations estimator does not support autoregressive components.r   z?Hannan-Rissanen estimator does not support seasonal components.r   FzInnovations MLE estimator does not support non-stationary autoregressive components, but `enforce_stationarity` is set to FalsezeInnovations MLE estimator does not support concentrating the scale out of the log-likelihood functionz"%s" is not a valid estimator.N)
r8   r9   r.   r[   r#   r   r    rs   rv   r!   )r\   	estimatorr   r   r   has_missingtitless          rn   validate_estimatorz'SARIMAXSpecification.validate_estimatorb  s
   d "a'"a',1' )(00'
 
 $$ L  "79?	9J"K L L L
 === 1$$)B$  "C#))#4"5 6 6 6  1$$)C$  "C#))#4"5 6 6 6
 /// E  "0282C"D E E E) 6  "I#))#4"5 6 6 6  E  "0282C"D E E EE E -'' :  "9 : : :) J  "I J J J @  "? @ @ @@ @ +++ :  "9 : : :: : +++(E11  "O P P P % =  "< = = == = ,&&D=	IJJJrp   Fc           	         t          || j        |d          }| j        | j        | j        | j        | j        g}g d}| j        s*|                    d           |                    d           t          j
        |          }t          t          |t          j        ||                              }d|v r|d                                         |d<   |S )a,  
        Split parameter array by type into dictionary.

        Parameters
        ----------
        params : array_like
            Array of model parameters.
        allow_infnan : bool, optional
            Whether or not to allow `params` to contain -np.inf, np.inf, and
            np.nan. Default is False.

        Returns
        -------
        split_params : dict
            Dictionary with keys 'exog_params', 'ar_params', 'ma_params',
            'seasonal_ar_params', 'seasonal_ma_params', and (unless
            `concentrate_scale=True`) 'sigma2'. Values are the parameters
            associated with the key, based on the `params` argument.

        Examples
        --------
        >>> spec = SARIMAXSpecification(ar_order=1)
        >>> spec.split_params([0.5, 4])
        {'exog_params': array([], dtype=float64),
         'ar_params': array([0.5]),
         'ma_params': array([], dtype=float64),
         'seasonal_ar_params': array([], dtype=float64),
         'seasonal_ma_params': array([], dtype=float64),
         'sigma2': 4.0}
        zjoint parameters)allow_infnantitle)exog_params	ar_params	ma_paramsseasonal_ar_paramsseasonal_ma_paramsr   r   )r   r   r}   r   r   r   r   r!   r   r2   cumsumdictzipsplititem)r\   paramsr   ixr   outs         rn   split_paramsz!SARIMAXSpecification.split_params  s    >  -9&8: : :  $"2D4D')BD= = =% 	#IIaLLLLL"""Yr]]3ubhvr223344s??M..00CM
rp   c           	         d| j         |fd| j        |fd| j        |fd| j        |fd| j        |fdt          | j                   |fg}g }|D ]\  }	}
}|
dk    ru|t          d	|	z            t          j	        t          j
        |                    }|j        |
fk    st          d
|
|	|j        fz            |                    |           t          j        |          S )a  
        Join parameters into a single vector.

        Parameters
        ----------
        exog_params : array_like, optional
            Parameters associated with exogenous regressors. Required if
            `exog` is part of specification.
        ar_params : array_like, optional
            Parameters associated with (non-seasonal) autoregressive component.
            Required if this component is part of the specification.
        ma_params : array_like, optional
            Parameters associated with (non-seasonal) moving average component.
            Required if this component is part of the specification.
        seasonal_ar_params : array_like, optional
            Parameters associated with seasonal autoregressive component.
            Required if this component is part of the specification.
        seasonal_ma_params : array_like, optional
            Parameters associated with seasonal moving average component.
            Required if this component is part of the specification.
        sigma2 : array_like, optional
            Innovation variance parameter. Required unless
            `concentrated_scale=True`.

        Returns
        -------
        params : ndarray
            Array of parameters.

        Examples
        --------
        >>> spec = SARIMAXSpecification(ar_order=1)
        >>> spec.join_params(ar_params=0.5, sigma2=4)
        array([0.5, 4. ])
        zexogenous variableszAR termszMA termszseasonal AR termszseasonal MA termsvariancer   Nz;Specification includes %s, but no parameters were provided.zISpecification included %d %s, but parameters with shape %s were provided.)r}   r   r   r   r   r%   r!   r#   r2   
atleast_1dsqueezerX   r   concatenate)r\   r   r   r   r   r   r   definitionsparams_listr   kr   s               rn   join_paramsz SARIMAXSpecification.join_params  s7   N #D$6D)95)95 $";"$ $";"$!7788&AC  + 	+ 	+E1f1uu>$ &BDI&J K K Krz&'9'9::|t++$ &P()5&,'?&@ A A A
 ""6***~k***rp   c                    |                      |          }| j        r| j        r9t          j        d|d          f         }t          |          st          d          | j        r9t          j        d|d          f         }t          |          st          d          | j        r~| j	        r8t          j        d|d         f         }t          |          st          d          | j
        r8t          j        d|d         f         }t          |          st          d	          | j        s|d
         dk    rt          d          dS dS )a  
        Validate parameter vector by raising ValueError on invalid values.

        Parameters
        ----------
        params : array_like
            Array of model parameters.

        Notes
        -----
        Primarily checks that the parameters have the right shape and are not
        NaN or infinite. Also checks if parameters are consistent with a
        stationary process if `enforce_stationarity=True` and that they are
        consistent with an invertible process if `enforce_invertibility=True`.
        Finally, checks that the variance term is positive, unless
        `concentrate_scale=True`.

        Examples
        --------
        >>> spec = SARIMAXSpecification(ar_order=1)
        >>> spec.validate_params([-0.5, 4.])  # returns None
        >>> spec.validate_params([-0.5, -2])
        ValueError: Non-positive variance term.
        >>> spec.validate_params([-1.5, 4.])
        ValueError: Non-stationary autoregressive polynomial.
        r   r   z)Non-stationary autoregressive polynomial.r   z2Non-stationary seasonal autoregressive polynomial.r   z)Non-invertible moving average polynomial.r   z2Non-invertible seasonal moving average polynomial.r   r   zNon-positive variance term.N)r   r   r   r2   r_r   r#   r   r    r   r   r!   )r\   r   ar_polyseasonal_ar_polyma_polyseasonal_ma_polys         rn   validate_paramsz$SARIMAXSpecification.validate_paramsQ  s   8 ""6** $ 
	5 5%F;$7#7 78$W-- 5$ &4 5 5 5( 5#%5V4H-I,I)I#J $%566 5$ &4 5 5 5 % 
	5 5%6+#6 67$W-- 5$ &4 5 5 5( 5#%5F3G,H)H#I $%566 5$ &4 5 5 5 % 	@h1$$ !>???	@ 	@$$rp   c                 ,   |                      |          }i }| j        r|d         |d<   | j        r+| j        rt	          |d                   |d<   n|d         |d<   | j        r,| j        rt	          |d                    |d<   n|d         |d<   | j        r+| j        rt	          |d                   |d<   n|d         |d<   | j        r,| j        rt	          |d                    |d<   n|d         |d<   | j	        s|d         dz  |d<    | j
        di |S )	a]  
        Constrain parameter values to be valid through transformations.

        Parameters
        ----------
        unconstrained : array_like
            Array of model unconstrained parameters.

        Returns
        -------
        constrained : ndarray
            Array of model parameters transformed to produce a valid model.

        Notes
        -----
        This is usually only used when performing numerical minimization
        of the log-likelihood function. This function is necessary because
        the minimizers consider values over the entire real space, while
        SARIMAX models require parameters in subspaces (for example positive
        variances).

        Examples
        --------
        >>> spec = SARIMAXSpecification(ar_order=1)
        >>> spec.constrain_params([10, -2])
        array([-0.99504,  4.     ])
        r   r   r   r   r   r   r   r   )r   r}   r   r   	constrainr   r    r   r   r!   r   )r\   unconstrainedr   s      rn   constrain_paramsz%SARIMAXSpecification.constrain_params  s   8 ))-88 	A$1-$@F=! 	A( A&/k0J&K&K{##&3K&@{# 	A) A'0{1K'L'L&L{##&3K&@{#$ 	9( 9m,@ABB +,, ""67 +,$ 	9) 9}-ABCCC +,, ""67 +,% 	:,X69F8t))&)))rp   c                 ,   |                      |          }i }| j        r|d         |d<   | j        r+| j        rt	          |d                   |d<   n|d         |d<   | j        r,| j        rt	          |d                    |d<   n|d         |d<   | j        r+| j        rt	          |d                   |d<   n|d         |d<   | j        r,| j        rt	          |d                    |d<   n|d         |d<   | j	        s|d         dz  |d<    | j
        di |S )	a  
        Reverse transformations used to constrain parameter values to be valid.

        Parameters
        ----------
        constrained : array_like
            Array of model parameters.

        Returns
        -------
        unconstrained : ndarray
            Array of parameters with constraining transformions reversed.

        Notes
        -----
        This is usually only used when performing numerical minimization
        of the log-likelihood function. This function is the (approximate)
        inverse of `constrain_params`.

        Examples
        --------
        >>> spec = SARIMAXSpecification(ar_order=1)
        >>> spec.unconstrain_params([-0.5, 4.])
        array([0.57735, 2.     ])
        r   r   r   r   r   r   g      ?r   )r   r}   r   r   unconstrainr   r    r   r   r!   r   )r\   constrainedr   s      rn   unconstrain_paramsz'SARIMAXSpecification.unconstrain_params  s   4 ''44 	?$/$>F=! 	?( ?&1+k2J&K&K{##&1+&>{# 	?) ?&1;{3K2K&L&L{##&1+&>{#$ 	7( 7,@ ABB +,,   45 +,$ 	7) 7-A!B BCC +,,   45 +,% 	:*84c9F8t))&)))rp   c                     | j         d }n;t          | j        t          t	          j        | j                            ||          }|S )N)rI   r
   rB   r%   r2   sum)r\   rl   offsetrm   s       rn   rO   z)SARIMAXSpecification.construct_trend_data  sJ    #JJ+RVDO%<%<!=!=tVM MJ rp   c                     g }| j         D ]R}|dk    r|                    d           |dk    r|                    d           :|                    d|z             S|S )Nr   constr   driftztrend.%d)rG   r   )r\   r   r   s      rn   rR   z*SARIMAXSpecification.construct_trend_names  ss    ! 	- 	-AAvvW%%%%aW%%%%Z!^,,,,rp   c                 f   g }| j         "|                    d| j        j        z             | j        r|                    d| j        z             |                    dt          | j                  z             | j        dk    r*|                    dt          | j	                  z             | j
        |                    d| j
        z             | j        |                    d| j        z             | j        |                    d	| j        z             d
d                    |          z  S )z2Represent SARIMAXSpecification object as a string.Nzendog=%szexog=%szorder=%sr   zseasonal_order=%szenforce_stationarity=%szenforce_invertibility=%szconcentrate_scale=%szSARIMAXSpecification(%s)z, )rV   r   rU   endog_namesr}   r|   rY   r&   r.   r*   r   r    r!   join)r\   
componentss     rn   __repr__zSARIMAXSpecification.__repr__  sB   
:!j4;+BBCCC 	;i$/9:::*s4:6777 1$$1C8K4L4LLMMM$07 $ 9: ; ; ;%18 $ :; < < <!-4t7MMNNN)DIIj,A,AAArp   )NNNNNNNNNNNNNNNr   NNr   T)F)NNNNNN)r   ) __name__
__module____qualname____doc__ro   propertyrs   rv   rx   rz   r}   r   r   r   r   r   r|   r   r   r   r   r   r   r   r   r   r   r   r   rO   rR   r   r   rp   rn   r   r      s       | || 59IM7;FJBFJN8<wB wB wB wBr 5 5 X5 5 5 X5 7 7 X7 * * X* $ $ X$ ! ! X! ! ! X! * * X* * * X*   X 8 8 X8
 4 4 X4 4 4 X4 E E XE
 E E XE
   X * * X*XyK yK yKv0 0 0 0d GK@D@+ @+ @+ @+D9@ 9@ 9@v<* <* <*|:* :* :*x   	 	 	B B B B Brp   r   )r   numpyr2   pandasrP   statsmodels.tools.datar   statsmodels.tsa.base.tsa_modelr    statsmodels.tsa.statespace.toolsr   r   r   r   r   r   r	   r
   statsmodels.tsa.arima.toolsr   r   r   r   rp   rn   <module>r      s             3 3 3 3 3 3 : : : : : :: : : : : : : : : : : : : : : :
 N M M M M M M MXB XB XB XB XB XB XB XB XB XBrp   