
    Dj|                     n    d Z ddlZddlZddlmZ ddlmZ h dZd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zy)z
Arg validation for auto-arima calls. This allows us to test validation more
directly without having to fit numerous combinations of models.
    N)metrics)ModelFitWarning>   aicbicoobaicchqicc                     | dk(  r|S | S )zCA more concise way to handle the default behavior of with_interceptauto )with_interceptdefaults     ^C:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\pmdarima/arima/_validation.pyauto_interceptr      s        c                     | t         vrt        d| dt               | dk(  r|dk(  rd} t        j                  d       | S )z0Check whether the information criterion is validz0auto_arima not defined for information_criteria=z&. Valid information criteria include: r   r   r   zoinformation_criterion cannot be 'oob' with out_of_sample_size = 0. Falling back to information criterion = aic.)VALID_CRITERIA
ValueErrorwarningswarn)information_criterionout_of_sample_sizes     r   check_information_criterionr      sW    N21>C D 	D
 %*<*A % E 	F ! r   c                     | r| S i S )zReturn kwargs or an empty dict.

    We often pass named kwargs (like `sarimax_kwargs`) as None by default. This
    is to avoid a mutable default, which can bite you in unexpected ways. This
    will return a kwarg-compatible value.
    r   )kwargss    r   check_kwargsr   *   s     Ir   c                 v    | dk  r|s| dk  rt        d      |s| dkD  rt        j                  d| z         d} | S )z+Check the value of M (seasonal periodicity)   r   z"m must be a positive integer (> 0)z-m (%i) set for non-seasonal fit. Setting to 0)r   r   r   )mseasonals     r   check_mr!   6   sC    	A(q1u=>>q5MMIAMNHr   c                 H    | r|dk7  rd}t        j                  d|z         |S )zPotentially update the n_jobs parameter

    We can't run in parallel with the stepwise algorithm. This checks
    ``n_jobs`` w.r.t. stepwise and will warn.
    r   z`stepwise model cannot be fit in parallel (n_jobs=%i). Falling back to stepwise parameter search.)r   r   )stepwisen_jobss     r   check_n_jobsr%   D   s3     FaK CEKL 	MMr   c                     |t         j                  }| t        d|z        | dk  rt        d|z        || k  rt        d|d|      | |fS )z2Ensure starting points and ending points are validzstart_%s cannot be Noner   zstart_%s must be positivemax_z must be >= start_)npinfr   )stmxargnames      r   check_start_max_valuesr-   Q   s^    	zVV	z2W<==	Av4w>??	Bw'JKKr6Mr   c                 R    | yt        | t        t        f      rt        |       S | ryy)zCheck the value of tracer   r   )
isinstanceintbool)traces    r   check_tracer3   ^   s+    }%#t%5zr   c                    t        | t              r;| dk(  rt        j                  S | dk(  rt        j                  S 	 t        t        |       S t        |       st        dt        |       z        | S # t        $ r t        d| z        w xY w)a;  Get a scoring metric by name, or passthrough a callable

    Parameters
    ----------
    metric : str or callable
        A name of a scoring metric, or a custom callable function. If it is a
        callable, it must adhere to the signature::

            def func(y_true, y_pred)

        Note that the ARIMA model selection seeks to MINIMIZE the score, and it
        is up to the user to ensure that scoring methods that return maximizing
        criteria (i.e., ``r2_score``) are wrapped in a function that will
        return the negative value of the score.
    msemaez#'%s' is not a valid scoring method.zG`metric` must be a valid scoring method, or a callable, but got type=%s)r/   strr   mean_squared_errormean_absolute_errorgetattrAttributeErrorr   callable	TypeErrortype)metrics    r   get_scoring_metricr@   j   s      &# U?---U?...	M7F++ F 46:6lC D 	D M  	MBVKLL	Ms   A0 0Bc                     |dk\  rt        j                  dt               y|| z   dkD  s| dkD  rt        j                  dt               yy)zWarn for large values of D   zqHaving more than one seasonal differences is not recommended. Please consider using only one seasonal difference.zvHaving 3 or more differencing operations is not recommended. Please consider reducing the total number of differences.N)r   r   r   )dDs     r   
warn_for_DrE      sJ    Av -.=	?
 
Qa!e /0?	A r   )__doc__numpyr(   r   sklearnr   pmdarima.warningsr   r   r   r   r   r!   r%   r-   r3   r@   rE   r   r   r   <module>rJ      sN   
    - 7!"	

	"JAr   