
    M/Ph
             
       Z   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	Z	ddl
ZddlZddlmZmZm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 ddlm Z m!Z! ddl"m#Z$m%Z& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0 e$j1        e$j2        e$j3        e$j4        e$j5        e$j6        e$j7        e$j8        e$j9        d	Z:e&j1        e&j2        e&j3        e&j4        e&j5        e&j6        e&j7        e&j8        e&j9        d	Z;d Z< G d d          Z= G d de          Z> G d de>          Z? G d de>          Z@dS )a$  
Notes
-----
Code written using below textbook as a reference.
Results are checked against the expected outcomes in the text book.

Properties:
Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles and
practice. OTexts, 2014.

Author: Terence L van Zyl
Modified: Kevin Sheppard
    )deprecate_kwargN)Any)HashableSequence)basinhoppingleast_squaresminimize)
inv_boxcox)boxcox)
array_like	bool_like	dict_like
float_likeint_likestring_like)TimeSeriesModel)_initialization_heuristic_initialization_simple)_exponential_smoothers
_smoothers)HoltWintersArgs)to_restrictedto_unrestricted)HoltWintersResultsHoltWintersResultsWrapper)freq_to_period)	muladd)r   r   )r   N)r   r   )r   r   )r   N)Nr   )Nr   NNc                       fd}|S )Nc                  `     | i |}t          |t          j                  r
|j        |z  S |S N)
isinstancenpndarrayT)argskwargserrfuncs      a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/holtwinters/model.pyfzopt_wrapper.<locals>.fQ   s<    dD#F##c2:&& 	53;
     )r+   r-   s   ` r,   opt_wrapperr0   P   s#         Hr.   c                       e Zd ZU eed<   eed<   eed<   eed<   eed<   eed<   ej        ed<   ej        ed<   ej        ed	<   ej        ed
<   eed<   ddZdS )
_OptConfigalphabetaphigammaleveltrendseasonalyparamsmaskmle_retvalsreturnc                     |d         | _         |d         | _        |d         | _        |d         | _        |d         | _        |d         | _        |dd          | _        | S )Nr                     )r3   r4   r6   r7   r8   r5   r9   )selfr;   s     r,   unpack_parametersz_OptConfig.unpack_parametersg   sX    AY
1I	AY
AY
AY
!9qrr
r.   N)r>   r2   )	__name__
__module____qualname__float__annotations__r%   r&   r   rG   r/   r.   r,   r2   r2   Z   s         LLL
KKK	JJJLLLLLLLLLj	zMMMJ
*	 	 	 	 	 	r.   r2   c                   8    e Zd ZdZ edd          	 	 	 d,ddddddddddd
 fd	            Zd
 Zd Zej	        d             Z
d Zd Zd Zd Zd Zd-dZd Ze	 d.dedee         fd            Zd Zed             Zd Zd Zd Zd Zdedefd Z ed!d"           ed#d$           ed%d&          	 	 	 	 d/d'ddddd'ddddd(
d)                                    Z	 d0d*Z  ed!d"           ed%d&          	 	 	 	 	 	 	 	 	 	 	 	 d1d+                        Z! xZ"S )2ExponentialSmoothinga  
    Holt Winter's Exponential Smoothing

    Parameters
    ----------
    endog : array_like
        The time series to model.
    trend : {"add", "mul", "additive", "multiplicative", None}, optional
        Type of trend component.
    damped_trend : bool, optional
        Should the trend component be damped.
    seasonal : {"add", "mul", "additive", "multiplicative", None}, optional
        Type of seasonal component.
    seasonal_periods : int, optional
        The number of periods in a complete seasonal cycle, e.g., 4 for
        quarterly data or 7 for daily data with a weekly cycle.
    initialization_method : str, optional
        Method for initialize the recursions. One of:

        * None
        * 'estimated'
        * 'heuristic'
        * 'legacy-heuristic'
        * 'known'

        None defaults to the pre-0.12 behavior where initial values
        are passed as part of ``fit``. If any of the other values are
        passed, then the initial values must also be set when constructing
        the model. If 'known' initialization is used, then `initial_level`
        must be passed, as well as `initial_trend` and `initial_seasonal` if
        applicable. Default is 'estimated'. "legacy-heuristic" uses the same
        values that were used in statsmodels 0.11 and earlier.
    initial_level : float, optional
        The initial level component. Required if estimation method is "known".
        If set using either "estimated" or "heuristic" this value is used.
        This allows one or more of the initial values to be set while
        deferring to the heuristic for others or estimating the unset
        parameters.
    initial_trend : float, optional
        The initial trend component. Required if estimation method is "known".
        If set using either "estimated" or "heuristic" this value is used.
        This allows one or more of the initial values to be set while
        deferring to the heuristic for others or estimating the unset
        parameters.
    initial_seasonal : array_like, optional
        The initial seasonal component. An array of length `seasonal`
        or length `seasonal - 1` (in which case the last initial value
        is computed to make the average effect zero). Only used if
        initialization is 'known'. Required if estimation method is "known".
        If set using either "estimated" or "heuristic" this value is used.
        This allows one or more of the initial values to be set while
        deferring to the heuristic for others or estimating the unset
        parameters.
    use_boxcox : {True, False, 'log', float}, optional
        Should the Box-Cox transform be applied to the data first? If 'log'
        then apply the log. If float then use the value as lambda.
    bounds : dict[str, tuple[float, float]], optional
        An dictionary containing bounds for the parameters in the model,
        excluding the initial values if estimated. The keys of the dictionary
        are the variable names, e.g., smoothing_level or initial_slope.
        The initial seasonal variables are labeled initial_seasonal.<j>
        for j=0,...,m-1 where m is the number of period in a full season.
        Use None to indicate a non-binding constraint, e.g., (0, None)
        constrains a parameter to be non-negative.
    dates : array_like of datetime, optional
        An array-like object of datetime objects. If a Pandas object is given
        for endog, it is assumed to have a DateIndex.
    freq : str, optional
        The frequency of the time-series. A Pandas offset or 'B', 'D', 'W',
        'M', 'A', or 'Q'. This is optional if dates are given.
    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'.

    Notes
    -----
    This is a full implementation of the holt winters exponential smoothing as
    per [1]_. This includes all the unstable methods as well as the stable
    methods. The implementation of the library covers the functionality of the
    R library as much as possible whilst still being Pythonic.

    See the notebook `Exponential Smoothing
    <../examples/notebooks/generated/exponential_smoothing.html>`__
    for an overview.

    References
    ----------
    .. [1] Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles
        and practice. OTexts, 2014.
    dampeddamped_trendNF	estimatednone)
seasonal_periodsinitialization_methodinitial_levelinitial_trendinitial_seasonal
use_boxcoxboundsdatesfreqmissingc       
         n   t                                          |d |||           t          |dddd          x| _        | _        d}t          |d|d	          }|d
v rddd
|         }|| _        t          |d          | _        t          |d|d	          }|d
v rddd
|         }|| _	        |dv | _
        |dv | _        | j        dk    s| j	        dk    r,t          j        | j        dk              st          d          | j        r| j
        st          d          | j        rut          |dd          | _        |8	 t#          | j                  | _        n# t&          $ r t          d          w xY w| j        dk    rt          d          | j        J nd| _        t)          | j                  | _        d}t          |dd|          | _        t1          |dd          | _        t1          |dd          | _        t          |	dd          | _        | j        dk    }|| _        |o| j        d u| _        |o| j	        d u| _        |                     |          | _         |
| _!        t          j"        | _#        | $                                | _        | %                                 i | _&        d S ) N)r\   endogr@   TC)ndim
contiguousorder)r   r   additivemultiplicativer8   )optionsoptional)rc   rd   r   r   rP   r9   r           zVendog must be strictly positive when usingmultiplicative trend or seasonal components.z#Can only dampen the trend componentrS   rf   znseasonal_periods has not been provided and index does not have a known freq. You must provide seasonal_periodsz'seasonal_periods must be larger than 1.r   )knownrQ   	heuristiclegacy-heuristicrT   F)rf   re   rU   rV   rW   rQ   )'super__init__r   _y_datar   r8   r   rP   r9   	has_trendhas_seasonalr%   all
ValueErrorr   rS   r   _index_freq	Exceptionlenr^   nobs_initialization_methodr   _initial_level_initial_trend_initial_seasonal_estimate_level_estimate_trend_estimate_seasonal_check_bounds_bounds_use_boxcoxnan_lambda_boxcox_initialize_fixed_parameters)rF   r^   r8   rP   r9   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   re   rQ   	__class__s                    r,   rm   zExponentialSmoothing.__init__   s]   & 	eT7CCC)7t3 
  
  
 	
$* ?E7GdKKK222!&%@@GE
%lNCCj'D
 
 
 555$)UCCHMH .0$6J%4=E#9#926JD
 D
#9 ?    	DT^ 	DBCCC 	&$, "4t% % %D!  ',:4;K,L,LD))    $+   $)) !JKKK(4444$%D!
OO	I&1!#	'
 '
 '
# )?T
 
 
 )?T
 
 
 ",04"
 "
 "
 /;>	((CTZt-C"+"IT0I))&11%v,,..!#s   E E7c                 r   t          |dd          }|d S d}|                                 }|D ]}||vr@d                    |d d                   }|d|d         z   z  }t          | d| d	          ||         }t	          |t
                    st          |          |d
         |d
         nt          j         }|d         |d         nt          j        }t          |          dk    s||k    rt          |          d|v sd|v r*|d
         dk     s|d         dk    rt          | d          |S )NrY   Trh   zcbounds must be a dictionary of 2-element tuples of the form (lb, ub) where lb < ub, lb>=0 and ub<=1, , and z7 does not match the list of supported variables names: .r   r@   rA   	smoothingdamprg         ?z* must have a lower bound >= 0.0 and <= 1.0)r   _ordered_namesjoinKeyErrorr$   tuple	TypeErrorr%   infrv   rs   )	rF   rY   msg	variableskey	supportedboundlbubs	            r,   r   z"ExponentialSmoothing._check_bounds,  s   68d;;;>F7 	 ''))	 	 	C)## IIin55	X	"55	 + +'+ + +   3KEeU++ %nn$"1X1qwB"1X1qrvB5zzQ"(( oo%s""fmma3%(S.. FFF   r.   c                 j   | j         	| j         du rt          j        | _        | j        S | j         du rt          | j                  \  }| _        ndt          | j         t          t          f          r4t          | j                   | _        t          | j        | j                   }nt          d          |S )NFTz*use_boxcox must be True, False or a float.)
r   r%   r   r   rn   r   r$   intrK   r   )rF   r:   s     r,   r   zExponentialSmoothing._boxcoxL  s    #t'75'@'@6DL7Nt##$TWooOAt||(3,77 	J !122DLtw 011AAHIIIr.   c              #     K   t          |d          }d}| j        r|dz  }| j        r5|dz  }| j        }|t	          d t          |          D                       z  }| j        r|dz  }| j        dv rd |D             }|t	          |          z  }|D ]D}||vr>d	                    |d
d                   dz   |d         z   }t          | d| d          Ed|v rv|d         }|dk    rt          d          |                    dd          }||k    rt          d          |                    dd          }	|	d|z
  k    rt          d          	 || _        d
V  i | _        d
S # i | _        w xY w)a  
        Temporarily fix parameters for estimation.

        Parameters
        ----------
        values : dict
            Values to fix. The key is the parameter name and the value is the
            fixed value.

        Yields
        ------
        None
            No value returned.

        Examples
        --------
        >>> from statsmodels.datasets.macrodata import load_pandas
        >>> data = load_pandas()
        >>> import statsmodels.tsa.api as tsa
        >>> mod = tsa.ExponentialSmoothing(data.data.realcons, trend="add",
        ...                                initialization_method="estimated")
        >>> with mod.fix_params({"smoothing_level": 0.2}):
        ...     mod.fit()
        values)smoothing_level)smoothing_trend)smoothing_seasonalc                     g | ]}d | S initial_seasonal.r/   .0is     r,   
<listcomp>z3ExponentialSmoothing.fix_params.<locals>.<listcomp>z  s!     K K KQ!8Q!8!8 K K Kr.   )damping_trend)rQ   Nc                 B    g | ]}d |v |                     d d          S )
smoothing_initial_)replace)r   r   s     r,   r   z3ExponentialSmoothing.fix_params.<locals>.<listcomp>~  s;       3&& L*55&&&r.   r   Nr   r   z if not allowed. Only z% are supported in this specification.r   rg   z!smoothing_level must be in (0, 1)r   z*smoothing_trend must be <= smoothing_levelr   r@   z1smoothing_seasonal must be <= 1 - smoothing_level)r   rp   rq   rS   r   rangerP   rx   r   r   rs   getr   )
rF   r   
valid_keysm
extra_keysr   validr3   r4   r6   s
             r,   
fix_paramszExponentialSmoothing.fix_paramsY  s     4 68,,)
> 	/..J 	M11J%A% K K%(( K K KLLLJ 	-,,J&*=== %  J
 %
+++J 	 	C*$$		*SbS/22X=
2N * *% * * *   % &&,-E|| !DEEE::/55De|| !MNNNJJ3S99Eq5y   G  	(%+D"EEE%'D"""RD"''''s   E& &	E/c                 d   | j         dk    r|                                 S d| j          d}| j        "t          |                    d                    | j        "t          |                    d                    | j        "t          |                    d                    | j         dk    r|                                 S | j         dk    r|                                 S | j         d	k    rA| j	        d
d| j
        dz  z  z   k     r|                                 S |                                 S d S )Nri   zinitialization method is z but initial_{0} has been set.r7   r8   r9   rk   rj   rQ   
   rA   )rx   _initialize_knownry   rs   formatrz   r{   _initialize_legacy_initialize_heuristicrw   rS   _initialize_simple)rF   r   s     r,   r   z ExponentialSmoothing._initialize  sE   &'11))+++((C ( ( ( 	 *SZZ00111*SZZ00111!-SZZ
33444&*<<<**,,,(K77--///(K77y2T%:a%? @@@@..00011333	 87r.   c                     | j         r| j        nd}| j        r| j        nd}t	          | j        ||| j                  \  }}}|| _        || _        || _	        d S NF)
rp   r8   rq   r9   r   rn   rS   ry   rz   r{   rF   r8   r9   lvlseass        r,   r   z'ExponentialSmoothing._initialize_simple  sk    "n7

%$($5@4==51GUHd&;
 
UD "#!%r.   c                     | j         r| j        nd}| j        r| j        nd}t	          | j        ||| j                  \  }}}|| _        || _        || _	        d S r   )
rp   r8   rq   r9   r   rn   rS   ry   rz   r{   r   s        r,   r   z*ExponentialSmoothing._initialize_heuristic  sk    "n7

%$($5@4==54GUHd&;
 
UD "#!%r.   c                 d    |                      d          \  }}}|| _        || _        || _        d S )NT)force)initial_valuesry   rz   r{   )rF   r   r8   r9   s       r,   r   z'ExponentialSmoothing._initialize_legacy  s=    #222>>UH!#!)r.   c                    d}| j         "t          |                    d                    d}| j        r)| j        "t          |                    d                    | j        s)| j        "t          |                    d                    | j        r)| j        "t          |                    d                    | j        s)| j        $t          |                    d                    d S d S )Nz3initialization is 'known' but initial_{0} not givenr7   z.initial_{0} set but model has no {0} componentr8   r9   )ry   rs   r   rp   rz   rq   r{   )rF   r   excesss      r,   r   z&ExponentialSmoothing._initialize_known  s    C&SZZ00111A> 	5d19SZZ00111 	5D$7$CV]]733444 	8!7!?SZZ
33444" 	8t'='IV]]:66777	8 	8'I'Ir.   c                 N   |Nt          | j        dd          }t          |t                    r| j        j        d         }n| j        d         |z   }|                     ||          \  }}}}|dk    r | j        dd|i|}n | j        dddi|}|j        |||z   dz            S )	a  
        In-sample and out-of-sample prediction.

        Parameters
        ----------
        params : ndarray
            The fitted model parameters.
        start : int, str, or datetime
            Zero-indexed observation number at which to start forecasting, ie.,
            the first forecast is start. Can also be a date string to
            parse or a datetime type.
        end : int, str, or datetime
            Zero-indexed observation number at which to end forecasting, ie.,
            the first forecast is start. Can also be a date string to
            parse or a datetime type.

        Returns
        -------
        ndarray
            The predicted values.
        Nr[   r@   r   r   )startendhr/   )getattr_indexr$   r   shape_get_prediction_index_predictfittedfcast)rF   r;   r   r   r[   out_of_sample_ress           r,   predictzExponentialSmoothing.predict  s    , =4;22D$$$ /)!,B$.'+'A'AS (B (
 (
$sM1 1$-::-:6::CC$-..!.v..Cus]':Q'>>??r.   c                 f   ||         }||k    }||                                          }d|t          j        |           <   d}||         ||||         z
  z  z   ||<   ||k    }||                                          }	d|	t          j        |	           <   d}||         |||         |	z
  z  z
  ||<   |S )Ng      Y@g-C6?g      Y)copyr%   isfinite)
rF   pselr   r   	initial_plocupperepslowers
             r,   _enforce_boundsz$ExponentialSmoothing._enforce_bounds  s    cF	 2o3%*r{5!!!"C3%"S'/#::	#2o3%+r{5!!!"C3"S'E/#::	#r.   r)   dkeysc                 B    |D ]}|| v rt          | d| d          d S )Nz must not contain ''rs   )r   r   namer   s       r,   _check_blocked_keywordsz,ExponentialSmoothing._check_blocked_keywords  sN      	E 	ECaxx D!C!CS!C!C!CDDD 	E 	Er.   c                     |d         d         |d         d         k    rt          d          |d         d         d|d         d         z
  k    rt          d          d S )Nr@   r   zmThe bounds for smoothing_trend and smoothing_level are incompatible since smoothing_trend <= smoothing_level.rA   zwThe bounds for smoothing_seasonal and smoothing_level are incompatible since smoothing_seasonal <= 1 - smoothing_level.r   )rF   rY   s     r,   _check_bound_feasibilityz-ExponentialSmoothing._check_bound_feasibility  sv    !9Q<&)A,&&I   !9Q<1vay|+,,'   -,r.   c           
      	   d| d d                                          z  }| d         s*t          | d                   t          | d                   z   }g }t          dd          D ]}| |         r||         }|d         |d         z
  }|d         d|z  z   }	|dk    rt          |d         |          d|z  z
  }
nt          |d         d|z
            d|z  z
  }
|                    t          j        |	|
|                     t          j        t          j        |           }|	                    |df          j
        }t          j        |          S |d         }d|d         |d         z
  z  }t          j        |d         |z   |d         |z
  |          }| d         s| d         s|d d d f         S g }|d         }|d         }| d         r| d         rz|D ]t}|d         }t          |d         |          }|d         }t          |d         d|z
            }||k    s||k    rOt          t          j        |t          j        |          z                      }t          t          j        |t          j        d|z
            z                      }t          j        |||          }t          j        |||          }t          j        t          j        ||                    	                    dd          j
        }t          j        |j        d         df          }||d d df<   ||d d dd f<   |                    |           vnq| d         r|D ]}|d         }t          |d         |          }||k    r't          t          j        |t          j        |          z                      }t          j        |df          }||d d df<   t          j        |||          |d d df<   |                    |           n|D ]}|d         }t          |d         d|z
            }||k    r*t          t          j        |t          j        d|z
            z                      }t          j        |df          }t          j        |||          |d d df<   ||d d df<   |                    |           t          j        |          S )NW   rB   r   r@   rA   g{Gzt?r   )sumr   r   minappendr%   linspacestackmeshgridreshaper'   ascontiguousarrayceilsqrtemptyr   vstack)r   rY   r3   nsnparamsr(   r   r   stepr   r   pointscombinedb_boundsg_boundsab_lbb_ubg_lbg_ubnbngbgbothfinals                             r,   _setup_brutez!ExponentialSmoothing._setup_brute+  s    3rr7;;== 1v 	0#a&kkCAKK/GD1a[[ 	9 	9q6 9"1IE 8eAh.DqEDL0BAvv q511EDL@ q1u955DKKBB 7 7888Xbk4011F^^WbM224F'///q	a58+,U1X_eAhorBB1v 	#c!f 	#!!!T'?"!9!9q6 )	'c!f )	' ' '{8A;**{8A;A..$;;$++bgajj1122bga!enn!45566KdB//KdB//xAq 1 122::1bAAC$*Q-!344aaad#aaae&&&&!'" V 	' 
' 
'{8A;**$;;bgajj1122"a))aaad k$b99aaad&&&&
'  
' 
'{8A;A..$;;bga!enn!45566"a)) k$b99aaadaaad&&&&y"""r.   c                 j    d}| j         }|t          d t          |          D                       z  }|S )Nr   r   r   rU   rV   r   c                     g | ]}d | S r   r/   r   s     r,   r   z7ExponentialSmoothing._ordered_names.<locals>.<listcomp>  s!    BBBA/A//BBBr.   )rS   r   r   )rF   namesr   s      r,   r   z#ExponentialSmoothing._ordered_namesx  s?    
 !BBqBBBCCCr.   c	                    | j         rs| j         |                                 }	t          j        fd|	D                       }
||
                                           rZg }t          |	||
          D ]\  }}}|s|s|                    |            d                    |          }t          d|           ||
z  }	                    d|          }	                    d|          }	                    d|          }	                    d|          }	                    d|          }	                    d	|          }t          | j                  D ]$}	                    d
| ||                   ||<   %||||||||fS )Nc                     g | ]}|vS r/   r/   )r   r   fixeds     r,   r   z:ExponentialSmoothing._update_for_fixed.<locals>.<listcomp>  s    !F!F!F$e"3!F!F!Fr.   r   z4Cannot fix a parameter that is not being estimated: r   r   r   r   rU   rV   r   )r   r   r%   arrayanyzipr   r   rs   r   r   rS   )rF   r   r3   r4   r6   r5   l0b0s0r  	not_fixedinvalidr   snfinvalid_namesr   r  s                    @r,   _update_for_fixedz&ExponentialSmoothing._update_for_fixed  s   ! 	B*E''))E!F!F!F!F!F!F!FGGIiZ %%'' 	#&uc9#=#= - -KD!R -R -t,,, $		' 2 2 2"/2 2  
 9CII/77E99.55DII2E::E))OS11C?B//B?B//B4011 B B		"9a"9"92a5AA1E4RR77r.   c                 t   | j         dk    rdnd }| j        dk    rdnd }||d nd}ddd|d f|d fdg}||d fg| j        z  z  }| j        gt	          | j        t
                    sJ t          |                                           D ])\  }}| j                            |||                   ||<   *| j	        }d|v rX|d         }|d         d         |k    r|d         d         |f|d<   |d         d         d|z
  k    r|d         d         d|z
  f|d<   d	|v r5|d	         }	t          |	|d         d                   |d         d         f|d<   d
|v r8|d
         }
|d         d         t          d|
z
  |d         d                   f|d<   t          |                                           D ]x\  }}||         d         ||         d         nt          j         }||         d         ||         d         nt          j        }||k    rt          d| d||          d          y|                     |           |S )Nr   rg   )rg   r   )g?gףp=
?r   r@   r   rA   r   r   zWAfter adjusting for user-provided bounds fixed values, the resulting set of bounds for r   z, are infeasible.)r8   r9   rS   r   r$   dict	enumerater   r   r   maxr   r%   r   rs   r   )rF   trend_lb	season_lblvl_lbrY   r   r   r  r3   r4   r6   r   r   s                r,   _construct_boundsz&ExponentialSmoothing._construct_bounds  s   *--334=E11CCt	!)i.?STNt
 	It$%(===<#dlD11111$T%8%8%:%:;; > >4 L,,T6!9==q		&%%+,Eay|e###AYq\51q	ay|q5y))#AYq\1u95q	%%*+DT6!9Q<00&)A,?F1I5((./E1s1u9fQil'C'CDF1I !4!4!6!677 	 	GAt!'1!91wB!'1!91rvBRxx &7;& &?Eay& & &    	%%f---r.   c	                    ||rt          j        |d d                   r| j        }	t          j        dgd|	z   z            }
d|
d d<   |
|z  }
|
                    t           j                  |_        d|_        |                     |
||          }t          |          }t           j
        }|d         }|D ]} |||          }||k     r|}|}|||
<   no|mt          |          |                                k    rCd}t          |          t          |          }}t          |                    ||                    |||<   |S )NrB   FrE   Tr   z.start_params must have {0} values but has {1}.)r%   r  rS   r  astypeint64xi	transformr  r0   r   rv   r   rs   r   )rF   r;   start_params	use_bruter   hw_argsrY   r3   r+   r   sv_selr   optbest_valbest_paramspointvalr   nxinsps                       r,   _get_starting_valuesz)ExponentialSmoothing._get_starting_values  sU    I"&RaR// %AXugQ/00FF2A2JcMFrx00GJ %G&&vvu==Fd##CvH )K # #c%))>>"'K"H(F6NN%<  CGGII--Fs88S%6%6S C!5!5666&F3Kr.   datar>   c           
      	   |j         }|j        }|j        }|j        }|j        }	|j        }
| j        }| j        }| j        }| j	        }| j
        }| j        }t          j        d|z             }|                     |j        |j                  \  }}}||ndt!          |d          z  }|}||rd|z  }|}|r
|dd|z
  z  }||nd}t          j        |d u |o|d u |o|d u | j        | j        |o|d u g|o| j        g|z  z             }|                     ||||||||          \  }}}}}}}}t,          ||f         }||||||g|d d<   |r||| d <   t          j        |          sDdd	lm} d
}t5          j        ||d           |                    |          }||_        ||_        |S |                                 }t          j        |d d         t>                    }tA          |!                    t          j"                  |||	|| j#                  }| $                    ||
||||||          }dgdz  |dd          z   } d tK          | |          D             }!t          j        |!t>                    }|j&        \  }"}#t          j'         |"t          j(        |"          <   t          j'        |#t          j(        |#          <   |!                    t          j"                  |_)        | *                    |||"|#          }$|$||<   tW          |||j,                  |d d<   ||         }$d|_-        |dv r4|"|#f}%| .                    |d           t_          ||$f|%|fd|}&|&j0        }'n|dv r|f|!d}(|1                                }d|v r<| .                    |d         dd           |(2                    |d                    |d= |(dd})|)2                    |           tg          |          }*ti          |*|$fi |)}&|&j5        j0        }'n?tg          |          }*| .                    |d           tm          |*|$f|f|!|d|}&|&j0        }'|&j7        ||<   tq          |||j,                  |d d<   ||         |&_7        |'sddlm9}+ t5          j        d|+           |&j7        ||<   |                    |           ||_        ||_        |&|_:        |S )NrE   rU   rV   g      ?r@   g?g?gGz?r   )EstimationWarningzVModel has no free parameters to estimate. Set optimized=False to suppress this warningrB   )
stackleveldtype)r   r@   c                     g | ]	\  }}||
S r/   r/   )r   bndflags      r,   r   z=ExponentialSmoothing._optimize_parameters.<locals>.<listcomp>U  s!    MMM93M3MMMr.   Tr   ls)r(   rY   )rY   r(   r   bhminimizer_kwargszkwargs['minimizer_kwargs'])r   g{Gz?)rF  stepsize)r(   rY   method)ConvergenceWarningz3Optimization failed to converge. Check mle_retvals.);r3   r4   r5   r6   r:   r;   rq   rp   r8   r9   rP   rS   r%   zerosr   r7   r"  r  r|   r}   r~   r  	SMOOTHERSr  statsmodels.tools.sm_exceptionsr;  warningswarnrG   r<   r&  rK   r   r(  r)  rw   r7  r  r'   r   isnanr*  r   r   rY   r+  r   r   successr   updater0   r   lowest_optimization_resultr	   xr   rI  r=   ),rF   r8  r-  rH  r)   r3   r4   r5   r6   r:   r,  rq   rp   r8   r9   rP   r   r;   r  r  r  
init_alpha	init_beta
init_gammainit_phir   r+   r;  messageorig_boundsrY   r.  
mod_boundsrelevant_boundsr   r   r   	ls_boundsr   rP  rF  default_kwargsobjrI  s,                                               r,   _optimize_parametersz)ExponentialSmoothing._optimize_parameters  s    
yh
F{(N	
=(!!a%((*DJ ) 
 

B $/UUS3q!99_
	<I<j(I
 	1EMZ0J/33th*ddl.$$$, 7 781<=

 

( ""Y
Hb"b
 
		

 (E*+ )ZRJrr
 	FA233Kvc{{ 	IIIIII;  M'#4CCCC))&11D DKDIK,,..+bqb/777!JJrx  &&!Q	
 
 **	
 	
 X\KO3
MMJ0D0DMMM/777BF728B<<628B<<ZZ))
 ((b"==	s$VS'.AArr
3K	 ,,,BI((1CDDDi(1
 FL C kGG--- *1
oNN[[]]F!V++,,-.&5 -   
 !''/A(BCCC-.$4  N !!&)))d##CsI@@@@C4<GGd##C((1MNNN Z&   C kGes"63??rr
s 	JJJJJJME"   esv&&&	r.   smoothing_sloper   initial_sloperV   damping_sloper   T)
	optimizedremove_biasr,  rH  minimize_kwargsr-  rX   use_basinhoppingrU   rV   c       
         &   t          |dd          }t          |dd          }t          |dd          }t          |dd          }t          |dd          }t          |dd          }t          |dd	          }t          |	d
d	          }	|	i n|	}	t          |dd	          }d}|dz  }|dz  }t	          |d|dd          }||t          d          |t          d          | j        d}n| j        }|t          d          | j        }| j        }|r|nd}| j        k|dk    rd}t          ||          }nYt          |t                    r|}t          ||          }n1|rt          |          \  }}n|                                }n| j        }|| _        t                      }||_        ||_        ||_        ||_        ||_        ||_        d|_        ||_        ||_        dx|_        |_        |dn|}|r|                     ||
||	          }n|                     ||          \  }}}||_        ||_        ||_        | j        r| j        }|                    d|j                  |_        |                    d|j                  |_        |                    d|j                  |_        |                    d|j                  |_        |                    d|j                  |_        |                    d|j                  |_        |                    d|j                  |_        |                     d|j        |j        |j        |j        |j        |j        |j        |||j                  }|j        |j        _        |S )a  
        Fit the model

        Parameters
        ----------
        smoothing_level : float, optional
            The alpha value of the simple exponential smoothing, if the value
            is set then this value will be used as the value.
        smoothing_trend :  float, optional
            The beta value of the Holt's trend method, if the value is
            set then this value will be used as the value.
        smoothing_seasonal : float, optional
            The gamma value of the holt winters seasonal method, if the value
            is set then this value will be used as the value.
        damping_trend : float, optional
            The phi value of the damped method, if the value is
            set then this value will be used as the value.
        optimized : bool, optional
            Estimate model parameters by maximizing the log-likelihood.
        remove_bias : bool, optional
            Remove bias from forecast values and fitted values by enforcing
            that the average residual is equal to zero.
        start_params : array_like, optional
            Starting values to used when optimizing the fit.  If not provided,
            starting values are determined using a combination of grid search
            and reasonable values based on the initial values of the data. See
            the notes for the structure of the model parameters.
        method : str, default "L-BFGS-B"
            The minimizer used. Valid options are "L-BFGS-B" , "TNC",
            "SLSQP" (default), "Powell", "trust-constr", "basinhopping" (also
            "bh") and "least_squares" (also "ls"). basinhopping tries multiple
            starting values in an attempt to find a global minimizer in
            non-convex problems, and so is slower than the others.
        minimize_kwargs : dict[str, Any]
            A dictionary of keyword arguments passed to SciPy's minimize
            function if method is one of "L-BFGS-B", "TNC",
            "SLSQP", "Powell", or "trust-constr", or SciPy's basinhopping
            or least_squares functions. The valid keywords are optimizer
            specific. Consult SciPy's documentation for the full set of
            options.
        use_brute : bool, optional
            Search for good starting values using a brute force (grid)
            optimizer. If False, a naive set of starting values is used.
        use_boxcox : {True, False, 'log', float}, optional
            Should the Box-Cox transform be applied to the data first? If 'log'
            then apply the log. If float then use the value as lambda.

            .. deprecated:: 0.12

               Set use_boxcox when constructing the model

        use_basinhopping : bool, optional
            Deprecated. Using Basin Hopping optimizer to find optimal values.
            Use ``method`` instead.

            .. deprecated:: 0.12

               Use ``method`` instead.

        initial_level : float, optional
            Value to use when initializing the fitted level.

            .. deprecated:: 0.12

               Set initial_level when constructing the model

        initial_trend : float, optional
            Value to use when initializing the fitted trend.

            .. deprecated:: 0.12

               Set initial_trend when constructing the model
               or set initialization_method.

        Returns
        -------
        HoltWintersResults
            See statsmodels.tsa.holtwinters.HoltWintersResults.

        Notes
        -----
        This is a full implementation of the holt winters exponential smoothing
        as per [1]. This includes all the unstable methods as well as the
        stable methods. The implementation of the library covers the
        functionality of the R library as much as possible whilst still
        being Pythonic.

        The parameters are ordered

        [alpha, beta, gamma, initial_level, initial_trend, phi]

        which are then followed by m seasonal values if the model contains
        a seasonal smoother. Any parameter not relevant for the model is
        omitted. For example, a model that has a level and a seasonal
        component, but no trend and is not damped, would have starting
        values

        [alpha, gamma, initial_level, s0, s1, ..., s<m-1>]

        where sj is the initial value for seasonal component j.

        References
        ----------
        [1] Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles
            and practice. OTexts, 2014.
        r   Tr   r   r   rU   rV   r,  rh   re  Nrf  rD  rB  )zL-BFGS-BTNCSLSQPPowellztrust-constrrH  F)re   r   rf   zVInitial values were set during model construction. These cannot be changed during fit.z@use_boxcox was set at model initialization and cannot be changedzGuse_basinhopping is deprecated. Set optimization method using 'method'.r   logrg   ri  r:  rW   r   )r   r   r   r   r   rU   rV   initial_seasonsrX   rd  is_optimized) r   r   r   r   r   rs   r   ro   rP   r   r$   rK   squeezern   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r=   r<   r_  r   r   r   r   _results)rF   r   r   r   r   rc  rd  r,  rH  re  r-  rX   rf  rU   rV   r3   r4   r6   r5   supported_methodsr8  rO   lamdar:   r   r  r  r  fphwfits                                 r,   fitzExponentialSmoothing.fit  s   B ?,=tDD/+<dCC-/CTJJ>>"=/4HH"=/4HH!,NNN#.
 
 
 !0 7""_$04
 
 
 344 
 	
 %
 
 
 $(A0   !   %JJ)J'"  
 z"$cc#U""4''J.. #"4'' #!$<<55 LLNNAll		!	!	!
%))#("N 	H++Y CC ,,+= -  JBB CICICL% H+FF#4ci@@	66"3SX>>FF#7CC	&&#'::FF?CI>>	FF?CI>>	!vv&8#,GGIH"y'))L!#  
 
 &)_"r.   c                 d   | j         |s| j        | j        | j        fS | j        }| j        }| j        }| j        }| j        }| j	        }	|}
|}|r|
8|t          j        | j                  |	z  dk                                             n|
}
||r||	|	|	z            |d|	         }}|dk    rct          j        t          j        |                                          t          j        |                                          z
  |	z            }n||z
  |	z                                  }|dk    rt!          |d|	         |
z            nt!          |d|	         |
z
            }nI|r9|
|d         n|
}
|(|dk    r|d         |d         z  n|d         |d         z
  }g }n|
|d         }
d}g }|
||fS )a  
        Compute initial values used in the exponential smoothing recursions.

        Parameters
        ----------
        initial_level : {float, None}
            The initial value used for the level component.
        initial_trend : {float, None}
            The initial value used for the trend component.
        force : bool
            Force the calculation even if initial values exist.

        Returns
        -------
        initial_level : float
            The initial value used for the level component.
        initial_trend : {float, None}
            The initial value used for the trend component.
        initial_seasons : list
            The initial values used for the seasonal components.

        Notes
        -----
        Convenience function the exposes the values used to initialize the
        recursions. When optimizing parameters these are used as starting
        values.

        Method used to compute the initial value depends on when components
        are included in the model.  In a simple exponential smoothing model
        without trend or a seasonal components, the initial value is set to the
        first observation. When a trend is added, the trend is initialized
        either using y[1]/y[0], if multiplicative, or y[1]-y[0]. When the
        seasonal component is added the initialization adapts to account for
        the modified structure.
        Nr   r   r@   )rx   ry   rz   r{   rn   r8   r9   rq   rp   rS   r%   arangerw   meanexprk  list)rF   rU   rV   r   r:   r8   r9   rq   rp   r   r  r  leadlagr  s                  r,   r   z#ExponentialSmoothing.initial_values  s   L &252##& 
 G
=(N	! 	<>J29TY''!+q0166888BBziza!a%iL!BQB%cE>>		!4!4rvchhjj7I7I!IQ NOOBB#:*0022B%-%6%6aebj!!!D2A2<L<LBB 		1Bz$)UNNQqTAaD[[!qtBBzqTBB2rzr.   c                   789 |}|}|}|}| j         }| j        }| j        }| j        }| j        }| j        }| j        7|r|nd}|	dk    rd}
t          |d          }nzt          |	t                    r|	}
t          ||
          }nR|	rt          |          \  }}
n=d}
|
                                }t          j        |          dk    rt          d          t          j        | j        f          }t          j        | j        f          }d|z
  }||z  |dd<   |d|z
  nd}|d|z
  nd}|r
||z  |dd<   t          j        | j        |z   dz   f          }t          j        | j        |z   dz   f          }t          j        | j        |z   7z   dz   f          9||d<   ||d<   |9d7<   |rFt          j        t          j        ||dz             t          j        d|dz   dz             z            nt          j        d|dz   dz             }t          j        t          j        d d	|         } t          j        t          j        d
 d	|         }!t          j        t          j        d d	|         }"| j        8|dk    rt1          d8dz             D ]}#||#dz
           9|#dz
           z  | | ||#dz
            |"||#dz
           |                    z  z   ||#<   |r:| |!||#         ||#dz
                     z  | |"||#dz
           |          z  z   ||#<   ||#dz
            | ||#dz
            |"||#dz
           |                    z  |9|#dz
           z  z   9|#7z   dz
  <   |d8dz                                            }$9787z                                            }%|8         |8d<   |r0 |"|d8         |          |d8<    |"|8         |          |8d<    | ||          }789fdt1          |dz   dz             D             987z   dz
  d<   |9d7          z  }&n|dk    rt1          d8dz             D ]}#||#dz
           |9|#dz
           z  z
  | | ||#dz
            |"||#dz
           |                    z  z   ||#<   |r:| |!||#         ||#dz
                     z  | |"||#dz
           |          z  z   ||#<   ||#dz
           | | ||#dz
            |"||#dz
           |                    z  z
  |9|#dz
           z  z   9|#7z   dz
  <   |d8dz                                            }$9787z                                            }%|8         |8d<   |r0 |"|d8         |          |d8<    |"|8         |          |8d<    | ||          }789fdt1          |dz   dz             D             987z   dz
  d<   |9d7          z   }&nt1          d8dz             D ]x}#||#dz
           | | ||#dz
            |"||#dz
           |                    z  z   ||#<   |r:| |!||#         ||#dz
                     z  | |"||#dz
           |          z  z   ||#<   y|d8dz                                            }$9787z                                            }%|8         |8d<   |r0 |"|d8         |          |d8<    |"|8         |          |8d<    | ||          }|}&|d8dz                                            }'|	s|	dk    st          |	t                    rt5          |&|
          }&|&d| dz
           |z
  }(|(j        |(z  })7|z  d|z  z   dz   d|z  z   }*| j        t          j        |)| j        z            z  |*dz  z   }+| j        |*z
  dz
  },|,dk    rd|*dz   z  |*dz   z  |,z  }-nt          j        }-|+|-z   }.| j        t          j        |)| j        z            z  |*t          j        | j                  z  z   }/||&d| dz
           z
  }0|r|&|0                                z  }&||||r|nt          j        |d         |dk    r|d         |z  nd9d7         |	|
|d
| _         g d}1|1d t1          7          D             z  }1g d}2|2d t1          7          D             z  }2||||d         |d         |g}3|39d7         !                                z  }3tE          tG          d |3                    }3t          j$        |3          }3|)t          j        tK          |1          tL                    }4n|'                    tL                    }4d||d||g}5|5dg7z  z  }5tQ          j)        d tU          |1|3|4          D             g d|2          }3|3j+        |5         }3tY          | | j         |&|&d| dz
           |&| dz
  d         |)|'|$|%|+|/|.|0|*|3|4          }6t[          |6          S )z
        Helper prediction function

        Parameters
        ----------
        h : int, optional
            The number of time steps to forecast ahead.
        r   rk  rg   Nr@   z!Only 1 dimensional data supportedr   c                     | S r#   r/   lr  s     r,   <lambda>z/ExponentialSmoothing._predict.<locals>.<lambda>0  s     r.   )r   r   Nc                     dS Nr   r/   r~  s     r,   r  z/ExponentialSmoothing._predict.<locals>.<lambda>3      A r.   c                     dS r  r/   )r  r5   s     r,   r  z/ExponentialSmoothing._predict.<locals>.<lambda>6  r  r.   r   c                 2    g | ]}d z
  |z  z            S r@   r/   r   jr   rw   r  s     r,   r   z1ExponentialSmoothing._predict.<locals>.<listcomp>M  8     ! ! !*+4!8q1u$%! ! !r.   r   c                 2    g | ]}d z
  |z  z            S r  r/   r  s     r,   r   z1ExponentialSmoothing._predict.<locals>.<listcomp>h  r  r.   rA   rB   )
r   r   r   r   rU   rV   rl  rX   rq  rd  )r3   r4   r6   zl.0zb.0r5   c                     g | ]}d | S )zs.r/   r   s     r,   r   z1ExponentialSmoothing._predict.<locals>.<listcomp>  s    ---q(q((---r.   r  c                     g | ]}d | S )zinitial_seasons.r/   r   s     r,   r   z1ExponentialSmoothing._predict.<locals>.<listcomp>  s!    9991&1&&999r.   c                 "    | t           j        n| S r#   )r%   r   )vs    r,   r  z/ExponentialSmoothing._predict.<locals>.<lambda>  s    rvv r.   r=  Tc                      g | ]\  }}}|||gS r/   r/   )r   cr-   os       r,   r   z1ExponentialSmoothing._predict.<locals>.<listcomp>  s$    GGG71aaAYGGGr.   )r   paramrc  )columnsindex)r   fittedvaluesfcastvaluessser7   r8   seasonaicbicaiccresidkparams_formattedrc  ).r^   rP   rq   rp   r8   r9   rS   r   r$   rK   rn  r%   r`   NotImplementedErrorrJ  rw   cumsumrepeatrv  multiplyr   dividesubtractpowerr   r   r
   r'   rk  r   rw  r   r;   tolistry  mapr  rv   boolr(  pd	DataFramer  r   r   r   ):rF   r   r   r   r   rU   rV   r   rl  rX   rq  rd  rm  r3   r4   r6   r5   r8  rO   rq   rp   r8   r9   r:   y_alphay_gammaalphacbetacgammaclvlsr  phi_htrendeddetrenddampenr   _trendr  fittedr7   r*   r  r  r  dof_effaicc_penaltyr  r  r  codesidx	formattedrc  includedrs  r   rw   r  s:                                                          @@@r,   r   zExponentialSmoothing._predict  s2   6  " z"(N	
=!$ccEtS!!AA
E** 		OEtU##AA 	Od||HAuuEAwqzzQ)*MNNN(DI<(((DI<((UQY
 ,D!#/UQ 	#GAAAJxQ*,--Hdi!ma')**Hdi!ma'!+-..Q!"1" )BIbiQU++ryAEAI/F/FFGGG1a!eai(( 	
 +bfNNKK
 )BK~~NN
 "+=M=MNN
 yu1dQh'' 
( 
(!!a%.1QU83WWT!a%[&&1q532G2GHHHQ   7747DQK#@#@@qQx 5 55AaD  'q1u~QK!a%#!6!61 1  aAh& (!a%!) q4!8|_))++Fq4!8|_))++Ft*DK 2!6!ETE(C00%4%!6!D'511$%%GD!$$E! ! ! ! ! !/4QUQY/?/?! ! !AdQhlnn QssV^FF1dQh''  AENqQx')QUVVAa!eHc5J5J K KKM Q
   7747DQK#@#@@qQx 5 55AaD AENwwtAE{FF1QU8S4I4IJJJL!a%(* !a%!)
 q4!8|_))++Fq4!8|_))++Ft*DK 2!6!ETE(C00%4%!6!D'511$%%GD!$$E! ! ! ! ! !/4QUQY/?/?! ! !AdQhlnn QssV^FF1dQh''  !!a%.WWT!a%[&&1q532G2GHHHQ   7747DQK#@#@@qQx 5 55AaD q4!8|_))++Fq4!8|_))++Ft*DK 2!6!ETE(C00%4%!6!D'511$%%GD!$$EFQ\"'')) 	/u,,
:u0M0M,..FXrAvX%eckq9},q01v:=i"&ty111AE9)a-!#Q;;QK1q51W<LL6L\!i"&ty111Aty8I8I4IIvhQh'' 	#ejjll"F$#"'$*6SS!!W+.77QqTCZZ !u$&
 
 @??--E!HH----
 
 
 	99a9999D%a!A$<	QrrU\\^^#	AA9MMNN	HY''	U4888II$++D11I)\4FKTFQJLGGc%I&F&FGGG222
 
 
	
 M(+	"K1"q&)rAvxx(&!
 
 
$ )///r.   )NFNr    )r)   )NNNN)NNF)NNNNNNNNNNNN)#rH   rI   rJ   __doc__r   rm   r   r   
contextlibcontextmanagerr   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r  r   r  r&  r7  r2   r_  rt  r   r   __classcell__r   s   @r,   rN   rN   s   s`       Z Zx _X~.. Y$ )!Y$ Y$ Y$ Y$ Y$ Y$ /.Y$v  @   D( D( D(L4 4 4.& & && & &* * *8 8 8#@ #@ #@ #@J  $ 08E EE)E E E \E   J# J# \J#X  8 8 860 0 0d% % %Nhh	h h h hT _&(9::__o66__o66 t !t t t t 76 76 ;:tn =BI I I IV _&(9::__o66 c0 c0 c0 76 ;:c0 c0 c0 c0 c0r.   rN   c            
       J     e Zd ZdZ	 	 d fd	Z	 d	ddddddddd fdZ xZS )
SimpleExpSmoothinga.  
    Simple Exponential Smoothing

    Parameters
    ----------
    endog : array_like
        The time series to model.
    initialization_method : str, optional
        Method for initialize the recursions. One of:

        * None
        * 'estimated'
        * 'heuristic'
        * 'legacy-heuristic'
        * 'known'

        None defaults to the pre-0.12 behavior where initial values
        are passed as part of ``fit``. If any of the other values are
        passed, then the initial values must also be set when constructing
        the model. If 'known' initialization is used, then `initial_level`
        must be passed, as well as `initial_trend` and `initial_seasonal` if
        applicable. Default is 'estimated'. "legacy-heuristic" uses the same
        values that were used in statsmodels 0.11 and earlier.
    initial_level : float, optional
        The initial level component. Required if estimation method is "known".
        If set using either "estimated" or "heuristic" this value is used.
        This allows one or more of the initial values to be set while
        deferring to the heuristic for others or estimating the unset
        parameters.

    See Also
    --------
    ExponentialSmoothing
        Exponential smoothing with trend and seasonal components.
    Holt
        Exponential smoothing with a trend component.

    Notes
    -----
    This is a full implementation of the simple exponential smoothing as
    per [1]_.  `SimpleExpSmoothing` is a restricted version of
    :class:`ExponentialSmoothing`.

    See the notebook `Exponential Smoothing
    <../examples/notebooks/generated/exponential_smoothing.html>`__
    for an overview.

    References
    ----------
    .. [1] Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles
        and practice. OTexts, 2014.
    Nc                 P    t                                          |||           d S )N)rT   rU   rl   rm   )rF   r^   rT   rU   r   s       r,   rm   zSimpleExpSmoothing.__init__  s9     	"7' 	 	
 	
 	
 	
 	
r.   TF)rc  r,  rU   r-  rX   rd  rH  re  c                X    t                                          |||||||||		  	        S )a	  
        Fit the model

        Parameters
        ----------
        smoothing_level : float, optional
            The smoothing_level value of the simple exponential smoothing, if
            the value is set then this value will be used as the value.
        optimized : bool, optional
            Estimate model parameters by maximizing the log-likelihood.
        start_params : ndarray, optional
            Starting values to used when optimizing the fit.  If not provided,
            starting values are determined using a combination of grid search
            and reasonable values based on the initial values of the data.
        initial_level : float, optional
            Value to use when initializing the fitted level.
        use_brute : bool, optional
            Search for good starting values using a brute force (grid)
            optimizer. If False, a naive set of starting values is used.
        use_boxcox : {True, False, 'log', float}, optional
            Should the Box-Cox transform be applied to the data first? If 'log'
            then apply the log. If float then use the value as lambda.
        remove_bias : bool, optional
            Remove bias from forecast values and fitted values by enforcing
            that the average residual is equal to zero.
        method : str, default "L-BFGS-B"
            The minimizer used. Valid options are "L-BFGS-B" (default), "TNC",
            "SLSQP", "Powell", "trust-constr", "basinhopping" (also "bh") and
            "least_squares" (also "ls"). basinhopping tries multiple starting
            values in an attempt to find a global minimizer in non-convex
            problems, and so is slower than the others.
        minimize_kwargs : dict[str, Any]
            A dictionary of keyword arguments passed to SciPy's minimize
            function if method is one of "L-BFGS-B" (default), "TNC",
            "SLSQP", "Powell", or "trust-constr", or SciPy's basinhopping
            or least_squares. The valid keywords are optimizer specific.
            Consult SciPy's documentation for the full set of options.

        Returns
        -------
        HoltWintersResults
            See statsmodels.tsa.holtwinters.HoltWintersResults.

        Notes
        -----
        This is a full implementation of the simple exponential smoothing as
        per [1].

        References
        ----------
        [1] Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles
            and practice. OTexts, 2014.
        )	r   rc  r,  rU   r-  rd  rX   rH  re  rl   rt  )rF   r   rc  r,  rU   r-  rX   rd  rH  re  r   s             r,   rt  zSimpleExpSmoothing.fit  s@    D ww{{+%'#!+  

 

 
	
r.   r    r#   )rH   rI   rJ   r  rm   rt  r  r  s   @r,   r  r    s        3 3p #	

 

 

 

 

 

 L
 L
 L
 L
 L
 L
 L
 L
 L
 L
 L
 L
r.   r  c                        e Zd ZdZ edd          	 	 	 	 	 d fd	            Z edd           ed	d
           edd          	 	 dddddddddddd
 fd                                    Z xZS )Holta$	  
    Holt's Exponential Smoothing

    Parameters
    ----------
    endog : array_like
        The time series to model.
    exponential : bool, optional
        Type of trend component.
    damped_trend : bool, optional
        Should the trend component be damped.
    initialization_method : str, optional
        Method for initialize the recursions. One of:

        * None
        * 'estimated'
        * 'heuristic'
        * 'legacy-heuristic'
        * 'known'

        None defaults to the pre-0.12 behavior where initial values
        are passed as part of ``fit``. If any of the other values are
        passed, then the initial values must also be set when constructing
        the model. If 'known' initialization is used, then `initial_level`
        must be passed, as well as `initial_trend` and `initial_seasonal` if
        applicable. Default is 'estimated'. "legacy-heuristic" uses the same
        values that were used in statsmodels 0.11 and earlier.
    initial_level : float, optional
        The initial level component. Required if estimation method is "known".
        If set using either "estimated" or "heuristic" this value is used.
        This allows one or more of the initial values to be set while
        deferring to the heuristic for others or estimating the unset
        parameters.
    initial_trend : float, optional
        The initial trend component. Required if estimation method is "known".
        If set using either "estimated" or "heuristic" this value is used.
        This allows one or more of the initial values to be set while
        deferring to the heuristic for others or estimating the unset
        parameters.

    See Also
    --------
    ExponentialSmoothing
        Exponential smoothing with trend and seasonal components.
    SimpleExpSmoothing
        Basic exponential smoothing with only a level component.

    Notes
    -----
    This is a full implementation of the Holt's exponential smoothing as
    per [1]_. `Holt` is a restricted version of :class:`ExponentialSmoothing`.

    See the notebook `Exponential Smoothing
    <../examples/notebooks/generated/exponential_smoothing.html>`__
    for an overview.

    References
    ----------
    .. [1] Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles
        and practice. OTexts, 2014.
    rO   rP   FNc                 b    |rdnd}t                                          ||||||           d S )Nr   r   )r8   rP   rT   rU   rV   r  )	rF   r^   exponentialrP   rT   rU   rV   r8   r   s	           r,   rm   zHolt.__init__  sP     %/%%"7'' 	 	
 	
 	
 	
 	
r.   r`  r   ra  rV   rb  r   T)
r   rc  r,  rU   rV   r-  rX   rd  rH  re  c       
         ^    t                                          |||||||||	|
||          S )a@  
        Fit the model

        Parameters
        ----------
        smoothing_level : float, optional
            The alpha value of the simple exponential smoothing, if the value
            is set then this value will be used as the value.
        smoothing_trend :  float, optional
            The beta value of the Holt's trend method, if the value is
            set then this value will be used as the value.
        damping_trend : float, optional
            The phi value of the damped method, if the value is
            set then this value will be used as the value.
        optimized : bool, optional
            Estimate model parameters by maximizing the log-likelihood.
        start_params : ndarray, optional
            Starting values to used when optimizing the fit.  If not provided,
            starting values are determined using a combination of grid search
            and reasonable values based on the initial values of the data.
        initial_level : float, optional
            Value to use when initializing the fitted level.

            .. deprecated:: 0.12

               Set initial_level when constructing the model

        initial_trend : float, optional
            Value to use when initializing the fitted trend.

            .. deprecated:: 0.12

               Set initial_trend when constructing the model

        use_brute : bool, optional
            Search for good starting values using a brute force (grid)
            optimizer. If False, a naive set of starting values is used.
        use_boxcox : {True, False, 'log', float}, optional
            Should the Box-Cox transform be applied to the data first? If 'log'
            then apply the log. If float then use the value as lambda.
        remove_bias : bool, optional
            Remove bias from forecast values and fitted values by enforcing
            that the average residual is equal to zero.
        method : str, default "L-BFGS-B"
            The minimizer used. Valid options are "L-BFGS-B" (default), "TNC",
            "SLSQP", "Powell", "trust-constr", "basinhopping" (also "bh") and
            "least_squares" (also "ls"). basinhopping tries multiple starting
            values in an attempt to find a global minimizer in non-convex
            problems, and so is slower than the others.
        minimize_kwargs : dict[str, Any]
            A dictionary of keyword arguments passed to SciPy's minimize
            function if method is one of "L-BFGS-B" (default), "TNC",
            "SLSQP", "Powell", or "trust-constr", or SciPy's basinhopping
            or least_squares. The valid keywords are optimizer specific.
            Consult SciPy's documentation for the full set of options.

        Returns
        -------
        HoltWintersResults
            See statsmodels.tsa.holtwinters.HoltWintersResults.

        Notes
        -----
        This is a full implementation of the Holt's exponential smoothing as
        per [1].

        References
        ----------
        [1] Hyndman, Rob J., and George Athanasopoulos. Forecasting: principles
            and practice. OTexts, 2014.
        )r   r   r   rc  r,  rU   rV   r-  rX   rd  rH  re  r  )rF   r   r   r   rc  r,  rU   rV   r-  rX   rd  rH  re  r   s                r,   rt  zHolt.fit  sI    t ww{{++'%''!#+  
 
 	
r.   )FFNNNr    )rH   rI   rJ   r  r   rm   rt  r  r  s   @r,   r  r  `  s       < <| _X~.. "
 
 
 
 
 /.
& _&(9::__o66__o66 d

 d
 d
 d
 d
 d
 d
 76 76 ;:d
 d
 d
 d
 d
r.   r  )Ar  statsmodels.compat.pandasr   r  typingr   collections.abcr   r   rM  numpyr%   pandasr  scipy.optimizer   r   r	   scipy.specialr
   scipy.statsr   statsmodels.tools.validationr   r   r   r   r   r   statsmodels.tsa.base.tsa_modelr   )statsmodels.tsa.exponential_smoothing.etsr   r   statsmodels.tsa.holtwintersr   	smoothersr   py_smoothers2statsmodels.tsa.holtwinters._exponential_smoothersr   &statsmodels.tsa.holtwinters._smoothersr   r   #statsmodels.tsa.holtwinters.resultsr   r   statsmodels.tsa.tsatoolsr   holt_win_add_mul_damholt_win_mul_mul_damholt_win__mulholt_win_add_add_damholt_win_mul_add_damholt_win__addholt_add_damholt_mul_damholt__rK  PY_SMOOTHERSr0   r2   rN   r  r  r/   r.   r,   <module>r     sN    6 5 5 5 5 5           . . . . . . . .          @ @ @ @ @ @ @ @ @ @ $ $ $ $ $ $                      ; : : : : :               O N N N N N               4 3 3 3 3 3 22*22*))"
 
	 !5 5- 5 5-,,%
 
         2Y0 Y0 Y0 Y0 Y0? Y0 Y0 Y0x*N
 N
 N
 N
 N
- N
 N
 N
bz
 z
 z
 z
 z
 z
 z
 z
 z
 z
r.   