def test_range(self):
     '''Test the ranged version of ``corr``.'''
     # Half the range of both signals
     for a1, a2 in _data_generator(self.maxLoops, self.maxN):
         if a1.size <= 1 or a2.size <= 1:
             continue
         lag_start = - (a1.size // 2)
         lag_end = a2.size // 2
         c_np_centre = a1.size - 1
         c_cpp = asignal.corr(a1, a2, mode='range', lag_start=lag_start,
                              lag_end=lag_end)
         c_np = np.correlate(a1, a2, mode='full')[::-1]
         np.testing.assert_allclose(
             c_cpp,
             c_np[c_np_centre + lag_start:c_np_centre + lag_end + 1],
             rtol=RTOL)
Exemplo n.º 2
0
    def extractCCStat(self, mon, out):
        '''
        Extract x-correlation statistics from a monitor.

        For each pair of monitored neurons
        Parameters
        ----------
        mon : list of dicts
            A list of (NEST) state monitors' status dictionaries
        out : dictionary
            Output data dictionary.
        '''
        out['x-corr'] = dict(correlations=[])
        xcOut = out['x-corr']['correlations']
        for n_id1 in range(len(mon)):
            sig1, dt1 = simei.sumAllVariables(mon, n_id1, self.stateList)
            xcOut.append([])
            xcOut2 = xcOut[n_id1]
            for n_id2 in range(len(mon)):
                cc_logger.debug('n_id1, n_id2 = {0}, {1}'.format(n_id1, n_id2))
                sig2, dt2 = simei.sumAllVariables(mon, n_id2, self.stateList)
                if (dt1 != dt2):
                    raise ValueError('dt1 != dt2')

                dt = dt1
                startIdx = 0
                lag_start = -int(self.maxLag / dt)
                lag_end = -lag_start
                endIdx1 = len(sig1)
                endIdx2 = len(sig2)

                if (self.tStart is not None):
                    startIdx = int(self.tStart / dt)
                if (self.tEnd is not None):
                    endIdx1 = int(self.tEnd / dt)
                    endIdx2 = endIdx1
                sig1 = sig1[startIdx:endIdx1]
                sig2 = sig2[startIdx:endIdx2]
                C = corr(sig1,
                         sig2,
                         mode='range',
                         lag_start=lag_start,
                         lag_end=lag_end)
                if (self.norm):
                    C /= np.max(C)
                xcOut2.append(C)
        out['x-corr']['lags'] = np.arange(lag_start, lag_end + 1) * dt
Exemplo n.º 3
0
    def extractCCStat(self, mon, out):
        '''Extract x-correlation statistics from a monitor.

        This is done for each pair of monitored neurons

        Parameters
        ----------
        mon : list of dicts
            A list of (NEST) state monitors' status dictionaries
        out : dictionary
            Output data dictionary.
        '''
        out['x-corr'] = dict(
                correlations=[])
        xcOut = out['x-corr']['correlations']
        for n_id1 in range(len(mon)):
            sig1, dt1 = simei.sumAllVariables(mon, n_id1, self.stateList)
            xcOut.append([])
            xcOut2 = xcOut[n_id1]
            for n_id2 in range(len(mon)):
                cc_logger.debug('n_id1, n_id2 = {0}, {1}'.format(n_id1, n_id2))
                sig2, dt2 = simei.sumAllVariables(mon, n_id2, self.stateList)
                if (dt1 != dt2):
                    raise ValueError('dt1 != dt2')

                dt        = dt1
                startIdx  = 0
                lag_start = -int(self.maxLag/dt)
                lag_end   = -lag_start
                endIdx1   = len(sig1)
                endIdx2   = len(sig2)

                if (self.tStart is not None):
                    startIdx = int(self.tStart / dt)
                if (self.tEnd is not None):
                    endIdx1 = int(self.tEnd / dt)
                    endIdx2 = endIdx1
                sig1 = sig1[startIdx:endIdx1]
                sig2 = sig2[startIdx:endIdx2]
                C = corr(sig1, sig2, mode='range', lag_start=lag_start,
                         lag_end=lag_end)
                if (self.norm):
                    C /= np.max(C)
                xcOut2.append(C)
        out['x-corr']['lags'] = np.arange(lag_start, lag_end+1) * dt
 def test_range(self):
     '''Test the ranged version of ``corr``.'''
     # Half the range of both signals
     for a1, a2 in _data_generator(self.maxLoops, self.maxN):
         if a1.size <= 1 or a2.size <= 1:
             continue
         lag_start = -(a1.size // 2)
         lag_end = a2.size // 2
         c_np_centre = a1.size - 1
         c_cpp = asignal.corr(a1,
                              a2,
                              mode='range',
                              lag_start=lag_start,
                              lag_end=lag_end)
         c_np = np.correlate(a1, a2, mode='full')[::-1]
         np.testing.assert_allclose(
             c_cpp,
             c_np[c_np_centre + lag_start:c_np_centre + lag_end + 1],
             rtol=RTOL)
    def test_zero_len(self):
        '''Test that an exception is raised when inputs have zero length.'''
        a1 = np.array([])
        a2 = np.arange(10)

        # corr(a1, a2)
        lag_start = 0
        lag_end   = 0
        for mode in ("onesided", "twosided", "range"):
            with pytest.raises(TypeError):
                asignal.corr(a1, a2, mode, lag_start, lag_end)
            with pytest.raises(TypeError):
                asignal.corr(a2, a1, mode, lag_start, lag_end)
            with pytest.raises(TypeError):
                asignal.corr(a1, a1, mode, lag_start, lag_end)
    def test_zero_len(self):
        '''Test that an exception is raised when inputs have zero length.'''
        a1 = np.array([])
        a2 = np.arange(10)

        # corr(a1, a2)
        lag_start = 0
        lag_end = 0
        for mode in ("onesided", "twosided", "range"):
            with pytest.raises(TypeError):
                asignal.corr(a1, a2, mode, lag_start, lag_end)
            with pytest.raises(TypeError):
                asignal.corr(a2, a1, mode, lag_start, lag_end)
            with pytest.raises(TypeError):
                asignal.corr(a1, a1, mode, lag_start, lag_end)
 def test_non_double(self):
     '''Test the corr function when dtype is not double.'''
     a1 = np.array([1, 2, 3], dtype=int)
     asignal.corr(a1, a1, mode='twosided')
 def test_twosided(self):
     '''Test the two-sided version of ``corr``.'''
     for a1, a2 in _data_generator(self.maxLoops, self.maxN):
         c_cpp = asignal.corr(a1, a2, mode='twosided')
         c_np = np.correlate(a1, a2, mode='full')[::-1]
         np.testing.assert_allclose(c_cpp, c_np, rtol=RTOL)
 def test_non_double(self):
     '''Test the corr function when dtype is not double.'''
     a1 = np.array([1, 2, 3], dtype=int)
     asignal.corr(a1, a1, mode='twosided')
Exemplo n.º 10
0
 def test_twosided(self):
     '''Test the two-sided version of ``corr``.'''
     for a1, a2 in _data_generator(self.maxLoops, self.maxN):
         c_cpp = asignal.corr(a1, a2, mode='twosided')
         c_np = np.correlate(a1, a2, mode='full')[::-1]
         np.testing.assert_allclose(c_cpp, c_np, rtol=RTOL)