#NEWLINE# def __next__( self ) : #NEWLINE# #INDENT# if ( not ( self . t >= 0 ) ) : #NEWLINE# #INDENT# raise StopIteration #NEWLINE# #UNINDENT# t = self . t #NEWLINE# kfilter = self . kfilter #NEWLINE# _kfilter = self . _kfilter #NEWLINE# model = self . model #NEWLINE# smoother_output = self . smoother_output #NEWLINE# scaled_smoothed_estimator = self . scaled_smoothed_estimator #NEWLINE# scaled_smoothed_estimator_cov = self . scaled_smoothed_estimator_cov #NEWLINE# smoothing_error = self . smoothing_error #NEWLINE# smoothed_state = self . smoothed_state #NEWLINE# smoothed_state_cov = self . smoothed_state_cov #NEWLINE# smoothed_state_disturbance = self . smoothed_state_disturbance #NEWLINE# smoothed_state_disturbance_cov = self . smoothed_state_disturbance_cov #NEWLINE# smoothed_measurement_disturbance = self . smoothed_measurement_disturbance #NEWLINE# smoothed_measurement_disturbance_cov = self . smoothed_measurement_disturbance_cov #NEWLINE# tmp_L = self . tmp_L #NEWLINE# _kfilter . seek ( t , False ) #NEWLINE# _kfilter . initialize_statespace_object_pointers ( ) #NEWLINE# _kfilter . initialize_filter_object_pointers ( ) #NEWLINE# _kfilter . select_missing ( ) #NEWLINE# missing_entire_obs = ( _kfilter . model . nmissing [ t ] == _kfilter . model . k_endog ) #NEWLINE# missing_partial_obs = ( ( not missing_entire_obs ) and ( _kfilter . model . nmissing [ t ] > 0 ) ) #NEWLINE# design_t = ( 0 if ( kfilter . design . shape [ 2 ] == 1 ) else t ) #NEWLINE# obs_cov_t = ( 0 if ( kfilter . obs_cov . shape [ 2 ] == 1 ) else t ) #NEWLINE# transition_t = ( 0 if ( kfilter . transition . shape [ 2 ] == 1 ) else t ) #NEWLINE# selection_t = ( 0 if ( kfilter . selection . shape [ 2 ] == 1 ) else t ) #NEWLINE# state_cov_t = ( 0 if ( kfilter . state_cov . shape [ 2 ] == 1 ) else t ) #NEWLINE# k_endog = _kfilter . k_endog #NEWLINE# transition = model . transition [ : , : , transition_t ] #NEWLINE# selection = model . selection [ : , : , selection_t ] #NEWLINE# state_cov = model . state_cov [ : , : , state_cov_t ] #NEWLINE# predicted_state = kfilter . predicted_state [ : , t ] #NEWLINE# predicted_state_cov = kfilter . predicted_state_cov [ : , : , t ] #NEWLINE# mask = ( ~ kfilter . missing [ : , t ] . astype ( bool ) ) #NEWLINE# if missing_partial_obs : #NEWLINE# #INDENT# design = np . array ( _kfilter . selected_design [ : ( k_endog * model . k_states ) ] , copy = True ) . reshape ( k_endog , model . k_states , order = 'F' ) #NEWLINE# obs_cov = np . array ( _kfilter . selected_obs_cov [ : ( k_endog ** 2 ) ] , copy = True ) . reshape ( k_endog , k_endog ) #NEWLINE# kalman_gain = kfilter . kalman_gain [ : , mask , t ] #NEWLINE# forecasts_error_cov = np . array ( _kfilter . forecast_error_cov [ : , : , t ] , copy = True ) . ravel ( order = 'F' ) [ : ( k_endog ** 2 ) ] . reshape ( k_endog , k_endog ) #NEWLINE# forecasts_error = np . array ( _kfilter . forecast_error [ : k_endog , t ] , copy = True ) #NEWLINE# F_inv = np . linalg . inv ( forecasts_error_cov ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if missing_entire_obs : #NEWLINE# #INDENT# design = np . zeros ( model . design . shape [ : ( - 1 ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# design = model . design [ : , : , design_t ] #NEWLINE# #UNINDENT# obs_cov = model . obs_cov [ : , : , obs_cov_t ] #NEWLINE# kalman_gain = kfilter . kalman_gain [ : , : , t ] #NEWLINE# forecasts_error_cov = kfilter . forecasts_error_cov [ : , : , t ] #NEWLINE# forecasts_error = kfilter . forecasts_error [ : , t ] #NEWLINE# F_inv = np . linalg . inv ( forecasts_error_cov ) #NEWLINE# #UNINDENT# tmp_L [ : , : , t ] = ( transition - kalman_gain . dot ( design ) ) #NEWLINE# L = tmp_L [ : , : , t ] #NEWLINE# if ( smoother_output & ( SMOOTHER_STATE | SMOOTHER_DISTURBANCE ) ) : #NEWLINE# #INDENT# if missing_entire_obs : #NEWLINE# #INDENT# scaled_smoothed_estimator [ : , ( t - 1 ) ] = transition . transpose ( ) . dot ( scaled_smoothed_estimator [ : , t ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# smoothing_error [ : k_endog , t ] = ( F_inv . dot ( forecasts_error ) - kalman_gain . transpose ( ) . dot ( scaled_smoothed_estimator [ : , t ] ) ) #NEWLINE# scaled_smoothed_estimator [ : , ( t - 1 ) ] = ( design . transpose ( ) . dot ( smoothing_error [ : k_endog , t ] ) + transition . transpose ( ) . dot ( scaled_smoothed_estimator [ : , t ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( smoother_output & ( SMOOTHER_STATE_COV | SMOOTHER_DISTURBANCE_COV ) ) : #NEWLINE# #INDENT# if missing_entire_obs : #NEWLINE# #INDENT# scaled_smoothed_estimator_cov [ : , : , ( t - 1 ) ] = L . transpose ( ) . dot ( scaled_smoothed_estimator_cov [ : , : , t ] ) . dot ( L ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# scaled_smoothed_estimator_cov [ : , : , ( t - 1 ) ] = ( design . transpose ( ) . dot ( F_inv ) . dot ( design ) + L . transpose ( ) . dot ( scaled_smoothed_estimator_cov [ : , : , t ] ) . dot ( L ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( smoother_output & SMOOTHER_STATE ) : #NEWLINE# #INDENT# smoothed_state [ : , t ] = ( predicted_state + predicted_state_cov . dot ( scaled_smoothed_estimator [ : , ( t - 1 ) ] ) ) #NEWLINE# #UNINDENT# if ( smoother_output & SMOOTHER_STATE_COV ) : #NEWLINE# #INDENT# smoothed_state_cov [ : , : , t ] = ( predicted_state_cov - predicted_state_cov . dot ( scaled_smoothed_estimator_cov [ : , : , ( t - 1 ) ] ) . dot ( predicted_state_cov ) ) #NEWLINE# #UNINDENT# if ( smoother_output & ( SMOOTHER_DISTURBANCE | SMOOTHER_DISTURBANCE_COV ) ) : #NEWLINE# #INDENT# QR = state_cov . dot ( selection . transpose ( ) ) #NEWLINE# #UNINDENT# if ( smoother_output & SMOOTHER_DISTURBANCE ) : #NEWLINE# #INDENT# smoothed_state_disturbance [ : , t ] = QR . dot ( scaled_smoothed_estimator [ : , t ] ) #NEWLINE# if ( not missing_entire_obs ) : #NEWLINE# #INDENT# smoothed_measurement_disturbance [ ( mask , t ) ] = obs_cov . dot ( smoothing_error [ : k_endog , t ] ) #NEWLINE# #UNINDENT# #UNINDENT# if ( smoother_output & SMOOTHER_DISTURBANCE_COV ) : #NEWLINE# #INDENT# smoothed_state_disturbance_cov [ : , : , t ] = ( state_cov - QR . dot ( scaled_smoothed_estimator_cov [ : , : , t ] ) . dot ( QR . transpose ( ) ) ) #NEWLINE# if missing_entire_obs : #NEWLINE# #INDENT# smoothed_measurement_disturbance_cov [ : , : , t ] = obs_cov #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ix = np . ix_ ( mask , mask , [ t ] ) #NEWLINE# smoothed_measurement_disturbance_cov [ ix ] = ( obs_cov - obs_cov . dot ( ( F_inv + kalman_gain . transpose ( ) . dot ( scaled_smoothed_estimator_cov [ : , : , t ] ) . dot ( kalman_gain ) ) ) . dot ( obs_cov ) ) [ : , : , np . newaxis ] #NEWLINE# ix = np . ix_ ( ( ~ mask ) , ( ~ mask ) , [ t ] ) #NEWLINE# mod_ix = np . ix_ ( ( ~ mask ) , ( ~ mask ) , [ 0 ] ) #NEWLINE# smoothed_measurement_disturbance_cov [ ix ] = np . copy ( model . obs_cov [ : , : , obs_cov_t : ( obs_cov_t + 1 ) ] ) [ mod_ix ] #NEWLINE# #UNINDENT# #UNINDENT# self . t -= 1