<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> def infer_net_from_xcorr ( S , dtmax , smooth = None ) : <EOL> if smooth is not None : <EOL> S = _moving_average ( S , window = smooth , axis = <NUM_LIT:0> ) <EOL> H = xcorr ( S , dtmax ) <EOL> H_sum = np . sum ( np . abs ( H ) , axis = <NUM_LIT:2> ) <EOL> return H_sum <EOL> def xcorr ( S , dtmax = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> ( T , N ) = S . shape <EOL> H = np . zeros ( ( N , N , dtmax ) ) <EOL> for dt in np . arange ( dtmax ) : <EOL> chunksz = <NUM_LIT:16> <EOL> for n1 in np . arange ( N , step = chunksz ) : <EOL> for n2 in np . arange ( N , step = chunksz ) : <EOL> n1c = min ( n1 + chunksz , N ) <EOL> n2c = min ( n2 + chunksz , N ) <EOL> H [ n1 : n1c , n2 : n2c , dt ] = np . corrcoef ( S [ : T - dt , n1 : n1c ] . T , <EOL> S [ dt : , n2 : n2c ] . T ) [ : ( n1c - n1 ) , ( n1c - n1 ) : ] <EOL> if dt == <NUM_LIT:0> : <EOL> H [ : , : , <NUM_LIT:0> ] = H [ : , : , <NUM_LIT:0> ] - np . diag ( np . diag ( H [ : , : , <NUM_LIT:0> ] ) ) <EOL> return H <EOL> def _moving_average ( a , axis = <NUM_LIT:0> , window = <NUM_LIT:10> ) : <EOL> ret = np . cumsum ( a , dtype = np . float64 , axis = axis ) <EOL> ret [ window : ] = ret [ window : ] - ret [ : - window ] <EOL> return ret [ window - <NUM_LIT:1> : ] / window </s>
