示例#1
0
 def test_fit(self):
     """Test function fit."""
     data = np.random.rand(100, 1000)
     p = EventRelatedPac()
     pha = p.filter(256, data, 'phase')
     amp = p.filter(256, data, 'amplitude')
     p.fit(pha, amp, method='circular')
     p.fit(pha, amp, method='gc')
示例#2
0
 def test_fit(self):
     """Test function fit."""
     data = np.random.rand(100, 1000)
     p = EventRelatedPac()
     pha = p.filter(256, data, 'phase')
     amp = p.filter(256, data, 'amplitude')
     p.fit(pha, amp, method='circular')
     p.fit(pha, amp, method='gc')
     p.fit(pha, amp, method='gc', n_perm=2)
     p.fit(pha, amp, method='gc', smooth=5)
     p.surrogates, p.pvalues
示例#3
0
    def test_functional_erpac(self):
        """Test function test_functional_pac."""
        # erpac simultation
        n_epochs, n_times, sf, edges = 400, 1000, 512., 50
        x, times = pac_signals_wavelet(f_pha=10,
                                       f_amp=100,
                                       n_epochs=n_epochs,
                                       noise=.1,
                                       n_times=n_times,
                                       sf=sf)
        times = times[edges:-edges]
        # phase / amplitude extraction (single time)
        p = EventRelatedPac(f_pha=[8, 12],
                            f_amp=(30, 200, 5, 5),
                            dcomplex='wavelet',
                            width=12)
        kw = dict(n_jobs=1, edges=edges)
        phases = p.filter(sf, x, ftype='phase', **kw)
        amplitudes = p.filter(sf, x, ftype='amplitude', **kw)
        n_amp = len(p.yvec)
        # generate a normal distribution
        gt = np.zeros((n_amp, n_times - 2 * edges))
        b_amp = np.abs(p.yvec.reshape(-1, 1) - np.array([[80, 120]])).argmin(0)
        gt[b_amp[0]:b_amp[1] + 1, :] = True

        plt.figure(figsize=(16, 5))
        plt.subplot(131)
        p.pacplot(gt, times, p.yvec, title='Ground truth', cmap='magma')

        for n_meth, meth in enumerate(['circular', 'gc']):
            # compute erpac + p-values
            erpac = p.fit(phases,
                          amplitudes,
                          method=meth,
                          mcp='bonferroni',
                          n_perm=30).squeeze()
            pvalues = p.pvalues.squeeze()
            # find everywhere erpac is significant + compare to ground truth
            is_signi = pvalues < .05
            erpac[~is_signi] = np.nan
            # computes accuracy
            acc = 100 * (is_signi == gt).sum() / (n_amp * n_times)
            assert acc > 80.
            # plot the result
            title = f"Method={p.method}\nAccuracy={np.around(acc, 2)}%"
            plt.subplot(1, 3, n_meth + 2)
            p.pacplot(erpac, times, p.yvec, title=title)
        plt.tight_layout()
        plt.show()
示例#4
0
 def test_filter(self):
     """Test function filter."""
     data = np.random.rand(7, 1000)
     p = EventRelatedPac()
     p.filter(256, data, 'phase')
     p.filter(256, data, 'amplitude')
示例#5
0
# now, concatenate the two signals across the time axis
x = np.concatenate((x1, x2), axis=1)
time = np.arange(x.shape[1]) / sf

###############################################################################
# Define an ERPAC object and extract the phase and the amplitude
###############################################################################
# use :class:`tensorpac.EventRelatedPac.filter` method to extract phases and
# amplitudes

# define an ERPAC object
p = EventRelatedPac(f_pha=[9, 11], f_amp=(60, 140, 5, 3))

# extract phases and amplitudes
pha = p.filter(sf, x, ftype='phase')
amp = p.filter(sf, x, ftype='amplitude')

###############################################################################
# Compute the ERPAC using the two implemented methods and plot it
###############################################################################

# implemented ERPAC methods
methods = ['circular', 'gc']

plt.figure(figsize=(16, 8))
for n_m, m in enumerate(methods):
    # compute the erpac
    erpac = p.fit(pha, amp, method=m, smooth=100).squeeze()

    # plot
示例#6
0
# now, concatenate the two signals across the time axis
x = np.concatenate((x1, x2), axis=1)
time = np.arange(x.shape[1]) / sf


###############################################################################
# Define an ERPAC object and extract the phase and the amplitude
###############################################################################
# use :class:`tensorpac.EventRelatedPac.filter` method to extract phases and
# amplitudes

# define an ERPAC object
p = EventRelatedPac(f_pha=[9, 11], f_amp=(60, 140, 5, 3))

# extract phases and amplitudes
pha = p.filter(sf, x, ftype='phase', n_jobs=1)
amp = p.filter(sf, x, ftype='amplitude', n_jobs=1)

###############################################################################
# Compute the ERPAC using the two implemented methods and plot it
###############################################################################

# implemented ERPAC methods
methods = ['circular', 'gc']

plt.figure(figsize=(16, 8))
for n_m, m in enumerate(methods):
    # compute the erpac
    erpac = p.fit(pha, amp, method=m, smooth=100, n_jobs=-1).squeeze()

    # plot
示例#7
0
import seaborn as sns

plt.style.use('seaborn-poster')
sns.set_style("white")
plt.rc('font', family=cfg["font"])

# erpac simultation
n_epochs, n_times, sf, edges = 400, 1000, 512., 50
x, times = pac_signals_wavelet(f_pha=10, f_amp=100, n_epochs=n_epochs,
                               noise=.1, n_times=n_times, sf=sf)
times = times[edges:-edges]
# phase / amplitude extraction (single time)
p = EventRelatedPac(f_pha=[8, 12], f_amp=(30, 200, 5, 5),
                    dcomplex='wavelet', width=12)
kw = dict(n_jobs=1, edges=edges)
phases = p.filter(sf, x, ftype='phase', **kw)
amplitudes = p.filter(sf, x, ftype='amplitude', **kw)
n_amp = len(p.yvec)
# generate a normal distribution
gt = np.zeros((n_amp, n_times - 2 * edges))
b_amp = np.abs(p.yvec.reshape(-1, 1) - np.array([[80, 120]])).argmin(0)
gt[b_amp[0]:b_amp[1] + 1, :] = True

plt.figure(figsize=(16, 5))
plt.subplot(131)
p.pacplot(gt, times, p.yvec, title='Ground truth', cmap='magma')

for n_meth, meth in enumerate(['circular', 'gc']):
    # compute erpac + p-values
    erpac = p.fit(phases, amplitudes, method=meth,
                  mcp='bonferroni', n_perm=30).squeeze()