Esempio n. 1
0
l_list = []
for event_id in [dict(hands=2), dict(feet=3)]:
    epochs = Epochs(raw,
                    events,
                    event_id,
                    tmin,
                    tmax,
                    proj=True,
                    picks=picks,
                    baseline=None,
                    preload=True)
    n_components = 20
    freqs = np.linspace(7, 30, 31)
    ica = ICA(n_components=n_components, freqs=freqs, rng=0)
    ica.fit(epochs, max_iter=5000, verbose=100)
    l_list.append([ica.compute_loss(x) for x in epochs_data])
plt.figure()
likelihoods = np.array(l_list)
for i, label in enumerate(['hand', 'feet']):
    plt.scatter(*(likelihoods[j, labels == i] for j in [0, 1]), label=label)

plt.xlabel('negative loglik of model hand')
plt.ylabel('negative loglik of model feet')
l_min = np.min(likelihoods)
l_max = np.max(likelihoods)
t = np.linspace(l_min, l_max)
plt.title(subject)
plt.plot(t, t, color='k', label='y=x')
plt.legend()
plt.show()
Esempio n. 2
0
import mne

from mne.datasets import sample

data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(raw_fname, preload=True)
picks = mne.pick_types(raw.info,
                       meg=False,
                       eeg=True,
                       eog=False,
                       stim=False,
                       exclude='bads')

n_components = 59
n_bins = 40
freqs = np.linspace(1, 60, n_bins + 1)
loss_list = []

for n_component in np.arange(1, n_components):
    print(n_component)
    smica = ICA(n_components=n_component, freqs=freqs, rng=0)
    smica.fit(raw, picks=picks, verbose=2000, tol=1e-7, em_it=10000)
    loss_list.append(smica.compute_loss())

plt.plot(np.arange(1, n_components), loss_list - np.min(loss_list))
plt.yscale('log')
plt.xlabel('Number of sources')
plt.ylabel('Negative log likelihood')
plt.show()