
    !g"                         d Z ddlZddl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ZddZdd	Z	 	 dd
Zd Zd Zd Zy)zQ
Tests for Chandrasekhar recursions

Author: Chad Fulton
License: Simplified-BSD
    N   )results_varmax)sarimaxvarmax)MEMORY_CONSERVEMEMORY_NO_LIKELIHOOD)assert_allclosec                    |j                   }t        | j                  |j                         t        | j                  j	                  |      |j                  j	                  |      dd       | j                  j
                  j                  D ]<  }|dk(  r	t        t        | j                  |      t        |j                  |             > g d}|s|dgz  }|D ]<  }t        | j                  |      }t        |j                  |      }t        ||d       > d	d
g}|s|g dz  }|D ]<  }t        | j                  |      }t        |j                  |      }t        ||d       > |sEg d}	|	D ]<  }t        | j                  |      }t        |j                  |      }t        ||d       > | j                  j                  }
|s/| j                  d|
dz   d      }| j                  d|
dz   d      }n,| j                  d|
dz         }| j                  d|
dz         }t        |j                  |j                         t        |j                  |j                         y )Ng-C6
?gh㈵>)rtolatolobs)predicted_statefiltered_state	forecastsforecasts_errorkalman_gaing-q=)r   predicted_state_covfiltered_state_cov)standardized_forecasts_errortmp1tmp2tmp3tmp4)smoothed_statesmoothed_state_covsmoothed_state_autocovsmoothed_state_disturbancesmoothed_state_disturbance_cov smoothed_measurement_disturbance$smoothed_measurement_disturbance_covscaled_smoothed_estimatorscaled_smoothed_estimator_covsmoothing_errorsmoothed_forecastssmoothed_forecasts_errorsmoothed_forecasts_error_cov
   2   (   )startenddynamic)r*   r+   )paramsr	   llfmodel	score_obsssmshapesgetattrfilter_resultsnobsget_predictionpredicted_meanse_mean)	res_chandres_origmemory_conserver-   namefilter_attractualdesiredfilter_attr_burnsmoothed_attrr5   
pred_chand	pred_origs                p/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/tsa/statespace/tests/test_chandrasekhar.pycheck_outputrE      s_   __FIMM8<<0!!&)  (	 ##** @5=	 8 8$? 7 7>	@@&K & 51148(1148e45
 ./CD    	  ! 51148(1148e45
 	9 " 	9DY55t<Fh55t<GFG%8	9 ??D--BD2I68 . :
,,24"957 - 9	 --BD2I-F
,,24"9,E	J--y/G/GHJ&&	(9(9:    c                    t        j                  ddd      }t        j                  t        j                  g d|      }t        j                  |d         j                         j                  dd	 }t        j                  |fi |}t        j                  |fi |}d
|j                  _        |j                  }| |j                  _        | |j                  _        |j                  |      }|j                  |      }	t!        ||	       y )N
1960-01-01
1982-10-01QSfreqinvincconsumpcolumnsindexrN   
1960-04-01
1978-10-01T)pd
date_range	DataFramer   lutkepohl_datanplogdifflocr   SARIMAXr1   filter_chandrasekharstart_paramsfilter_univariatesmoothrE   )
ra   kwargsrS   dtaendogmod_orig	mod_chandr-   r9   r:   s
             rD   check_univariate_chandrasekharrh   ^   s    MM,4@E
,,~448GCFF3u:##%)),|DEu//H00I)-IMM&""F%6HLL"&7IMM#  (I v&HH%rF   c                 <   t        j                  ddd      }t        j                  t        j                  g d|      }t        j                  |d         j                         |d<   t        j                  |d	         j                         |d
<   t        j                  |d         j                         |d<   |j                  dddd
gf   }t        j                  |fi |}t        j                  |fi |}d|j                  _        |j                  }	| |j                  _        | |j                  _        |r<t        j                  ddgddgg      |d<   t        j                  ddgddgg      |d<   |rq|j                  j!                  t"        t$         z         |j                  j!                  t"        t$         z         |j'                  |	      }
|j'                  |	      }n"|j)                  |	      }
|j)                  |	      }t+        |
||       y )NrH   rI   rJ   rK   rM   rQ   rN   dln_invrO   dln_incrP   dln_consumprT   rU   T      ?      ?obs_cov)r;   )rV   rW   rX   r   rY   rZ   r[   r\   r]   r   VARMAXr1   r_   r`   ra   arrayset_conserve_memoryr   r   filterrb   rE   )ra   gen_obs_covr;   rc   rS   rd   re   rf   rg   r-   r9   r:   s               rD    check_multivariate_chandrasekharru   v   s    MM,4@E
,,~448GCVVCJ',,.C	NVVCJ',,.C	NI/446CGGL-	9/EEFE}}U-f-He.v.I)-IMM&""F%6HLL"&7IMM# hhS	),b	(3 4!xx"c),b	)3  4	) (( 444	6)) 444	6 $$V,	??6*$$V,	??6*HoFrF   c                      t        d       t        dd       t        d       t        dd       t        dd       t        dd       t        ddd	       y )
NFra   Tra   concentrate_scalera   measurement_errordiagonalra   error_cov_typera   rt   ra   rt   r;   rh   ru    rF   rD   test_chandrasekhar_conventionalr      sY    "U;"U59; %u=$u7;=$u4>@$u157$u15tMrF   c                      t        d       t        dd       t        d       t        dd       t        dd       t        dd       t        ddd       y )	NTrw   rx   rz   r|   r}   r   r   r   r   rF   rD   test_chandrasekhar_univariater      sY    "T:"T59; %t<$t7;=$t4>@$t157$t15tMrF   c                  r   t        j                  d      } t         j                  | d<   t        j                  |       }d|j
                  _        t        j                  t        d      5  |j                  ddg       d d d        t        j                  d      } t        j                  |       }d|j
                  _        d|j
                  _        t        j                  t        d      5  |j                  ddg       d d d        t        j                  d      } t        j                  |       }d|j
                  _        t        j                  d	      |d
<   t        j                  t        d      5  |j                  ddg       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr'   r   Tz6Cannot use Chandrasekhar recursions with missing data.)matchrn   rm   z9Cannot use Chandrasekhar recursions with filtered timing.)r   r   r'   ro   zeCannot use Chandrasekhar recursions with time-varying system matrices \(except for intercept terms\).)rZ   zerosnanr   r^   r1   r_   pytestraisesRuntimeErrorrs   timing_init_filteredones)re   mods     rD   test_invalidr      s]   
 HHRLEvvE!H
//%
 C#'CGG 	| -M 
O 

C:
 HHRLE
//%
 C#'CGG #'CGG 	| -7 
9  	

C: HHRLE
//%
 C#'CGG WWZ(C	N	| -C 
E  	

C:	 '   s$   *F-F!7F-F!F*-F6)F)FFF)__doc__numpyrZ   pandasrV   resultsr   statsmodels.tsa.statespacer   r   (statsmodels.tsa.statespace.kalman_filterr   r   numpy.testingr	   r   rE   rh   ru   r   r   r   r   rF   rD   <module>r      sO      # 6+ ) H;V&0 8=HM(GVM M  rF   