
    VfdA*                     D   d Z ddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZmZmZ ej                            ej                            e                    Z G d dej                  Z G d d	          Z G d
 dej                  Zd Z G d d          ZdS )zM
Tests for miscellaneous models

Author: Chad Fulton
License: Simplified-BSD
    N)mlemodelsarimax)datasets)assert_equalassert_allcloseassert_raisesc                   X     e Zd ZdZ fdZed             Zed             Z fdZ xZ	S )
Interceptszp
    Test class for observation and state intercepts (which usually do not
    get tested in other models).
    c                 f   d}d} t          t          |           j        |f||d| t          j        d          | d<   t          j        d          | d<   t          j        d          | d<   t          j        d          | d<   t          j        d          | d<   |                                  d S )N   k_statesk_posdefdesignobs_cov
transition	selection	state_cov)superr
   __init__npeyeinitialize_approximate_diffuseselfendogkwargsr   r   	__class__s        Llib/python3.11/site-packages/statsmodels/tsa/statespace/tests/test_models.pyr   zIntercepts.__init__   s    (j$(	C$x	C 	C;A	C 	C 	CX&))YVAYY\F1II[F1II[++-----    c                 
    g dS )N)zd.1zd.2zd.3zc.1zc.2zc.3 r   s    r   param_nameszIntercepts.param_names&   s    9999r    c                 *    t          j        d          S )N   )r   aranger#   s    r   start_paramszIntercepts.start_params*   s    y||r    c                 ~     t          t          |           j        |fi |}|d d         | d<   |dd          | d<   d S )Nr   obs_interceptstate_intercept)r   r
   updater   paramsr   r   s      r   r,   zIntercepts.update.   sR    /z4((/AA&AA &rr
_"(*r    
__name__
__module____qualname____doc__r   propertyr$   r(   r,   __classcell__r   s   @r   r
   r
      s         
. 
. 
. 
. 
. : : X:   X- - - - - - - - -r    r
   c                       e Zd Zedd            Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd ZdS )TestInterceptsmixedc                    t           t          j        z   dz   }t          j        |          | _        t          j                                        j	        }t          j
        ddd          |_        |g d                                         }||                                z  }|dk    r5t          j        |j        d dd d f<   t          j        |j        d	d
d d f<   n|dk    r1t          j        |j        dddf<   t          j        |j        d	d
df<   n~|dk    rxt          j        |j        dddf<   t          j        |j        dddf<   t          j        |j        dddf<   t          j        |j        d	d
df<   t          j        |j        d	d
df<   t#          |fi |}t          j        d          dz   | _        || _        |                    | j        d          | _        t          j        d| j        j        f          | j        _        t          j        d| j        j        f          | j        _        t          j        d| j        j        f          | j        _        t          j        d| j        j        f          | j        _        t;          | j        j                  D ]}t          j                            | j        j         d d d d |f                   | j        j        d|f<   t          j                            | j        j!        d d d d |dz   f                   | j        j        d|f<   t          j                            | j        j"        d d d d |f                   | j        j        d|f<   t          j                            | j        j#        d d d d |f                   | j        j        d|f<   d S )Nz results/results_intercepts_R.csvz
1959-01-01z	2009-7-01QS)startendfreq)realgdprealconsrealinvall2   w      partialr   r9      F      '   Z      r&   T)
return_ssm)$current_pathosseppdread_csvdesiredr   	macrodataload_pandasdata
date_rangeindexcopystdr   nanilocr
   r'   r.   modelsmoothresultszerosnobs!det_scaled_smoothed_estimator_covdet_predicted_state_covdet_smoothed_state_cov"det_smoothed_state_disturbance_covrangelinalgdetscaled_smoothed_estimator_covpredicted_state_covsmoothed_state_covsmoothed_state_disturbance_cov)clswhichr   pathdtaobsmodis           r   setup_classzTestIntercepts.setup_class6   s}    bf$'IIk$''  ,,..3M+'+- - -	4445::<<CGGIIoE>>!vCHSbS!!!V#%6CHSWaaaZ  i "CHQrT1W#%6CHSWaZ  g "CHQrT1W!#CHRUAX!#CHRUAX#%6CHSWaZ #%6CHSWaZ ''''Yq\\A%
	jjj==
 Ha()) 	5.0h39>7J.K.K+-/Xq#).6I-J-J*Ha()) 	6 sy~&& 
	J 
	JA	K=aaaAgFH H K9!Q$? 9;	/111ac	:9< 9<CK/1579y}}.qqq!!!Qw789 89CK.q!t4 	K>qqq!!!QwGI I K:1a4@@
	J 
	Jr    c                 ^    t          t          j        | j        j                  d           d S )NgY	)r   r   sumr_   llf_obsr#   s    r   test_loglikezTestIntercepts.test_loglikel   s'    t|344nEEEEEr    c                 ^    t          | j        j        j        | j        g d                    d S )N)r1r2r3)r   r_   scaled_smoothed_estimatorTrS   r#   s    r   test_scaled_smoothed_estimatorz-TestIntercepts.test_scaled_smoothed_estimatoro   s:    L24L+++,	
 	
 	
 	
 	
r    c                 \    t          | j        j        j        | j        dg                    d S )NdetN)r   r_   rb   r~   rS   r#   s    r   "test_scaled_smoothed_estimator_covz1TestIntercepts.test_scaled_smoothed_estimator_covu   s5    L:<L&"	
 	
 	
 	
 	
r    c                 ^    t          | j        j        j        | j        g d                    d S )N)m1m2m3)r   r_   	forecastsr~   rS   r#   s    r   test_forecastszTestIntercepts.test_forecasts{   s:    L"$L+++,	
 	
 	
 	
 	
r    c                 ^    t          | j        j        j        | j        g d                    d S )N)v1v2v3)r   r_   forecasts_errorr~   rS   r#   s    r   test_forecasts_errorz#TestIntercepts.test_forecasts_error   s:    L(*L+++,	
 	
 	
 	
 	
r    c                 x    t          | j        j                                        | j        g d                    d S )N)F1F2F3)r   r_   forecasts_error_covdiagonalrS   r#   s    r   test_forecasts_error_covz'TestIntercepts.test_forecasts_error_cov   sC    L,5577L+++,	
 	
 	
 	
 	
r    c                 v    t          | j        j        d d dd f         j        | j        g d                    d S )NrI   )a1a2a3)r   r_   predicted_stater~   rS   r#   s    r   test_predicted_statesz$TestIntercepts.test_predicted_states   sK    L(ABB/1L+++,	
 	
 	
 	
 	
r    c                 \    t          | j        j        j        | j        dg                    d S )NdetP)r   r_   rc   r~   rS   r#   s    r   test_predicted_states_covz(TestIntercepts.test_predicted_states_cov   s5    L02L&"	
 	
 	
 	
 	
r    c                 ^    t          | j        j        j        | j        g d                    d S )N)	alphahat1	alphahat2	alphahat3)r   r_   smoothed_stater~   rS   r#   s    r   test_smoothed_statesz#TestIntercepts.test_smoothed_states   s:    L')L@@@A	
 	
 	
 	
 	
r    c                 \    t          | j        j        j        | j        dg                    d S )NdetV)r   r_   rd   r~   rS   r#   s    r   test_smoothed_states_covz'TestIntercepts.test_smoothed_states_cov   s5    L/1L&"	
 	
 	
 	
 	
r    c                 ^    t          | j        j        j        | j        g d                    d S )N)muhat1muhat2muhat3)r   r_   smoothed_forecastsr~   rS   r#   s    r   test_smoothed_forecastsz&TestIntercepts.test_smoothed_forecasts   s:    L+-L7778	
 	
 	
 	
 	
r    c                 ^    t          | j        j        j        | j        g d                    d S )N)etahat1etahat2etahat3)r   r_   smoothed_state_disturbancer~   rS   r#   s    r   test_smoothed_state_disturbancez.TestIntercepts.test_smoothed_state_disturbance   s:    L35L:::;	
 	
 	
 	
 	
r    c                 \    t          | j        j        j        | j        dg                    d S )NdetVeta)r   r_   re   r~   rS   r#   s    r   #test_smoothed_state_disturbance_covz2TestIntercepts.test_smoothed_state_disturbance_cov   s5    L;=L)%	
 	
 	
 	
 	
r    c                 b    t          | j        j        j        | j        g d         d           d S )N)epshat1epshat2epshat3g&.>)atol)r   r_    smoothed_measurement_disturbancer~   rS   r#   s    r   %test_smoothed_measurement_disturbancez4TestIntercepts.test_smoothed_measurement_disturbance   sA    L9;L:::;$	
 	
 	
 	
 	
 	
r    c                 x    t          | j        j                                        | j        g d                    d S )N)Veps1Veps2Veps3)r   r_   $smoothed_measurement_disturbance_covr   rS   r#   s    r   )test_smoothed_measurement_disturbance_covz8TestIntercepts.test_smoothed_measurement_disturbance_cov   sC    L=FFHHL4445	
 	
 	
 	
 	
r    N)r9   )r0   r1   r2   classmethodrt   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r    r   r8   r8   5   s       3J 3J 3J [3JjF F F
 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 
 
 
r    r8   c                   X     e Zd ZdZ fdZed             Zed             Z fdZ xZ	S )LargeStateCovAR1z
    Test class for k_posdef > k_states (which usually do not get tested in
    other models).

    This is just an AR(1) model with an extra unused state innovation
    c                     d}d} t          t          |           j        |f||d| d| d<   d| d<   d| d<   |                                  d S )NrI   rL   r   )r   r   r   )r   r   r   )r   rI   rI   )r   r   r   initialize_stationaryr   s        r   r   zLargeStateCovAR1.__init__   s    .%%.	C$x	C 	C;A	C 	C 	C ^"#"#""$$$$$r    c                 
    ddgS )Nphisigma2r"   r#   s    r   r$   zLargeStateCovAR1.param_names   s    x  r    c                 
    ddgS )N      ?rI   r"   r#   s    r   r(   zLargeStateCovAR1.start_params   s    Qxr    c                 v     t          t          |           j        |fi |}|d         | d<   |d         | d<   d S )Nr   )r   r   r   rI   )r   r   r   )r   r   r,   r-   s      r   r,   zLargeStateCovAR1.update   sL    5'..5fGGGG#)!9 "()r    r/   r6   s   @r   r   r      s         % % % % % ! ! X!   X, , , , , , , , ,r    r   c                  `    t          t          t          t          j        d                     d S )N
   )r   
ValueErrorr   r   r'   r"   r    r   test_large_kposdefr      s#    *.	">>>>>r    c                   ~    e Zd Zed             Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )TestLargeStateCovAR1c                     t          j        d           g d}ddg}t          j        |          }|                    |          | _        t          |          }|                    |          | _        d S )NzTODO: This test is skipped since an exception is currently raised if k_posdef > k_states. However, this test could be used if models of those types were allowed)
皙?g      333333ӿgg      ?r   r   r   r   g?r   rI   )pytestskipr   SARIMAXr^   res_desiredr   res)rm   r   r.   mod_desiredrr   s        r   rt   z TestLargeStateCovAR1.setup_class   s    9	
 	
 	
 EDD q oe,,%,,V44 u%%**V$$r    c                 z   t          | j        j        j        d           t          | j        j        j        d           t          | j        j        j        d           t          | j        j        j        d           t          | j        j        j        d           t          | j        j        j        d           d S )NrI   rL   )rL   r   )rI   r   )r   r   filter_resultsr   r   r   shaper   r#   s    r   test_dimensionsz$TestLargeStateCovAR1.test_dimensions   s    TX,5q999TX,5q999TX8>HHHT%4=qAAAT%4=qAAAT%@F	 	 	 	 	r    c                 N    t          | j        j        | j        j                   d S N)r   r   rw   r   r#   s    r   rx   z!TestLargeStateCovAR1.test_loglike	  s#    ($*:*BCCCCCr    c                 f    t          | j        j        d         | j        j        d                    d S Nr   )r   r   r}   r   r#   s    r   r   z3TestLargeStateCovAR1.test_scaled_smoothed_estimator  s=    :1=(B1E	G 	G 	G 	G 	Gr    c                 f    t          | j        j        d         | j        j        d                    d S r   )r   r   ri   r   r#   s    r   r   z7TestLargeStateCovAR1.test_scaled_smoothed_estimator_cov  s=    >qA(FqI	K 	K 	K 	K 	Kr    c                 N    t          | j        j        | j        j                   d S r   )r   r   r   r   r#   s    r   r   z#TestLargeStateCovAR1.test_forecasts  s#    *D,<,FGGGGGr    c                 N    t          | j        j        | j        j                   d S r   )r   r   r   r   r#   s    r   r   z)TestLargeStateCovAR1.test_forecasts_error  s.    0(8	: 	: 	: 	: 	:r    c                 N    t          | j        j        | j        j                   d S r   )r   r   r   r   r#   s    r   r   z-TestLargeStateCovAR1.test_forecasts_error_cov  s.    4(<	> 	> 	> 	> 	>r    c                 f    t          | j        j        d         | j        j        d                    d S r   )r   r   r   r   r#   s    r   r   z*TestLargeStateCovAR1.test_predicted_states  s8    03(8;	= 	= 	= 	= 	=r    c                 f    t          | j        j        d         | j        j        d                    d S Nr   r   )r   r   rj   r   r#   s    r   r   z.TestLargeStateCovAR1.test_predicted_states_cov#  s=    4T:(<TB	D 	D 	D 	D 	Dr    c                 f    t          | j        j        d         | j        j        d                    d S r   )r   r   r   r   r#   s    r   r   z)TestLargeStateCovAR1.test_smoothed_states'  s8    /2(7:	< 	< 	< 	< 	<r    c                 f    t          | j        j        d         | j        j        d                    d S r   )r   r   rk   r   r#   s    r   r   z-TestLargeStateCovAR1.test_smoothed_states_cov+  s=    3D9(;DA	C 	C 	C 	C 	Cr    c                     t          | j        j        d         | j        j        d                    t          | j        j        d         d           d S )Nr   rI   )r   r   r   r   r#   s    r   r   z4TestLargeStateCovAR1.test_smoothed_state_disturbance/  sQ    ;A>(CAF	H 	H 	H;A>BBBBBr    c                     t          | j        j        d         | j        j        d                    t          | j        j        d         d           d S )Nr   )rI   rI   r   )r   r   rl   r   r   r#   s    r   r   z8TestLargeStateCovAR1.test_smoothed_state_disturbance_cov4  sQ    ?E(GM	O 	O 	O;DA1EEEEEr    c                 N    t          | j        j        | j        j                   d S r   )r   r   r   r   r#   s    r   r   z:TestLargeStateCovAR1.test_smoothed_measurement_disturbance9  s3    A(I	K 	K 	K 	K 	Kr    c                 N    t          | j        j        | j        j                   d S r   )r   r   r   r   r#   s    r   r   z>TestLargeStateCovAR1.test_smoothed_measurement_disturbance_cov=  s3    E(M	O 	O 	O 	O 	Or    N)r0   r1   r2   r   rt   r   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r    r   r   r      s.       % % [%*  D D DG G GK K KH H H: : :> > >= = =D D D< < <C C CC C C
F F F
K K KO O O O Or    r   )r3   numpyr   pandasrQ   rO   r   statsmodels.tsa.statespacer   r   statsmodelsr   numpy.testingr   r   r   ro   dirnameabspath__file__rN   MLEModelr
   r8   r   r   r   r"   r    r   <module>r      s            				  8 8 8 8 8 8 8 8             F F F F F F F F F Fwrwx8899- - - - -" - - -@L
 L
 L
 L
 L
 L
 L
 L
^, , , , ,x( , , ,@? ? ?WO WO WO WO WO WO WO WO WO WOr    