U
    Ãmœdi  ã                   @   s$   d Z ddlZddd„Zd	dd„ZdS )
z4
SARIMAX tools.

Author: Chad Fulton
License: BSD-3
é    Nc                 C   s´  t  | ¡} |dkrdnd| }t  | |  t¡k¡sBtd|| f ƒ‚|  t¡} t  | dk ¡rftd| ƒ‚| jdkr�| jd dkr�| dd…df } n| jdkrªtd	|| f ƒ‚| jdkr¾|  	¡ } nÀt
| ƒdkrÐd} n®d| k}t  | dk¡dk}t  | dk¡}|�s|�r.|�rtd
| ƒ‚t  | dk¡d d } n
t  | ¡} t
| ƒdk�rLd} n2t  | t  dt
| ƒd ¡k¡�rv| d } n|  ¡ } t| tƒ�oœt  t  | ¡dk¡}|�r°td| ƒ‚| S )a+  
    Standardize lag order input.

    Parameters
    ----------
    order : int or array_like
        Maximum lag order (if integer) or iterable of specific lag orders.
    title : str, optional
        Description of the order (e.g. "autoregressive") to use in error
        messages.

    Returns
    -------
    order : int or list of int
        Maximum lag order if consecutive lag orders were specified, otherwise
        a list of integer lag orders.

    Notes
    -----
    It is ambiguous if order=[1] is meant to be a boolean list or
    a list of lag orders to include, but this is irrelevant because either
    interpretation gives the same result.

    Order=[0] would be ambiguous, except that 0 is not a valid lag
    order to include, so there is no harm in interpreting as a boolean
    list, in which case it is the same as order=0, which seems like
    reasonable behavior.

    Examples
    --------
    >>> standardize_lag_order(3)
    3
    >>> standardize_lag_order(np.arange(1, 4))
    3
    >>> standardize_lag_order([1, 3])
    [1, 3]
    NÚorderz%s orderz)Invalid %s. Non-integer order (%s) given.r   z#Terms in the %s cannot be negative.é   é   zeInvalid %s. Must be an integer or 1-dimensional array-like object (e.g. list, ndarray, etc.). Got %s.z¦Invalid %s. Appears to be a boolean list (since it contains a 0 element and/or multiple elements) but also contains elements greater than 1 like a list of lag orders.éÿÿÿÿz+Invalid %s. Cannot have duplicate elements.)ÚnpÚarrayÚallZastypeÚintÚ
ValueErrorÚanyÚndimÚshapeÚitemÚlenÚsumÚwhereÚsortZarangeÚtolistÚ
isinstanceÚlistÚdiff)r   ÚtitleZ	has_zerosZhas_multiple_onesZ
has_gt_oneZhas_duplicate© r   úT/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/tsa/arima/tools.pyÚstandardize_lag_order
   sL    &
ÿ

þ

ü
 
 r   Fc                 C   sî   |dkrdnd| }zBt j| td�} dd„ |  ¡ D ƒ}t|ƒrBtnt}t j| |d�} W n  tk
rv   td| ƒ‚Y nX |s¨t  t  	| ¡¡sœt  t  
| ¡¡r¨td| ƒ‚t  t  | ¡¡} | j|fkrê|d	krÐdnd
}td|||| jf ƒ‚| S )aÙ  
    Validate parameter vector for basic correctness.

    Parameters
    ----------
    params : array_like
        Array of parameters to validate.
    length : int
        Expected length of the parameter vector.
    allow_infnan : bool, optional
            Whether or not to allow `params` to contain -np.Inf, np.Inf, and
            np.nan. Default is False.
    title : str, optional
        Description of the parameters (e.g. "autoregressive") to use in error
        messages.

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

    Notes
    -----
    Basic check that the parameters are numeric and that they are the right
    shape. Optionally checks for NaN / infinite values.
    NÚ z for %s)Údtypec                 S   s   g | ]}t |tƒ‘qS r   )r   Úcomplex)Ú.0Úpr   r   r   Ú
<listcomp>�   s     z"validate_basic.<locals>.<listcomp>z,Parameters vector%s includes invalid values.z/Parameters vector%s includes NaN or Inf values.r   ÚszOSpecification%s implies %d parameter%s, but values with shape %s were provided.)r   r   ÚobjectZravelr   r   ÚfloatÚ	TypeErrorr
   ÚisnanÚisinfZ
atleast_1dZsqueezer   )ÚparamsÚlengthZallow_infnanr   Z
is_complexr   Úpluralr   r   r   Úvalidate_basico   s.    ÿÿÿþr*   )N)FN)Ú__doc__Únumpyr   r   r*   r   r   r   r   Ú<module>   s   
e