MNE-Python compatibility (AMICAICA)¶
AMICAICA fits AMICA directly from an MNE-Python
Raw/Epochs and hands the result back through the standard MNE ICA surface.
It is additive: the scikit-learn-style AMICA interface and the
EEGLAB output are unchanged; this is a
second entry point for MNE users, not a replacement.
MNE is an optional dependency, so import pamica never requires it. Install the
extra and import the wrapper explicitly:
import mne
from pamica.mne_compat import AMICAICA
raw = mne.io.read_raw_eeglab("subject.set", preload=True)
ica = AMICAICA(n_mix=3, random_state=42).fit(raw, picks="eeg", max_iter=100)
sources = ica.get_sources(raw) # an mne.io.RawArray of component activations
maps = ica.get_components() # scalp maps, shape (n_channels, n_components)
ica.plot_components() # native mne.viz topographies
# Reconstruct with some components removed:
clean = ica.apply(raw.copy(), exclude=[0, 3])
fit accepts a Raw or Epochs (epochs are concatenated along time, as MNE's
own ICA does), any MNE picks selector, and forwards remaining keywords
(max_iter, lrate, do_newton, ...) to AMICA.fit,
so a setting left out takes the backend's default, as with AMICA (for example lrate=0.1). It rejects
non-finite input, supports principal component analysis (PCA) reduction
(pcakeep/pcadb) and rank-deficient data
(see Rank-reduced fits and the PCA residual),
and a degenerate (diverged) fit is refused by the consumer methods rather than
emitting NaNs.
Choosing the backend¶
AMICAICA fits through AMICA, so it takes the same backend parameter:
the PyTorch backend by default, or the Apple-GPU MLX backend with backend="mlx" (issue #313).
Everything on this page works on both.
# raw: 32 average-referenced EEG channels, so rank 31
ica = AMICAICA(backend="mlx", random_state=42).fit(raw, picks="eeg", pcakeep=31)
clean = ica.apply(raw.copy(), exclude=[0])
As with AMICA, device (and a dtype fit keyword) apply to the PyTorch backend only and raise ValueError with backend="mlx",
and backend="mlx" without MLX installed raises ImportError.
The export reads the fitted mean, sphere and per-model centers through the backend-agnostic float64 accessors
AMICA.get_mean(), get_sphere() and get_model_center(), so both backends take the same code path.
Precision follows the backend:
- A PyTorch fit (float64 by default) exports at float64 parity.
- An MLX fit computes in float32, so its unmixing matrix, mean and centers carry float32 rounding
and the export is float32-consistent rather than float64-parity.
get_sourcesagrees withica.amica_.transform(which runs in float32) within float32 tolerance, and excluding a component changes the data by that component's back-projection to the same tolerance. - Reconstruction does not depend on the backend's precision.
MNE's mixing is the float64 pseudo-inverse of the exported unmixing and the PCA basis is orthonormal,
so
applywith nothing excluded returns the input to float64 round-off on either backend, residual included. Precision on the MLX backend gives the measured figures.
Interoperating with mne.preprocessing.ICA¶
to_mne_ica() returns a fully-populated
mne.preprocessing.ICA,
so the entire MNE ICA ecosystem (plotting, find_bads_eog/_ecg, exclusion
workflows) works on an AMICA decomposition:
The wrapper's get_sources, apply, get_components, plot_components and
plot_sources delegate to this object, so they reproduce AMICA.transform
exactly: MNE
computes sources as
unmixing_matrix_ @ pca_components_[:n_components_] @ (X / pre_whitener_ - pca_mean_), and
the export maps pamica's mean, symmetric-ZCA sphere and unmixing into those
matrices (writing the sphere as V diag(1/√e) Vᵀ with V orthonormal so MNE's
scalp maps come out in channel space). The equivalence
to_mne_ica().get_sources(raw) == AMICA.transform(X) is pinned by the test
suite on real sample EEG.
Rank-reduced fits and the PCA residual¶
A fit can be rank-reduced by pcakeep/pcadb,
or by automatic rank detection on Maxwell-filtered, average-referenced or interpolated data.
AMICA then models only the retained PCA subspace, and n_components_ is that rank.
The export still carries the full PCA basis, so apply restores the residual the reduction discarded,
as MNE's own ICA does (issue #322).
With nothing excluded, apply returns the input;
excluding a component removes that component and nothing else.
This goes beyond the Fortran reference, whose back-projection reconstructs only the retained subspace.
MNE's own n_pca_components gives that behavior back:
ica = AMICAICA(random_state=42).fit(raw, pcakeep=20, max_iter=100)
# Default: the residual is restored.
clean = ica.apply(raw.copy(), exclude=[0])
# Reference behavior: rank-reduced reconstruction.
reduced = ica.apply(raw.copy(), exclude=[0], n_pca_components=ica.n_components_)
Sources, component maps and the log-likelihood are the same either way; only reconstruction differs.
The fitted basis is ica.pca_components_ (retained rows first, then the residual) with ica.pca_explained_variance_,
and pamica vs. AMICA has the full rationale.
Multi-model fits¶
AMICA can learn a mixture of ICA models (n_models > 1). MNE's ICA represents
only one unmixing matrix, so each model is exported as its own single-model
mne.preprocessing.ICA, and the per-sample model dominance (which model best
explains each timepoint) is exposed directly, since MNE has no concept for it:
ica = AMICAICA(n_models=2, random_state=42).fit(raw, max_iter=100)
# Per-model: model_idx selects the model on every consumer method.
sources_m1 = ica.get_sources(raw, model_idx=1)
ica.plot_components(model_idx=1)
model1 = ica.to_mne_ica(model_idx=1) # a standard ICA for model 1
# Model dominance over time (P(model | sample), columns sum to 1):
prob = ica.get_model_probability(raw) # (n_models, n_samples)
ica.plot_model_probability(raw) # per-model probability + best-model LL
get_model_probability/plot_model_probability build on the public
AMICA.model_loglik/model_probability accessors, which score arbitrary data
through the fitted sphere and mean. Each per-model export folds that model's
data-space center into pca_mean_, so to_mne_ica(model_idx=h).get_sources(raw)
reproduces AMICA.transform(X, model_idx=h) (with X the picked channel array)
for every model, not just the first.
Inspecting pamica-specific metadata¶
An mne.preprocessing.ICA has no field for AMICA's adaptive source densities or
component sharing, so rather than drop them, the wrapper exposes them directly:
from pamica.mne_compat import AMICAICA, PDFTYPE_NAMES
ica = AMICAICA(n_models=2, random_state=42).fit(raw, max_iter=100)
families = ica.get_pdftype(model_idx=0) # (n_components,) codes 0-4
names = [PDFTYPE_NAMES[c] for c in families] # e.g. "generalized_gaussian"
rho = ica.get_rho(model_idx=0) # (n_mix, n_components) GG shape
shared = ica.shared_components() # [(model, comp), ...] groups
get_pdftype returns each component's density family (0 generalized Gaussian,
1 super-Gaussian cosh, 2 Gaussian, 3 logistic, 4 sub-Gaussian cosh; they differ
per component only under the adaptive switcher pdftype=1). get_rho is the
generalized-Gaussian shape (meaningful for pdftype=0). shared_components
lists components merged across models by share_comps (empty otherwise). The
same three accessors exist on the scikit-learn-style AMICA.
Separation-quality metrics¶
The MIR/PMI metrics are available directly on an MNE object, so MNE-side users get the same separation-quality numbers as EEGLAB-side users:
mir_nats, variance = ica.mir(raw, model_idx=0) # mutual information reduced
mi_matrix = ica.pmi(raw, model_idx=0) # pairwise MI between sources
Both extract the fitted channels from the Raw/Epochs and delegate to
AMICA.mir/pmi, reproducing the array API exactly.
pamica.mne_compat.AMICAICA
¶
Fit AMICA from MNE objects and interoperate with mne.preprocessing.ICA.
The wrapper fits pamica's natural-gradient AMICA backend on the data of an
MNE :class:~mne.io.Raw or :class:~mne.Epochs and lets MNE consume the
result: :meth:get_sources, :meth:apply, :meth:get_components,
:meth:plot_components and :meth:plot_sources all delegate to a real
:class:mne.preprocessing.ICA built by :meth:to_mne_ica.
For a multi-model fit (n_models > 1) each model is exported as its own
single-model MNE ICA (to_mne_ica(model_idx=...) / the model_idx
argument on the consumer methods), and the per-sample model dominance --
which MNE's ICA cannot represent -- is exposed directly by
:meth:get_model_probability / :meth:plot_model_probability.
Separation-quality metrics (issue #133) are available directly on an MNE
object: :meth:mir (Mutual Information Reduction) and :meth:pmi (pairwise
mutual information between sources). The pamica-specific fitted metadata MNE
cannot hold -- source-density family, GG shape, component sharing -- is
inspectable via :meth:get_pdftype / :meth:get_rho / :meth:shared_components.
The fit runs on the PyTorch backend by default and on the Apple-GPU MLX
backend with backend="mlx" (issue #313); see the precision note in the
Notes below.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_models
|
int
|
Number of ICA models to learn (AMICA |
1
|
n_mix
|
int
|
Number of mixture components per source (AMICA |
3
|
random_state
|
int or None
|
Seed for the AMICA fit (passed through as the backend |
None
|
device
|
str or device
|
Torch device for the fit ( |
None
|
verbose
|
bool
|
Whether the underlying :class: |
True
|
backend
|
(torch, mlx)
|
Which :class: |
"torch"
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ImportError
|
If |
Attributes:
| Name | Type | Description |
|---|---|---|
amica_ |
AMICA
|
The fitted pamica model (holds all |
info_ |
Info
|
The picked measurement info the fit was run on (channel subset only). |
ch_names_ |
list of str
|
Names of the fitted channels, in order. |
n_components_ |
int
|
Number of ICA components. Equals the number of fitted channels unless the data are rank-deficient, in which case the model is sized to the detected numerical rank (issue #223). |
pre_whitener_ |
np.ndarray of shape (n_channels, 1)
|
Per-channel-type scaling applied before fitting, following MNE's own ICA
convention (one |
pca_components_ |
np.ndarray of shape (n_channels, n_channels) or None
|
The full orthonormal PCA basis of the fit, in pre-whitened channel
space, computed once at fit time and exported as the MNE ICA's
|
pca_explained_variance_ |
np.ndarray of shape (n_channels,) or None
|
Variance of the pre-whitened fit data along each row of
|
reject_by_annotation_ |
bool
|
Whether the last |
good_sample_mask_ |
np.ndarray of bool or None
|
For a |
converged_ |
bool
|
Whether the last fit ended usable (not degenerate). A degenerate fit is kept for inspection but refused by the consumer methods (issue #50). |
stop_reason_ |
str or None
|
Why the backend fit stopped (e.g. |
Notes
Model h's AMICA transform is S = W_fort @ (sphere @ (X - mean) - c_h),
where c_h is that model's data-space center (identically zero for a
single model, since the c update is gated to n_models > 1). MNE
computes sources as S = unmixing_matrix_ @ pca_components_[:n_components_]
@ (X / pre_whitener_ - pca_mean_).
X is scaled by channel type before fitting, exactly as MNE's own ICA does,
so the two pipelines agree; AMICA's sphering absorbs a global rescale, so this
changes nothing for single-channel-type data. Writing the symmetric-ZCA sphere as
V @ diag(1/sqrt(e)) @ V.T with V orthonormal, the exported ICA for
model h uses pca_components_ = V.T,
unmixing_matrix_ = W_fort @ sphere @ V and
pca_mean_ = mean + inv(sphere) @ c_h (which reduces to mean when
c_h is zero). Keeping pca_components_ orthonormal is what makes MNE's
get_components (scalp maps inv(sphere) @ inv(W_fort)) come out right,
since MNE assumes orthonormal PCA rows. The mapping is pinned by a round-trip
test (to_mne_ica(model_idx=h).get_sources(raw) equals
amica_.transform(X, model_idx=h)).
Rank-deficient input -- Maxwell-filtered MEG, average referencing, channel
interpolation, or an explicit pcakeep/pcadb -- is supported. The sphere
is then (n_kept, n_channels) and has no eigendecomposition, so the
retained basis is its right singular vectors instead. n_components_
reports the retained rank.
The discarded PCA subspace (the residual) is never part of the
decomposition, and the export keeps it: pca_components_ holds the full
(n_channels, n_channels) basis, retained rows first, and MNE's
ICA.apply keeps rows past n_components_ as residual PCA components.
So :meth:apply restores the residual by default, as MNE's own ICA does,
and excluding a component removes only that component (issue #322). This
goes beyond the Fortran reference, whose output has no representation of
the residual (the written sphere's rows past numeigs are zero), so any
back-projection from it drops the residual. Sources, component maps and the
log-likelihood are unchanged; only reconstruction differs. For the
reference's rank-reduced reconstruction pass MNE's own
n_pca_components=ica.n_components_ to :meth:apply. See
docs/guides/amica-differences.md and ADR 0005.
Precision: the export always reads the fit through the same float64
accessors (AMICA.get_sphere/get_mean/get_model_center), so
both backends go through one code path. A PyTorch fit (float64 by
default) exports at float64 parity. An MLX fit computes in float32, so its
unmixing matrix, mean and centers carry float32 rounding (its sphere is
the float64 one it was built from), and the export is float32-consistent
rather than float64-parity: :meth:get_sources agrees with
amica_.transform (which runs in float32) to float32 tolerance, and
excluding a component changes the data by that component's
back-projection to the same tolerance. Reconstruction does not depend on
that precision: MNE's mixing is the float64 pseudo-inverse of the exported
unmixing and the PCA basis is orthonormal to float64 round-off, so
:meth:apply with nothing excluded returns the input to float64
round-off on either backend, PCA residual included.
Source code in pamica/mne_compat/core.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 | |
fit(inst, picks=None, start=None, stop=None, reject_by_annotation=True, **fit_kwargs)
¶
Fit AMICA to the data of an MNE Raw or Epochs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inst
|
BaseRaw | BaseEpochs
|
The data to decompose. |
required |
picks
|
str | list | slice | None
|
Channels to fit, in any form MNE accepts (e.g. |
None
|
start
|
int | None
|
Sample range for |
None
|
stop
|
int | None
|
Sample range for |
None
|
reject_by_annotation
|
bool
|
If |
True
|
**fit_kwargs
|
Forwarded to :meth: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
AMICAICA
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in pamica/mne_compat/core.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
to_mne_ica(model_idx=0)
¶
Build (and cache) a fully-populated :class:mne.preprocessing.ICA.
The returned object is a genuine MNE ICA: get_sources, apply,
get_components, save and the mne.viz plotters operate on it
natively. See the class :class:Notes <AMICAICA> for the
mean/sphere/unmixing to pca_mean_/pca_components_/
unmixing_matrix_ mapping.
For a multi-model fit each model is exported as its own single-model
MNE ICA (MNE has no multi-model concept); pass model_idx to pick
one. The per-model exports are cached and returned by reference:
mutating one (for example setting .exclude) persists across
subsequent :meth:apply/:meth:get_sources calls for that model until
the next :meth:fit.
The export carries the full (n_channels, n_channels) PCA basis
computed at fit time (see pca_components_), with n_components_
the retained rank and n_pca_components left at None. For a
rank-reduced fit the rows past n_components_ span the discarded
PCA residual, which MNE keeps as residual PCA components, so the
exported ICA's apply restores it by default (issue #322). This goes
beyond the Fortran reference, whose output has no representation of
the residual; apply(..., n_pca_components=ica.n_components_) gives
the reference's rank-reduced reconstruction. When a residual is
exported, its dimension and that opt-out are logged at INFO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_idx
|
int
|
Which AMICA model to export ( |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
ica |
ICA
|
|
Source code in pamica/mne_compat/core.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
get_sources(inst, *args, model_idx=0, **kwargs)
¶
Sources for inst from model model_idx (see ICA.get_sources).
model_idx is keyword-only so positional arguments pass straight
through to MNE's ICA.get_sources (e.g. add_channels,
start/stop).
Source code in pamica/mne_compat/core.py
apply(inst, *args, model_idx=0, **kwargs)
¶
Remove selected components of model model_idx and back-project.
model_idx is keyword-only so positional arguments pass straight
through to MNE's ICA.apply. Pass exclude=[...] (or set it on the
exported ICA) to drop components; with no exclusions this reconstructs
the input.
For a rank-reduced fit (pcakeep/pcadb or automatic rank
detection) the PCA residual, the subspace the reduction discarded and
AMICA never modeled, is restored by default: excluding a component
removes that component's back-projection and nothing else, as with
MNE's own ICA (issue #322). This differs from the Fortran reference,
whose back-projection reconstructs only the retained subspace. To get
that rank-reduced reconstruction, pass
n_pca_components=ica.n_components_; a float n_pca_components
keeps residual rows by cumulative explained variance, following MNE.
A full-rank fit has no residual, so the option changes nothing there.
Source code in pamica/mne_compat/core.py
get_components(*, model_idx=0)
¶
plot_components(*args, model_idx=0, **kwargs)
¶
Plot model model_idx component topographies (see ICA.plot_components).
plot_sources(inst, *args, model_idx=0, **kwargs)
¶
Plot model model_idx component time courses (see ICA.plot_sources).
get_model_probability(inst, *, reject_by_annotation=True)
¶
Per-sample posterior probability of each model on inst (dominance).
Returns P(model | sample) as (n_models, n_samples) via
:meth:AMICA.model_probability on inst's data (Epochs are
concatenated along time). Each column sums to 1; all ones for a single
model. MNE's own ICA has no multi-model concept, so this is exposed
here rather than through the exported per-model ICA objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inst
|
BaseRaw | BaseEpochs
|
Data to score. |
required |
reject_by_annotation
|
bool
|
For |
True
|
Source code in pamica/mne_compat/core.py
plot_model_probability(inst, *, srate=None, reject_by_annotation=True, **kwargs)
¶
Plot per-model probability + best-model log-likelihood over inst.
Delegates to :func:pamica.viz.plot_model_probability with the live
per-model log-likelihood (:meth:AMICA.model_loglik) on inst's
data. srate defaults to the fitted recording's sampling rate, so the
x-axis is in seconds; extra keywords (smooth_sec, window_sec,
axes) pass through.
With reject_by_annotation (default, Raw only), samples covered
by inst's bad_* annotations plot as gaps: the log-likelihood is
evaluated on the good samples only and rejected columns are NaN, so
the time axis stays aligned with inst (issue #251). Note
smooth_sec widens the gaps by the smoothing window, since the
Hanning smoothing propagates NaN across its support.
Source code in pamica/mne_compat/core.py
mir(inst, *, model_idx=0, nbins=None, reject_by_annotation=True)
¶
Mutual Information Reduction of model model_idx on inst.
How much mutual information the fitted unmixing removes from the data,
in nats (issue #133). Delegates to :meth:AMICA.mir on inst's
fitted-channel data; MIR is shift-invariant, so mean/c centering is
irrelevant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inst
|
BaseRaw | BaseEpochs
|
Data to score ( |
required |
model_idx
|
int
|
Which model's unmixing to use. |
0
|
nbins
|
int
|
Histogram bin count; see :func: |
None
|
reject_by_annotation
|
bool
|
For |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
mir_nats |
float
|
|
variance |
float
|
|
Source code in pamica/mne_compat/core.py
pmi(inst, *, model_idx=0, nbins=None, reject_by_annotation=True)
¶
Pairwise Mutual Information between model model_idx's sources on inst.
The residual pairwise dependence between fitted sources, in nats
(issue #133). Delegates to :meth:AMICA.pmi on inst's fitted-channel
data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inst
|
BaseRaw | BaseEpochs
|
Data to score ( |
required |
model_idx
|
int
|
Which model's sources to use. |
0
|
nbins
|
int
|
Histogram bin count; see :func: |
None
|
reject_by_annotation
|
bool
|
For |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
mi_matrix |
np.ndarray of shape (n_components, n_components)
|
Symmetric; the diagonal is each source's own entropy. |
Source code in pamica/mne_compat/core.py
get_pdftype(*, model_idx=0)
¶
Per-component source-density family code for model model_idx.
One integer per ICA component (0-4); map to names with
:data:pamica.mne_compat.PDFTYPE_NAMES. All components share one family
unless the adaptive switcher (pdftype=1) moved them (issue #26).
Source code in pamica/mne_compat/core.py
get_rho(*, model_idx=0)
¶
Generalized-Gaussian shape rho for model model_idx.
Shape (n_mix, n_components); rho == 2 is Gaussian-shaped,
rho == 1 Laplacian, rho < 1 heavier-tailed. Meaningful only for
the generalized-Gaussian family (pdftype=0).
Source code in pamica/mne_compat/core.py
shared_components()
¶
Components shared across models by share_comps (issue #60).
One group of (model_idx, component_idx) pairs per shared component;
empty when nothing is shared (always so for a single model or a default
multi-model fit with share_comps off).