MCPcopy
hub / github.com/mne-tools/mne-python / _regularize

Function _regularize

mne/preprocessing/maxwell.py:1390–1421  ·  view source on GitHub ↗

Regularize a decomposition matrix.

(
    regularize, exp, S_decomp, mag_or_fine, extended_remove, t, verbose=None
)

Source from the content-addressed store, hash-verified

1388
1389@verbose
1390def _regularize(
1391 regularize, exp, S_decomp, mag_or_fine, extended_remove, t, verbose=None
1392):
1393 """Regularize a decomposition matrix."""
1394 # ALWAYS regularize the out components according to norm, since
1395 # gradiometer-only setups (e.g., KIT) can have zero first-order
1396 # (homogeneous field) components
1397 int_order, ext_order = exp["int_order"], exp["ext_order"]
1398 n_in = _get_n_moments(int_order)
1399 n_out = S_decomp.shape[1] - n_in
1400 t_str = f"{t:8.3f}"
1401 if regularize is not None: # regularize='in'
1402 in_removes, out_removes = _regularize_in(
1403 int_order, ext_order, S_decomp, mag_or_fine, extended_remove
1404 )
1405 else:
1406 in_removes = []
1407 out_removes = _regularize_out(
1408 int_order, ext_order, mag_or_fine, extended_remove
1409 )
1410 reg_in_moments = np.setdiff1d(np.arange(n_in), in_removes)
1411 reg_out_moments = np.setdiff1d(np.arange(n_in, S_decomp.shape[1]), out_removes)
1412 n_use_in = len(reg_in_moments)
1413 n_use_out = len(reg_out_moments)
1414 reg_moments = np.concatenate((reg_in_moments, reg_out_moments))
1415 S_decomp = S_decomp.take(reg_moments, axis=1)
1416 if regularize is not None or n_use_out != n_out:
1417 logger.info(
1418 f" Using {n_use_in + n_use_out}/{n_in + n_out} harmonic components "
1419 f"for {t_str} ({n_use_in}/{n_in} in, {n_use_out}/{n_out} out)"
1420 )
1421 return S_decomp, reg_moments, n_use_in
1422
1423
1424@verbose

Callers 1

_get_decompFunction · 0.85

Calls 4

_get_n_momentsFunction · 0.85
_regularize_inFunction · 0.85
_regularize_outFunction · 0.85
infoMethod · 0.80

Tested by

no test coverage detected