
    M/Ph)                     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                 X   d}d} 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)super__init__npeyeinitialize_approximate_diffuseselfendogkwargsr   r   	__class__s        l/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/statespace/tests/test_models.pyr   zIntercepts.__init__   s    	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                 p     t                      j        |fi |}|d d         | d<   |dd          | d<   d S )Nr   obs_interceptstate_interceptr   updater   paramsr   r   s      r   r-   zIntercepts.update.   sK    11&11 &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   r:      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TrT   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`   rc   r   rT   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   rT   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   rT   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diagonalrT   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 )NrJ   )a1a2a3)r   r`   predicted_stater   rT   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`   rd   r   rT   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   rT   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`   re   r   rT   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   rT   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   rT   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`   rf   r   rT   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   rT   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   rT   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)r:   )r1   r2   r3   classmethodru   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r    r   r9   r9   5   s       3J 3J 3J [3JjF F F
 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 
 
 
r    r9   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                      j        |f||d| d| d<   d| d<   d| d<   |                                  d S )NrJ   rM   r   )r   r   r   )r   r   r   )r   rJ   rJ   )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      ?rJ   r"   r#   s    r   r(   zLargeStateCovAR1.start_params   s    Qxr    c                 h     t                      j        |fi |}|d         | d<   |d         | d<   d S )Nr   )r   r   r   rJ   )r   r   r   r,   r.   s      r   r-   zLargeStateCovAR1.update   sD    11&11#)!9 "()r    r0   r7   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   rJ   )pytestskipr   SARIMAXr_   res_desiredr   res)rn   r   r/   mod_desiredrs   s        r   ru   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 )NrJ   rM   )rM   r   )rJ   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   rx   r   r#   s    r   ry   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   rj   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   rk   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   rl   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   rJ   )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   )rJ   rJ   r   )r   r   rm   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)r1   r2   r3   r   ru   r   ry   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   )r4   numpyr   pandasrR   rP   r   statsmodels.tsa.statespacer   r   statsmodelsr   numpy.testingr   r   r   rp   dirnameabspath__file__rO   MLEModelr
   r9   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    