Run AMICA on EEG Data

In this tutorial we will:

  1. Run AMICA on EEG data

  2. Compare our results to Fortran AMICA.

  3. Export our AMICA instance to an mne.preprocessing.ICA object.

import amica
from amica import AMICA
import matplotlib.pyplot as plt
import mne

import numpy as np

Download sample data

data_path = amica.datasets.data_path()

Load Fortran AMICA initial weights and results

This is not necessary to run AMICA in Python, but we are going to compare amica-python results to those obtained from the original Fortran implementation.

initial_weights, initial_scales, initial_locations = amica.utils.load_initial_weights(
    data_path / "eeglab_sample_data" / "amicaout_test", n_components=32, n_mixtures=3
    )

Load EEG data

amica_outdir = data_path / "eeglab_sample_data" / "amicaout_test"
fortran_results = amica.utils.load_fortran_results(
    amica_outdir, n_components=32, n_mixtures=3
    )
raw = mne.io.read_raw_eeglab(
    data_path / "eeglab_sample_data"/ "eeglab_data.set", preload=True
    )
data = raw.get_data().T  # Shape (n_samples, n_channels)
data *= 1e6  # Convert from Volts to microVolts
Reading /home/circleci/amica_test_data/eeglab_sample_data/eeglab_data.fdt
Reading 0 ... 30503  =      0.000 ...   238.305 secs...

Run AMICA-Python

transformer = AMICA(
        max_iter=200,
        w_init=initial_weights,
        sbeta_init=initial_scales,
        mu_init=initial_locations,
        verbose=2
)
transformer.fit(data)
INFO     | getting the mean ... - amica.linalg:pre_whiten
INFO     |  Getting the covariance matrix ... - amica.linalg:pre_whiten
INFO     | doing eigenvalue decomposition for 32 features ... - amica.linalg:pre_whiten
INFO     | minimum eigenvalues: [4.87990051 6.92011971 7.65621479] - amica.linalg:pre_whiten
INFO     | maximum eigenvalues: [9711.14308385 3039.68504351 1244.41294471] - amica.linalg:pre_whiten
INFO     | num eigvals kept: 32 - amica.linalg:pre_whiten
INFO     | Sphering the data... - amica.linalg:pre_whiten
INFO     | numeigs = 32, nw = 32 - amica.linalg:pre_whiten
INFO     | 1: block size = 30504 - amica.core:solve
INFO     | Solving. (please be patient, this may take a while)... - amica.core:solve
INFO     | Iteration 1, lrate = 0.05000, LL = -3.5136812, nd = 0.0578126, D = 0.00446 took 0.21 seconds - amica.core:_main_loop
INFO     | Iteration 2, lrate = 0.05000, LL = -3.4687938, nd = 0.0254382, D = 0.00391 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 3, lrate = 0.05000, LL = -3.4616091, nd = 0.0243398, D = 0.00376 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 4, lrate = 0.05000, LL = -3.4589193, nd = 0.0270364, D = 0.00554 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 5, lrate = 0.05000, LL = -3.4569812, nd = 0.0277558, D = 0.00994 took 0.21 seconds - amica.core:_main_loop
INFO     | Iteration 6, lrate = 0.05000, LL = -3.4553322, nd = 0.0273357, D = 0.01680 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 7, lrate = 0.05000, LL = -3.4538623, nd = 0.0264404, D = 0.02561 took 0.22 seconds - amica.core:_main_loop
INFO     | Iteration 8, lrate = 0.05000, LL = -3.4525343, nd = 0.0253345, D = 0.03580 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 9, lrate = 0.05000, LL = -3.4513420, nd = 0.0240416, D = 0.04681 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 10, lrate = 0.05000, LL = -3.4502899, nd = 0.0225474, D = 0.05812 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 11, lrate = 0.05000, LL = -3.4493808, nd = 0.0208839, D = 0.06920 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 12, lrate = 0.05000, LL = -3.4486104, nd = 0.0191346, D = 0.07957 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 13, lrate = 0.05000, LL = -3.4479753, nd = 0.0173030, D = 0.08886 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 14, lrate = 0.05000, LL = -3.4474542, nd = 0.0157035, D = 0.09674 took 0.22 seconds - amica.core:_main_loop
INFO     | Iteration 15, lrate = 0.05000, LL = -3.4470249, nd = 0.0143385, D = 0.10318 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 16, lrate = 0.05000, LL = -3.4466649, nd = 0.0132064, D = 0.10822 took 0.28 seconds - amica.core:_main_loop
INFO     | Iteration 17, lrate = 0.05000, LL = -3.4463600, nd = 0.0123116, D = 0.11195 took 0.22 seconds - amica.core:_main_loop
INFO     | Iteration 18, lrate = 0.05000, LL = -3.4460919, nd = 0.0116319, D = 0.11453 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 19, lrate = 0.05000, LL = -3.4458499, nd = 0.0111276, D = 0.11612 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 20, lrate = 0.05000, LL = -3.4456295, nd = 0.0107475, D = 0.11690 took 0.21 seconds - amica.core:_main_loop
INFO     | Iteration 21, lrate = 0.05000, LL = -3.4454234, nd = 0.0104643, D = 0.11704 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 22, lrate = 0.05000, LL = -3.4452293, nd = 0.0102432, D = 0.11667 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 23, lrate = 0.05000, LL = -3.4450445, nd = 0.0100656, D = 0.11591 took 0.21 seconds - amica.core:_main_loop
INFO     | Iteration 24, lrate = 0.05000, LL = -3.4448657, nd = 0.0099188, D = 0.11485 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 25, lrate = 0.05000, LL = -3.4446937, nd = 0.0097926, D = 0.11356 took 0.22 seconds - amica.core:_main_loop
INFO     | Iteration 26, lrate = 0.05000, LL = -3.4445265, nd = 0.0096849, D = 0.11212 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 27, lrate = 0.05000, LL = -3.4443632, nd = 0.0095877, D = 0.11055 took 0.20 seconds - amica.core:_main_loop
INFO     | Iteration 28, lrate = 0.05000, LL = -3.4442048, nd = 0.0094986, D = 0.10891 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 29, lrate = 0.05000, LL = -3.4440489, nd = 0.0094179, D = 0.10722 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 30, lrate = 0.05000, LL = -3.4438959, nd = 0.0093394, D = 0.10550 took 0.21 seconds - amica.core:_main_loop
INFO     | Iteration 31, lrate = 0.05000, LL = -3.4437453, nd = 0.0092646, D = 0.10377 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 32, lrate = 0.05000, LL = -3.4435975, nd = 0.0091968, D = 0.10203 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 33, lrate = 0.05000, LL = -3.4434514, nd = 0.0091354, D = 0.10031 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 34, lrate = 0.05000, LL = -3.4433079, nd = 0.0090763, D = 0.09860 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 35, lrate = 0.05000, LL = -3.4431670, nd = 0.0090245, D = 0.09691 took 0.22 seconds - amica.core:_main_loop
INFO     | Iteration 36, lrate = 0.05000, LL = -3.4430282, nd = 0.0089752, D = 0.09524 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 37, lrate = 0.05000, LL = -3.4428901, nd = 0.0089295, D = 0.09360 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 38, lrate = 0.05000, LL = -3.4427538, nd = 0.0088829, D = 0.09199 took 0.22 seconds - amica.core:_main_loop
INFO     | Iteration 39, lrate = 0.05000, LL = -3.4426194, nd = 0.0088388, D = 0.09042 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 40, lrate = 0.05000, LL = -3.4424860, nd = 0.0087975, D = 0.08887 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 41, lrate = 0.05000, LL = -3.4423547, nd = 0.0087559, D = 0.08736 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 42, lrate = 0.05000, LL = -3.4422239, nd = 0.0087198, D = 0.08588 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 43, lrate = 0.05000, LL = -3.4420943, nd = 0.0086848, D = 0.08444 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 44, lrate = 0.05000, LL = -3.4419655, nd = 0.0086506, D = 0.08303 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 45, lrate = 0.05000, LL = -3.4418378, nd = 0.0086188, D = 0.08165 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 46, lrate = 0.05000, LL = -3.4417113, nd = 0.0085873, D = 0.08031 took 0.22 seconds - amica.core:_main_loop
INFO     | Iteration 47, lrate = 0.05000, LL = -3.4415855, nd = 0.0085544, D = 0.07900 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 48, lrate = 0.05000, LL = -3.4414606, nd = 0.0085211, D = 0.07772 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 49, lrate = 0.05000, LL = -3.4413366, nd = 0.0084888, D = 0.07648 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 50, lrate = 0.05000, LL = -3.4412137, nd = 0.0073552, D = 0.07526 took 0.39 seconds - amica.core:_main_loop
INFO     | Starting Newton ... setting numdecs to 0 - amica.core:_main_loop
INFO     | Iteration 51, lrate = 0.10000, LL = -3.4410148, nd = 0.0073394, D = 0.07393 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 52, lrate = 0.20000, LL = -3.4406292, nd = 0.0072835, D = 0.07137 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 53, lrate = 0.30000, LL = -3.4400637, nd = 0.0072115, D = 0.06776 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 54, lrate = 0.40000, LL = -3.4393283, nd = 0.0071184, D = 0.06333 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 55, lrate = 0.50000, LL = -3.4384312, nd = 0.0070108, D = 0.05839 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 56, lrate = 0.60000, LL = -3.4373842, nd = 0.0068979, D = 0.05327 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 57, lrate = 0.70000, LL = -3.4361985, nd = 0.0067652, D = 0.04822 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 58, lrate = 0.80000, LL = -3.4348911, nd = 0.0065756, D = 0.04348 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 59, lrate = 0.90000, LL = -3.4334900, nd = 0.0063576, D = 0.03913 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 60, lrate = 1.00000, LL = -3.4320193, nd = 0.0061072, D = 0.03525 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 61, lrate = 1.00000, LL = -3.4306365, nd = 0.0058443, D = 0.03208 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 62, lrate = 1.00000, LL = -3.4293493, nd = 0.0055605, D = 0.02950 took 0.40 seconds - amica.core:_main_loop
INFO     | Iteration 63, lrate = 1.00000, LL = -3.4281693, nd = 0.0052842, D = 0.02745 took 0.40 seconds - amica.core:_main_loop
INFO     | Iteration 64, lrate = 1.00000, LL = -3.4270925, nd = 0.0050450, D = 0.02597 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 65, lrate = 1.00000, LL = -3.4261108, nd = 0.0048195, D = 0.02502 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 66, lrate = 1.00000, LL = -3.4252153, nd = 0.0046346, D = 0.02454 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 67, lrate = 1.00000, LL = -3.4243916, nd = 0.0044608, D = 0.02437 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 68, lrate = 1.00000, LL = -3.4236341, nd = 0.0042997, D = 0.02439 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 69, lrate = 1.00000, LL = -3.4229293, nd = 0.0041611, D = 0.02453 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 70, lrate = 1.00000, LL = -3.4222690, nd = 0.0040368, D = 0.02470 took 0.40 seconds - amica.core:_main_loop
INFO     | Iteration 71, lrate = 1.00000, LL = -3.4216481, nd = 0.0039236, D = 0.02492 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 72, lrate = 1.00000, LL = -3.4210605, nd = 0.0038293, D = 0.02514 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 73, lrate = 1.00000, LL = -3.4205003, nd = 0.0037451, D = 0.02541 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 74, lrate = 1.00000, LL = -3.4199601, nd = 0.0036840, D = 0.02571 took 0.32 seconds - amica.core:_main_loop
INFO     | Iteration 75, lrate = 1.00000, LL = -3.4194357, nd = 0.0036248, D = 0.02601 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 76, lrate = 1.00000, LL = -3.4189283, nd = 0.0035608, D = 0.02632 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 77, lrate = 1.00000, LL = -3.4184328, nd = 0.0035077, D = 0.02665 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 78, lrate = 1.00000, LL = -3.4179502, nd = 0.0034498, D = 0.02700 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 79, lrate = 1.00000, LL = -3.4174823, nd = 0.0033849, D = 0.02735 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 80, lrate = 1.00000, LL = -3.4170301, nd = 0.0033202, D = 0.02772 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 81, lrate = 1.00000, LL = -3.4165961, nd = 0.0032324, D = 0.02812 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 82, lrate = 1.00000, LL = -3.4161830, nd = 0.0031522, D = 0.02853 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 83, lrate = 1.00000, LL = -3.4157921, nd = 0.0030533, D = 0.02897 took 0.40 seconds - amica.core:_main_loop
INFO     | Iteration 84, lrate = 1.00000, LL = -3.4154224, nd = 0.0029692, D = 0.02942 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 85, lrate = 1.00000, LL = -3.4150725, nd = 0.0028897, D = 0.02989 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 86, lrate = 1.00000, LL = -3.4147412, nd = 0.0028215, D = 0.03038 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 87, lrate = 1.00000, LL = -3.4144243, nd = 0.0027518, D = 0.03085 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 88, lrate = 1.00000, LL = -3.4141217, nd = 0.0026904, D = 0.03132 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 89, lrate = 1.00000, LL = -3.4138322, nd = 0.0026328, D = 0.03178 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 90, lrate = 1.00000, LL = -3.4135558, nd = 0.0025808, D = 0.03224 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 91, lrate = 1.00000, LL = -3.4132903, nd = 0.0025351, D = 0.03268 took 0.38 seconds - amica.core:_main_loop
INFO     | Iteration 92, lrate = 1.00000, LL = -3.4130349, nd = 0.0024919, D = 0.03310 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 93, lrate = 1.00000, LL = -3.4127878, nd = 0.0024396, D = 0.03352 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 94, lrate = 1.00000, LL = -3.4125515, nd = 0.0023929, D = 0.03395 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 95, lrate = 1.00000, LL = -3.4123236, nd = 0.0023507, D = 0.03436 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 96, lrate = 1.00000, LL = -3.4121046, nd = 0.0023118, D = 0.03476 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 97, lrate = 1.00000, LL = -3.4118917, nd = 0.0022843, D = 0.03515 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 98, lrate = 1.00000, LL = -3.4116854, nd = 0.0022630, D = 0.03554 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 99, lrate = 1.00000, LL = -3.4114822, nd = 0.0022459, D = 0.03589 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 100, lrate = 1.00000, LL = -3.4112831, nd = 0.0022394, D = 0.03623 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 101, lrate = 1.00000, LL = -3.4112498, nd = 0.0022958, D = 0.03623 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 102, lrate = 1.00000, LL = -3.4112233, nd = 0.0023264, D = 0.03623 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 103, lrate = 1.00000, LL = -3.4111987, nd = 0.0023474, D = 0.03623 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 104, lrate = 1.00000, LL = -3.4111754, nd = 0.0023640, D = 0.03623 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 105, lrate = 1.00000, LL = -3.4111530, nd = 0.0023774, D = 0.03623 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 106, lrate = 1.00000, LL = -3.4111324, nd = 0.0023891, D = 0.03623 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 107, lrate = 1.00000, LL = -3.4109271, nd = 0.0023282, D = 0.03689 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 108, lrate = 1.00000, LL = -3.4107273, nd = 0.0022918, D = 0.03719 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 109, lrate = 1.00000, LL = -3.4105318, nd = 0.0022727, D = 0.03743 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 110, lrate = 1.00000, LL = -3.4103369, nd = 0.0022641, D = 0.03766 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 111, lrate = 1.00000, LL = -3.4101420, nd = 0.0022599, D = 0.03790 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 112, lrate = 1.00000, LL = -3.4099467, nd = 0.0022437, D = 0.03812 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 113, lrate = 1.00000, LL = -3.4097545, nd = 0.0022286, D = 0.03832 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 114, lrate = 1.00000, LL = -3.4095622, nd = 0.0022082, D = 0.03851 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 115, lrate = 1.00000, LL = -3.4093724, nd = 0.0021893, D = 0.03869 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 116, lrate = 1.00000, LL = -3.4091839, nd = 0.0021746, D = 0.03888 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 117, lrate = 1.00000, LL = -3.4089963, nd = 0.0021577, D = 0.03907 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 118, lrate = 1.00000, LL = -3.4088109, nd = 0.0021374, D = 0.03925 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 119, lrate = 1.00000, LL = -3.4086289, nd = 0.0021174, D = 0.03945 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 120, lrate = 1.00000, LL = -3.4084500, nd = 0.0020963, D = 0.03963 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 121, lrate = 1.00000, LL = -3.4082740, nd = 0.0020709, D = 0.03984 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 122, lrate = 1.00000, LL = -3.4081012, nd = 0.0020386, D = 0.04005 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 123, lrate = 1.00000, LL = -3.4079335, nd = 0.0020010, D = 0.04026 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 124, lrate = 1.00000, LL = -3.4077697, nd = 0.0019664, D = 0.04047 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 125, lrate = 1.00000, LL = -3.4076116, nd = 0.0019212, D = 0.04069 took 0.38 seconds - amica.core:_main_loop
INFO     | Iteration 126, lrate = 1.00000, LL = -3.4074604, nd = 0.0018721, D = 0.04090 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 127, lrate = 1.00000, LL = -3.4073149, nd = 0.0018282, D = 0.04110 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 128, lrate = 1.00000, LL = -3.4071761, nd = 0.0017893, D = 0.04130 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 129, lrate = 1.00000, LL = -3.4070432, nd = 0.0017520, D = 0.04149 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 130, lrate = 1.00000, LL = -3.4069132, nd = 0.0017223, D = 0.04166 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 131, lrate = 1.00000, LL = -3.4067873, nd = 0.0016955, D = 0.04183 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 132, lrate = 1.00000, LL = -3.4066614, nd = 0.0016805, D = 0.04198 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 133, lrate = 1.00000, LL = -3.4065355, nd = 0.0016748, D = 0.04212 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 134, lrate = 1.00000, LL = -3.4064093, nd = 0.0016768, D = 0.04227 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 135, lrate = 1.00000, LL = -3.4062816, nd = 0.0016918, D = 0.04241 took 0.38 seconds - amica.core:_main_loop
INFO     | Iteration 136, lrate = 1.00000, LL = -3.4061507, nd = 0.0017111, D = 0.04255 took 0.32 seconds - amica.core:_main_loop
INFO     | Iteration 137, lrate = 1.00000, LL = -3.4060147, nd = 0.0017316, D = 0.04267 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 138, lrate = 1.00000, LL = -3.4058754, nd = 0.0017380, D = 0.04282 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 139, lrate = 1.00000, LL = -3.4057353, nd = 0.0017304, D = 0.04298 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 140, lrate = 1.00000, LL = -3.4055960, nd = 0.0017083, D = 0.04313 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 141, lrate = 1.00000, LL = -3.4054582, nd = 0.0016882, D = 0.04328 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 142, lrate = 1.00000, LL = -3.4053247, nd = 0.0016611, D = 0.04344 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 143, lrate = 1.00000, LL = -3.4051935, nd = 0.0016307, D = 0.04359 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 144, lrate = 1.00000, LL = -3.4050661, nd = 0.0016045, D = 0.04373 took 0.38 seconds - amica.core:_main_loop
INFO     | Iteration 145, lrate = 1.00000, LL = -3.4049427, nd = 0.0015778, D = 0.04387 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 146, lrate = 1.00000, LL = -3.4048225, nd = 0.0015514, D = 0.04401 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 147, lrate = 1.00000, LL = -3.4047046, nd = 0.0015245, D = 0.04415 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 148, lrate = 1.00000, LL = -3.4045883, nd = 0.0014937, D = 0.04430 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 149, lrate = 1.00000, LL = -3.4044803, nd = 0.0014655, D = 0.04445 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 150, lrate = 1.00000, LL = -3.4043806, nd = 0.0014378, D = 0.04461 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 151, lrate = 1.00000, LL = -3.4042855, nd = 0.0014054, D = 0.04476 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 152, lrate = 1.00000, LL = -3.4041939, nd = 0.0013679, D = 0.04492 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 153, lrate = 1.00000, LL = -3.4041070, nd = 0.0013300, D = 0.04506 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 154, lrate = 1.00000, LL = -3.4040245, nd = 0.0012945, D = 0.04521 took 0.40 seconds - amica.core:_main_loop
INFO     | Iteration 155, lrate = 1.00000, LL = -3.4039453, nd = 0.0012577, D = 0.04535 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 156, lrate = 1.00000, LL = -3.4038690, nd = 0.0012225, D = 0.04550 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 157, lrate = 1.00000, LL = -3.4037953, nd = 0.0011889, D = 0.04564 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 158, lrate = 1.00000, LL = -3.4037255, nd = 0.0011548, D = 0.04578 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 159, lrate = 1.00000, LL = -3.4036581, nd = 0.0011226, D = 0.04592 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 160, lrate = 1.00000, LL = -3.4035933, nd = 0.0010944, D = 0.04606 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 161, lrate = 1.00000, LL = -3.4035302, nd = 0.0010692, D = 0.04621 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 162, lrate = 1.00000, LL = -3.4034694, nd = 0.0010422, D = 0.04636 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 163, lrate = 1.00000, LL = -3.4034098, nd = 0.0010182, D = 0.04649 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 164, lrate = 1.00000, LL = -3.4033514, nd = 0.0009982, D = 0.04664 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 165, lrate = 1.00000, LL = -3.4032967, nd = 0.0009739, D = 0.04678 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 166, lrate = 1.00000, LL = -3.4032475, nd = 0.0009558, D = 0.04693 took 0.38 seconds - amica.core:_main_loop
INFO     | Iteration 167, lrate = 1.00000, LL = -3.4032000, nd = 0.0009387, D = 0.04706 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 168, lrate = 1.00000, LL = -3.4031536, nd = 0.0009255, D = 0.04720 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 169, lrate = 1.00000, LL = -3.4031080, nd = 0.0009100, D = 0.04733 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 170, lrate = 1.00000, LL = -3.4030636, nd = 0.0008974, D = 0.04745 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 171, lrate = 1.00000, LL = -3.4030199, nd = 0.0008862, D = 0.04757 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 172, lrate = 1.00000, LL = -3.4029767, nd = 0.0008749, D = 0.04769 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 173, lrate = 1.00000, LL = -3.4029340, nd = 0.0008627, D = 0.04781 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 174, lrate = 1.00000, LL = -3.4028920, nd = 0.0008521, D = 0.04793 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 175, lrate = 1.00000, LL = -3.4028504, nd = 0.0008435, D = 0.04805 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 176, lrate = 1.00000, LL = -3.4028090, nd = 0.0008381, D = 0.04817 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 177, lrate = 1.00000, LL = -3.4027686, nd = 0.0008318, D = 0.04829 took 0.51 seconds - amica.core:_main_loop
INFO     | Iteration 178, lrate = 1.00000, LL = -3.4027279, nd = 0.0008218, D = 0.04841 took 0.38 seconds - amica.core:_main_loop
INFO     | Iteration 179, lrate = 1.00000, LL = -3.4026881, nd = 0.0008168, D = 0.04854 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 180, lrate = 1.00000, LL = -3.4026476, nd = 0.0008093, D = 0.04865 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 181, lrate = 1.00000, LL = -3.4026071, nd = 0.0008022, D = 0.04877 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 182, lrate = 1.00000, LL = -3.4025668, nd = 0.0007969, D = 0.04889 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 183, lrate = 1.00000, LL = -3.4025265, nd = 0.0007888, D = 0.04900 took 0.29 seconds - amica.core:_main_loop
INFO     | Iteration 184, lrate = 1.00000, LL = -3.4024863, nd = 0.0007816, D = 0.04912 took 0.39 seconds - amica.core:_main_loop
INFO     | Iteration 185, lrate = 1.00000, LL = -3.4024490, nd = 0.0007768, D = 0.04925 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 186, lrate = 1.00000, LL = -3.4024112, nd = 0.0007712, D = 0.04937 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 187, lrate = 1.00000, LL = -3.4023730, nd = 0.0007647, D = 0.04949 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 188, lrate = 1.00000, LL = -3.4023342, nd = 0.0007579, D = 0.04961 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 189, lrate = 1.00000, LL = -3.4022947, nd = 0.0007573, D = 0.04972 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 190, lrate = 1.00000, LL = -3.4022533, nd = 0.0007581, D = 0.04984 took 0.38 seconds - amica.core:_main_loop
INFO     | Iteration 191, lrate = 1.00000, LL = -3.4022101, nd = 0.0007578, D = 0.04996 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 192, lrate = 1.00000, LL = -3.4021649, nd = 0.0007592, D = 0.05008 took 0.31 seconds - amica.core:_main_loop
INFO     | Iteration 193, lrate = 1.00000, LL = -3.4021169, nd = 0.0007580, D = 0.05020 took 0.38 seconds - amica.core:_main_loop
INFO     | Iteration 194, lrate = 1.00000, LL = -3.4020689, nd = 0.0007561, D = 0.05033 took 0.41 seconds - amica.core:_main_loop
INFO     | Iteration 195, lrate = 1.00000, LL = -3.4020312, nd = 0.0007540, D = 0.05047 took 0.40 seconds - amica.core:_main_loop
INFO     | Iteration 196, lrate = 1.00000, LL = -3.4019944, nd = 0.0007498, D = 0.05061 took 0.40 seconds - amica.core:_main_loop
INFO     | Iteration 197, lrate = 1.00000, LL = -3.4019574, nd = 0.0007469, D = 0.05075 took 0.40 seconds - amica.core:_main_loop
INFO     | Iteration 198, lrate = 1.00000, LL = -3.4019203, nd = 0.0007458, D = 0.05089 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 199, lrate = 1.00000, LL = -3.4018827, nd = 0.0007426, D = 0.05103 took 0.30 seconds - amica.core:_main_loop
INFO     | Iteration 200, lrate = 1.00000, LL = -3.4018446, nd = 0.0007414, D = 0.05116 took 0.30 seconds - amica.core:_main_loop
WARNING  | Maximum number of iterations reached before convergence. Consider increasing max_iter or relaxing tol. - amica.core:_main_loop
INFO     | Finished in 64.42 seconds - amica.core:_main_loop
AMICA(max_iter=200,
      mu_init=array([[0.50965947, 0.04527889, 0.35247896],
       [0.8762351 , 0.26628711, 0.99480272],
       [0.40212523, 0.27389552, 0.20770561],
       [0.65411987, 0.34182142, 0.09300251],
       [0.80444938, 0.44339815, 0.8126825 ],
       [0.97930402, 0.74877807, 0.04348142],
       [0.78631199, 0.60419269, 0.85805117],
       [0.02165665, 0.84801097, 0.85489792],
       [0.27966586, 0.56910808, 0.53418476],
       [0....
       [0.76343641, 0.05840647, 0.34338642, ..., 0.97308572, 0.76182668,
        0.83096944],
       [0.58233765, 0.04081942, 0.43449808, ..., 0.33150471, 0.73984712,
        0.66007229],
       ...,
       [0.63443108, 0.33966091, 0.97756094, ..., 0.92677176, 0.24606719,
        0.54599154],
       [0.85448053, 0.88756462, 0.86326901, ..., 0.93752582, 0.87834654,
        0.02637342],
       [0.93852255, 0.64263167, 0.14632447, ..., 0.74057343, 0.5679117 ,
        0.47788761]], shape=(32, 32)))
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


Compare results

def plot_topomaps(A, output="python"):
    fig, ax = plt.subplots(
        nrows=8,
        ncols=4,
        figsize=(8, 12),
        constrained_layout=True
        )
    for i, this_ax in zip(range(32), ax.flat):
        mne.viz.plot_topomap(
            A[:, i],
            pos=raw.info,
            axes=this_ax,
            show=False,
        )
        this_ax.set_title(f"Component {i}")
    fig.suptitle(f"AMICA Component Topomaps ({output})", fontsize=16)
    return fig, ax
fig1, ax1 = plot_topomaps(transformer.mixing_, output="python")
AMICA Component Topomaps (python), Component 0, Component 1, Component 2, Component 3, Component 4, Component 5, Component 6, Component 7, Component 8, Component 9, Component 10, Component 11, Component 12, Component 13, Component 14, Component 15, Component 16, Component 17, Component 18, Component 19, Component 20, Component 21, Component 22, Component 23, Component 24, Component 25, Component 26, Component 27, Component 28, Component 29, Component 30, Component 31

The Fortran mixing matrix is in sphered space. We need to unwhiten it first.

A_fortran = np.linalg.pinv(fortran_results['S']) @ fortran_results['A']
fig2, ax2 = plot_topomaps(A_fortran, output="fortran")
AMICA Component Topomaps (fortran), Component 0, Component 1, Component 2, Component 3, Component 4, Component 5, Component 6, Component 7, Component 8, Component 9, Component 10, Component 11, Component 12, Component 13, Component 14, Component 15, Component 16, Component 17, Component 18, Component 19, Component 20, Component 21, Component 22, Component 23, Component 24, Component 25, Component 26, Component 27, Component 28, Component 29, Component 30, Component 31

Export to MNE

ica = transformer.to_mne(info=raw.info)
ica.plot_components(nrows=8, ncols=4)
ICA components, ICA000, ICA001, ICA002, ICA003, ICA004, ICA005, ICA006, ICA007, ICA008, ICA009, ICA010, ICA011, ICA012, ICA013, ICA014, ICA015, ICA016, ICA017, ICA018, ICA019, ICA020, ICA021, ICA022, ICA023, ICA024, ICA025, ICA026, ICA027, ICA028, ICA029, ICA030, ICA031
<MNEFigure size 780x1909 with 32 Axes>

Total running time of the script: (1 minutes 14.505 seconds)

Gallery generated by Sphinx-Gallery