
    Dj^                        d dl Zd dlmZ d dlZd dlZd dlZddlmZ ddl	m
Z
 ddl	mZ ddlmZmZmZ dd	lmZmZmZ dd
lmZ ddlmZmZ ddl	mZ ddlmZ ddlmZ g dZ d Z! G d de      Z" G d de      Z#	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ$e
jJ                  jM                  e
jN                  e
jP                  e
jR                  e
jT                  e
jV                        e$_,        d Z-y)    N)LinearRegression   )	BaseARIMA   )_doc)_validation)ndiffsis_constantnsdiffs)diffis_iterablecheck_endog)if_has_delegate)AbstractContextContextType)_auto_solvers)DTYPE)statsmodels)
auto_arima	AutoARIMAStepwiseContextc                  t    dD ]2  }| j                  |d       st        j                  d|z  t               4 | S )N)solvertransparamsz?%s has been deprecated and will be removed in a future version.)popwarningswarnDeprecationWarning)kwargsks     WC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\pmdarima/arima/auto.py_warn_for_deprecationsr"   #   sB    & .::aMM .012,..
 M    c                   L   e Zd Zej                  j                  ddddej                        Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZ	 e
d      	 	 	 	 	 	 	 dd       Z e
d      	 	 	 	 dd       Z e
d      	 	 dd	       Z e
d      d
        Zy)r    )yXfit_argsreturn_valid_fitssarimax_kwargsNc'                 <   || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        | | _        |!| _         |"| _!        |#| _"        |$| _#        |%| _$        |&| _%        tM        di |'}'|'| _'        y )N )(start_pdstart_qmax_pmax_dmax_qstart_PDstart_Qmax_Pmax_Dmax_Q	max_ordermseasonal
stationaryinformation_criterionalphatestseasonal_teststepwisen_jobsstart_paramstrendmethodmaxiteroffset_test_argsseasonal_test_argssuppress_warningserror_actiontracerandomrandom_staten_fitsout_of_sample_sizescoringscoring_argswith_interceptr"   r   )(selfr-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   r   s(                                           r!   __init__zAutoARIMA.__init__7   s.   V 





" $%:"
	* (
 0"4!2(
("4(,'1&1r#   c                 J   | j                   si n| j                   }t        |fi d|d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d| j                  d	| j                  d
| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                   d| j"                  d| j$                  d| j&                  d| j(                  d| j*                  d| j,                  d| j.                  d| j0                  d| j2                  d| j4                  d| j6                  d| j8                  d| j:                  d| j<                  d| j>                  d | j@                  d!| jB                  d"| jD                  d#| jF                  d$d%d&| jH                  d'| jJ                  d(| jL                  d)| jN                  d*||| _(        | S )+al  Fit the auto-arima estimator

        Fit an AutoARIMA to a vector, ``y``, of observations with an
        optional matrix of ``X`` variables.

        Parameters
        ----------
        y : array-like or iterable, shape=(n_samples,)
            The time-series to which to fit the ``ARIMA`` estimator. This may
            either be a Pandas ``Series`` object (statsmodels can internally
            use the dates in the index), or a numpy array. This should be a
            one-dimensional array of floats, and should not contain any
            ``np.nan`` or ``np.inf`` values.

        X : array-like, shape=[n_obs, n_vars], optional (default=None)
            An optional 2-d array of exogenous variables. If provided, these
            variables are used as additional features in the regression
            operation. This should not include a constant or trend. Note that
            if an ``ARIMA`` is fit on exogenous features, it must be provided
            exogenous features for making predictions.

        **fit_args : dict or kwargs
            Any keyword arguments to pass to the auto-arima function.
        r'   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r)   FrO   rP   rQ   rR   r*   ))r   r   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   model_)rS   r&   r'   r(   r*   s        r!   fitzAutoARIMA.fit   s   2 $(;;DKK ++ LL+ ff	+
 LL+ **+ **+ **+ LL+ ff+ LL+ **+ **+ **+ nn+  ff!+" ]]#+$ %+& #'"<"<'+( **)+* ++, ,,-+. ]]/+0 ;;1+2 **3+4 **5+6 ;;7+8 LL9+: "22;+<  $66=+> #44?+@ **A+B **C+D ;;E+F **G+H ;;I+J $K+L  $66M+N LLO+P **Q+R  ..S+T *W+Z r#   rV   c           	      F    | j                   j                  |||||||      S )N)r'   startenddynamicreturn_conf_intr>   typ)rV   predict_in_sample)rS   r'   rY   rZ   r[   r\   r>   r]   s           r!   r^   zAutoARIMA.predict_in_sample   s5     {{,,+ - 
 	
r#   c                 @    | j                   j                  ||||      S )N)	n_periodsr'   r\   r>   )rV   predict)rS   r`   r'   r\   r>   s        r!   ra   zAutoARIMA.predict   s,     {{""+	 # 
 	
r#   c                 B     | j                   j                  |f||d|S )N)r'   rF   )rV   update)rS   r&   r'   rF   r   s        r!   rc   zAutoARIMA.update   s5     "t{{!!

 	
 	
r#   c                 6    | j                   j                         S )z Get a summary of the ARIMA model)rV   summaryrS   s    r!   re   zAutoARIMA.summary	  s     {{""$$r#   )&r   Nr      r   rg   r   Nr   r   r   r   rg   r   TFaic皙?kpssocsbTr   NNlbfgs2   NNTrK   FFN
   r   mseNautoN)NNNFFri   levels)rn   NFri   NN)__name__
__module____qualname__r   _AUTO_ARIMA_DOCSTRformat_KWARGS_DOCSTR__doc__rT   rW   r   r^   ra   rc   re   r,   r#   r!   r   r   -   sF   %%,,

** - ,G 


#OSjHT X 
 
( X 

 
 X 	
 
 X% %r#   r   c                   *     e Zd ZdZd fd	Zd Z xZS )r   a  Context manager to capture runtime context for stepwise mode.

    ``StepwiseContext`` allows one to call :func:`auto_arima` in the context
    of a runtime configuration that offers additional level of
    control required in certain scenarios. Use cases that are either
    sensitive to duration and/or the number of attempts to
    find the best fit can use ``StepwiseContext`` to control them.

    Parameters
    ----------
    max_steps : int, optional (default=100)
        The maximum number of steps to try to find a best fit. When
        the number of tries exceed this number, the stepwise process
        will stop and the best fit model at that time will be returned.

    max_dur : int, optional (default=None)
        The maximum duration in seconds to try to find a best fit.
        When the cumulative fit duration exceeds this number, the
        stepwise process will stop and the best fit model at that
        time will be returned. Please note that this is a soft limit.

    Notes
    -----
    Although the ``max_steps`` parameter is set to a default value of None
    here, the stepwise search is limited to 100 tries to find a best fit model.
    Defaulting the parameter to None here preserves the intention of the
    caller and properly handles the nested contexts, like:

    >>> with StepwiseContext(max_steps=10):
    ...     with StepwiseContext(max_dur=30):
    ...         auto_arima(sample, stepwise=True, ...)

    In the above example, the stepwise search will be limited to either
    a maximum of 10 steps or a maximum duration of 30 seconds, whichever
    occurs first and the best fit model at that time will be returned
    c                     |"d|cxk  rdk  st        d       t        d      ||dk  rt        d      ||d}t        t        |   di | y )Nr   i  z&max_steps should be between 1 and 1000z#max_dur should be greater than zero)	max_stepsmax_durr,   )
ValueErrorsuperr   rT   )rS   r}   r~   r   	__class__s       r!   rT   zStepwiseContext.__init__7  sm     Y)>$)>EFF *?EFF7a<BCC #
 	ot-77r#   c                 "    t         j                  S rq   )r   STEPWISErf   s    r!   get_typezStepwiseContext.get_typeF  s    ###r#   rs   )rt   ru   rv   rz   rT   r   __classcell__)r   s   @r!   r   r     s    #J8$r#   r   c*                    t        dAi |*}*t        j                  |      }t        j                  |      }t        j                  |'      }'t        j                  |)      })t        j                  ||      }t        j                  |       } t        j
                  ||      }t        j                  ||d      \  }}t        j                  ||d      \  }}t        j                  ||d      \  }}t        j                  |
|d      \  }
}||f|	|ffD ](  \  }+},|,dk  rt        d      |+|+dk  st        d       |!r|#dk  rt        d      h d	}-||-vrt        d
|-d|      t        j                         }.t        | t        d      } | j                  d   }/t        j                  t        j                  |||||*|| ||&|%|'|      }0t!        |       rVt#        j$                  d       t'        t        j(                   |0| f|ddt        j*                  |(d      d|)      |$|.|       S t        j,                  ||%      }t/        t1        |t3        j4                  |/dz                    }t/        t1        |t3        j4                  |/dz                    }t1        ||      }t1        ||      }|sdx}	}| j7                         }1|.t9               j;                  ||       }2| |2j=                  |      z
  }1|rdx}}	|dk(  rdx}	x}}nV|	Tt?        |1f|||d|}	|	dkD  r?|=tA        ||	|      }3t3        jB                  t         |3d      jE                         r|	dz  }	|	dkD  rtA        |1|	|      }4n|1}4|4j                  d   dk(  rt        d|	z        ||	dkD  rtA        ||	|      }3n|}3nd }3|TtG        |4f|||d|}|dkD  r?|=tA        |3|d      }3t3        jB                  t         |3d      jE                         r|dz  }|st        jH                  ||	       |dkD  rtA        |4|d      }4t!        |4      r|sdntK        jL                  d|	d|f      }5|	dkD  r|dk(  rt        j*                  |(d      }(n8|	dkD  r|dkD  rn-|dk(  rn'|dk  rt        j*                  |(d      }(nt        d      t'        t        j(                   |0| f|d|df|5|(d|)      |$|.|       S |dkD  r(|dkD  rt1        ||dz
        }|dkD  rt1        ||dz
        }|(dk(  r||	z   d v }(|sp|t2        jN                  }n|dk  rt        d!      t        jP                  dAi d"| d#|d$|0d%|d&|	d'|d(|d)|d*|d+|d,|d-|!d.|"d/|#d0|d1|d2| d3|(d4|)}6n|/d5k  rt1        |d      }t1        |d      }dx}}
t1        ||      }7t1        ||      }8t1        ||      }9t1        |
|      }:t        jR                  | fi d#|d6|d7|d8|d9|d:|*d;|d2| d<|d=|%d>|&d?|'d|7d%|d|8d|9d&|	d|:d'|d)|d*|d+|d,|d1|d@|d3|(|)}6|6jU                         };t'        |;|$|.|       S )BNpqPQr   z.max_d & max_D must be positive integers (>= 0)z/d & D must be None or a positive integer (>= 0)z5n_fits must be a positive integer for a random search>   Nr   raiserK   ignorezerror_action must be one of z
, but got T)dtypepreserve_series)rC   rD   rE   rF   
fit_paramsrI   rK   rJ   rP   rO   rQ   r=   zEInput time-series is completely constant; returning a (0, 0, 0) ARMA.)r   r   r   )r   r   r   r   F)r'   orderseasonal_orderrR      r   )r:   r?   r7   )differenceslag)arraxisa)  The seasonal differencing order, D=%i, was too large for your time series, and after differencing, there are no samples remaining in your data. Try a smaller value for D, or if you didn't set D to begin with, try setting it explicitly. This can also occur in seasonal settings when m is too large.)r?   r>   r1   )r.   r4   r   zGdata follow a simple polynomial and are not suitable for ARIMA modelingrp   )r   r   z3max_order must be None or a positive integer (>= 0)r&   r'   fit_partialr.   r4   r:   r9   r0   r2   r6   r8   rL   rM   rN   rB   r;   rK   rR   r*   rn   rC   rD   rE   rF   r   rI   rJ   rO   rP   rQ   r=   r,   )+r"   valcheck_kwargscheck_mcheck_tracecheck_n_jobscheck_start_max_valuesr   timer   r   shape	functoolspartialsolvers_fit_candidate_modelr
   r   r   _return_wrapper_sort_and_filter_fitsauto_interceptcheck_information_criterionintminnpfloorcopyr   rW   ra   r   r   apply_along_axisanyr	   
warn_for_D	sm_compatcheck_seasonal_orderinf_RandomFitWrapper_StepwiseFitWrappersolve)<r&   r'   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r)   rO   rP   rQ   rR   r*   r(   _d_max_dactionsrY   	n_samplesr   xxlmdiffxregdxssnsearchr   r   r   r   
sorted_ress<                                                               r!   r   r   J  sk   b &11H ''(89))*<=##L1L%%n5NAx AOOE"Eh/F //DNGU//DNGU//DNGU//DNGU 5zAu:. 3
FA:MNN>Av  "2 3 33 &1* / 0 	0 9G7"#\3 4 	4 IIKE 	AUD9A
I ##$$!+!-!3K" 1~ 4 	5 ))##/#&#5#5&$/ %
 ue- 	- 	''(=(:	<  E288IM234EE288IM234E '5!G'5!G
 
A 
B}##Aq)A 	A 	AvEE	
B *!-u *(* q5Q]A1!4H"";H1EIIKQ 	1u"!+ 
xx{a P   	 	}q5A1!4HH  	y
	

 
 q5Q]H!;H "";H1EIIKQ a 1u"!+ 2"*l//Aq!= 	 q5Q!V //EN Uq1u!VU //EN  ; < < ))a)#&#1 %	 ue
 	
 	1u19q1u%E19q1u%E a%F* I] . / / ** 


 $
 	

 
 
  
 
 
 
 
 
 &
 
 
  !
" #
$ *%
& *'
. r>'1oG'1oG !!Gg  ,,

 &
 	

 
 
  
 0
 
 &
  2
 
 &
 
 
  !
" #
$ %
& '
( )
* +
, -
. /
0 1
2 3
4 #85
6 *9
> J:'8%GGr#   )r&   r'   r(   r*   r)   c                 z    t        |       s| g} |r#t        dt        j                         |z
  z         |s| d   S | S )a  If the user wants to get all of the models back, this will
    return a list of the ARIMA models, otherwise it will just return
    the model. If this is called from the end of the function, ``fits``
    will already be a list.

    We *know* that if a function call makes it here, ``fits`` is NOT None
    or it would have thrown an exception in :func:`_post_ppc_arima`.

    Parameters
    ----------
    fits : iterable or ARIMA
        The ARIMA(s)

    return_all : bool
        Whether to return all.
    zTotal fit time: %.3f secondsr   )r   printr   )fits
return_allrY   rK   s       r!   r   r     sD    $ tv ,		e0CDE AwKr#   ))Nr   Nr   rg   r   rg   r   Nr   r   r   r   rg   r   TFrh   ri   rj   rk   Tr   NNrl   rm   NNTrK   FFNrn   Fr   ro   Nrp   N).numpyr   sklearn.linear_modelr   r   r   r   baser   r%   r   r   r   utilsr	   r
   r   r   r   r   utils.metaestimatorsr   _contextr   r   r   r   compat.numpyr   compatr   r   __all__r"   r   r   r   rw   rx   	_Y_DOCSTR_EXOG_DOCSTR_FIT_ARGS_DOCSTR_SARIMAX_ARGS_DOCSTR_VALID_FITS_DOCSTRrz   r   r,   r#   r!   <module>r      s:    1        / / 2 2 2 2 '   -_%	 _%H6$o 6$v 








	

UtHp ,,33
nn
"",,-- 4 
 r#   