pyntbci.eeg.generate_mixing_matrix

pyntbci.eeg.generate_mixing_matrix(n_channels: int, n_sources: int = 1, primary_channels: int | list[int] | list[list[int]] = None, leakage: float = 0.3, channel_jitter: float = 0.2, random_state: int | Generator = None, dtype: str | dtype = 'float32') NDArray[source]

Generate a mixing matrix that projects one or more sources to channel space, simulating volume conduction. A set of “primary” channels can be specified per source (e.g., occipital channels for a visually evoked source), which receive a weight of 1, while all other channels receive a smaller “leakage” weight.

Parameters:
  • n_channels (int) – The number of channels to mix into.

  • n_sources (int (default: 1)) – The number of sources to mix.

  • primary_channels (int | list[int] | list[list[int]] (default: None)) – The channel indexes that should receive the full-strength signal for each source. If a single int or list[int] is given, it is used for every source. If a list[list[int]] is given, it must have n_sources entries, one list of channel indexes per source. If None, all channels are treated as primary channels for every source (i.e., no spatial specificity).

  • leakage (float (default: 0.3)) – The relative weight (with respect to a primary channel) given to non-primary channels.

  • channel_jitter (float (default: 0.2)) – The relative per-channel random gain variability, as a fraction of the weight.

  • random_state (int | np.random.Generator (default: None)) – A seed or numpy random number generator to draw the channel gains from. If None, a new one is used.

  • dtype (str | np.dtype (default: "float32")) – The dtype of the returned array. Computation is always done in float64 internally; this only controls the precision of the final result.

Returns:

mixing_matrix – The mixing matrix of shape (n_sources, n_channels).

Return type:

NDArray