def test_norm(self): '''Test normalization.''' # Simple array a = np.arange(10) c_cpp = asignal.acorr(a, mode='twosided', norm=True) c_np = np.correlate(a, a, mode='full')[::-1] np.testing.assert_allclose(c_cpp, c_np / np.max(c_np), rtol=RTOL) # A zero array will return zero zero_array = np.zeros(13) c_cpp = asignal.acorr(zero_array, mode='twosided', norm=True) assert np.all(c_cpp == 0.)
def extractACStat(self, mon): ''' Extract autocorrelation statistics from a monitor. For each monitored neuron, extract the (highest) frequency, value of the autocorrelation at the frequency and the autocorrelation function itself. Parameters ---------- mon : list of dicts A list of (NEST) state monitors' status dictionaries output : tuple A tuple (freq, acval, acVec), containing the arrays of frequencies for the monitored neurons, autocorrelation values at the corresponding frequencies, and autocorrelation functions of all the neurons. ''' freq = [] # Frequency of input signal acval = [] # Auto-correlation at the corresponding frequency acVec = [] for n_id in range(len(mon)): #for n_id in range(5): #print "n_id: ", n_id sig, dt = simei.sumAllVariables(mon, n_id, self.stateList) startIdx = 0 endIdx = len(sig) if (self.tStart is not None): startIdx = int(self.tStart / dt) if (self.tEnd is not None): endIdx = int(self.tEnd / dt) sig = sig[startIdx:endIdx] sig = butterBandPass(sig, dt * self.dtMult, self.bandStart, self.bandEnd) ac = acorr(sig - np.mean(sig), max_lag=self.maxLag / dt, norm=self.norm) ext_idx, ext_t = localExtrema(ac) acVec.append(ac) f, a = findFreq(ac, dt * self.dtMult, ext_idx, ext_t) freq.append(f) acval.append(a) return freq, acval, acVec, dt
def extractACStat(self, mon): ''' Extract autocorrelation statistics from a monitor. For each monitored neuron, extract the (highest) frequency, value of the autocorrelation at the frequency and the autocorrelation function itself. Parameters ---------- mon : list of dicts A list of (NEST) state monitors' status dictionaries output : tuple A tuple (freq, acval, acVec), containing the arrays of frequencies for the monitored neurons, autocorrelation values at the corresponding frequencies, and autocorrelation functions of all the neurons. ''' freq = [] # Frequency of input signal acval = [] # Auto-correlation at the corresponding frequency acVec = [] for n_id in range(len(mon)): #for n_id in range(5): #print "n_id: ", n_id sig, dt = simei.sumAllVariables(mon, n_id, self.stateList) startIdx = 0 endIdx = len(sig) if (self.tStart is not None): startIdx = int(self.tStart / dt) if (self.tEnd is not None): endIdx = int(self.tEnd / dt) sig = sig[startIdx:endIdx] sig = butterBandPass(sig, dt*self.dtMult, self.bandStart, self.bandEnd) ac = acorr(sig - np.mean(sig), max_lag=self.maxLag/dt, norm=self.norm) ext_idx, ext_t = localExtrema(ac) acVec.append(ac) f, a = findFreq(ac, dt*self.dtMult, ext_idx, ext_t) freq.append(f) acval.append(a) return freq, acval, acVec, dt
def test_default_params(self): '''Test default parameters.''' a = np.arange(10) c_cpp = asignal.acorr(a) c_np = np.correlate(a, a, mode='full')[::-1][a.size - 1:] np.testing.assert_allclose(c_cpp, c_np, rtol=RTOL)
def test_twosided(self): '''Test the two-sided version of ``corr``.''' a = np.arange(10) c_cpp = asignal.acorr(a, mode='twosided', max_lag=5) c_np = np.correlate(a, a, mode='full')[::-1][a.size - 6:a.size + 5] np.testing.assert_allclose(c_cpp, c_np, rtol=RTOL)