<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> import logging <EOL> log = logging . getLogger ( "<STR_LIT>" ) <EOL> def sampleInhomogeneousPoissonProc ( tt , lam ) : <EOL> """<STR_LIT>""" <EOL> N_t = len ( tt ) <EOL> dt = np . diff ( tt ) <EOL> dlam = np . diff ( lam ) <EOL> trapLam = <NUM_LIT:0.5> * dt * ( <NUM_LIT:2> * lam [ <NUM_LIT:1> : ] - dlam ) <EOL> cumLam = np . ravel ( np . cumsum ( trapLam ) ) <EOL> cumLam = np . hstack ( ( np . array ( [ <NUM_LIT:0.0> ] ) , cumLam ) ) <EOL> intLam = cumLam [ - <NUM_LIT:1> ] <EOL> N = np . random . poisson ( intLam ) <EOL> Q = np . random . uniform ( <NUM_LIT:0> , intLam , size = N ) <EOL> Q = np . sort ( Q ) <EOL> S = np . zeros ( N ) <EOL> tt_off = <NUM_LIT:0> <EOL> for ( n , q ) in enumerate ( Q ) : <EOL> while q > cumLam [ tt_off ] : <EOL> tt_off += <NUM_LIT:1> <EOL> assert tt_off < N_t , "<STR_LIT>" <EOL> q_lb = cumLam [ tt_off - <NUM_LIT:1> ] <EOL> q_ub = cumLam [ tt_off ] <EOL> q_frac = ( q - q_lb ) / ( q_ub - q_lb ) <EOL> assert q_frac >= <NUM_LIT:0.0> and q_frac <= <NUM_LIT:1.0> , "<STR_LIT>" <EOL> tt_lb = tt [ tt_off - <NUM_LIT:1> ] <EOL> tt_ub = tt [ tt_off ] <EOL> S [ n ] = tt_lb + q_frac * ( tt_ub - tt_lb ) <EOL> return S <EOL> def approximateFiringRate ( S , ( T_start , T_stop ) , N_bins ) : <EOL> """<STR_LIT>""" <EOL> bin_edges = np . linspace ( T_start , T_stop , N_bins + <NUM_LIT:1> ) <EOL> bin_width = ( T_stop - T_start ) / N_bins <EOL> fr = np . histogram ( S , bin_edges , range = ( T_start , T_stop ) ) [ <NUM_LIT:0> ] / bin_width <EOL> N_smoothing_kernel_bins = <NUM_LIT:9> <EOL> smoothing_kernel_bin_centers = np . linspace ( - ( N_smoothing_kernel_bins - <NUM_LIT:1> ) / <NUM_LIT:2> * bin_width , <EOL> ( N_smoothing_kernel_bins - <NUM_LIT:1> ) / <NUM_LIT:2> * bin_width , <EOL> N_smoothing_kernel_bins <EOL> ) <EOL> smoothing_kernel = np . exp ( - <NUM_LIT:0.5> * smoothing_kernel_bin_centers ** <NUM_LIT:2> ) <EOL> smoothing_kernel = smoothing_kernel / np . sum ( smoothing_kernel ) <EOL> l_pad = np . mean ( fr [ : N_smoothing_kernel_bins ] ) <EOL> r_pad = np . mean ( fr [ - N_smoothing_kernel_bins : ] ) <EOL> fr_pad = np . hstack ( ( l_pad * np . ones ( N_smoothing_kernel_bins ) , fr , r_pad * np . ones ( N_smoothing_kernel_bins ) ) ) <EOL> fr_smooth = np . convolve ( fr_pad , smoothing_kernel , "<STR_LIT>" ) <EOL> fr_smooth = fr_smooth [ N_smoothing_kernel_bins : - N_smoothing_kernel_bins ] <EOL> assert np . size ( fr_smooth ) == N_bins , "<STR_LIT>" <EOL> return fr_smooth </s>
