#NEWLINE# def jackknifed_coh_variance( tx , ty , eigvals , adaptive = True ) : #NEWLINE# #INDENT# '\n    Returns the variance of the coherency between x and y, estimated\n    through jack-knifing the tapered samples in {tx, ty}.\n\n    Parameters\n    ----------\n\n    tx : ndarray, (K, L)\n       The K complex spectra of tapered timeseries x\n    ty : ndarray, (K, L)\n       The K complex spectra of tapered timeseries y\n    eigvals : ndarray (K,)\n       The eigenvalues associated with the K DPSS tapers\n\n    Returns\n    -------\n\n    jk_var : ndarray\n       The variance computed in the transformed domain (see\n       normalize_coherence)\n    ' #NEWLINE# K = tx . shape [ 0 ] #NEWLINE# jk_coh = [ ] #NEWLINE# sides = 'onesided' #NEWLINE# all_orders = set ( range ( K ) ) #NEWLINE# import nitime.algorithms as alg #NEWLINE# for i in range ( K ) : #NEWLINE# #INDENT# items = list ( all_orders . difference ( [ i ] ) ) #NEWLINE# tx_i = np . take ( tx , items , axis = 0 ) #NEWLINE# ty_i = np . take ( ty , items , axis = 0 ) #NEWLINE# eigs_i = np . take ( eigvals , items ) #NEWLINE# if adaptive : #NEWLINE# #INDENT# ( wx , _ ) = adaptive_weights ( tx_i , eigs_i , sides = sides ) #NEWLINE# ( wy , _ ) = adaptive_weights ( ty_i , eigs_i , sides = sides ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# wx = wy = eigs_i [ : , None ] #NEWLINE# #UNINDENT# sxy_i = alg . mtm_cross_spectrum ( tx_i , ty_i , ( wx , wy ) , sides = sides ) #NEWLINE# sxx_i = alg . mtm_cross_spectrum ( tx_i , tx_i , wx , sides = sides ) #NEWLINE# syy_i = alg . mtm_cross_spectrum ( ty_i , ty_i , wy , sides = sides ) #NEWLINE# msc = np . abs ( sxy_i ) #NEWLINE# msc /= np . sqrt ( ( sxx_i * syy_i ) ) #NEWLINE# jk_coh . append ( msc ) #NEWLINE# #UNINDENT# jk_coh = np . array ( jk_coh ) #NEWLINE# normalize_coherence ( jk_coh , ( ( 2 * K ) - 2 ) , copy = False ) #NEWLINE# jk_avg = np . mean ( jk_coh , axis = 0 ) #NEWLINE# jk_var = ( jk_coh - jk_avg ) #NEWLINE# np . power ( jk_var , 2 , jk_var ) #NEWLINE# jk_var = jk_var . sum ( axis = 0 ) #NEWLINE# f = ( float ( ( K - 1 ) ) / K ) #NEWLINE# jk_var *= f #NEWLINE# return jk_var