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

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")

Export to MNE¶
ica = transformer.to_mne(info=raw.info)
ica.plot_components(nrows=8, ncols=4)

<MNEFigure size 780x1909 with 32 Axes>
Total running time of the script: (1 minutes 54.949 seconds)