Simulate data according to an instantaneous mixin model. Data are simulated in the statistical source space, where n=n_components sources contain the peak of interest.
(
freqs_sig=(9, 12),
n_trials=100,
n_channels=20,
n_samples=500,
samples_per_second=250,
n_components=5,
SNR=0.05,
random_state=42,
)
| 34 | |
| 35 | |
| 36 | def simulate_data( |
| 37 | freqs_sig=(9, 12), |
| 38 | n_trials=100, |
| 39 | n_channels=20, |
| 40 | n_samples=500, |
| 41 | samples_per_second=250, |
| 42 | n_components=5, |
| 43 | SNR=0.05, |
| 44 | random_state=42, |
| 45 | ): |
| 46 | """Simulate data according to an instantaneous mixin model. |
| 47 | |
| 48 | Data are simulated in the statistical source space, where n=n_components |
| 49 | sources contain the peak of interest. |
| 50 | """ |
| 51 | rng = np.random.RandomState(random_state) |
| 52 | |
| 53 | filt_params_signal = dict( |
| 54 | l_freq=freqs_sig[0], |
| 55 | h_freq=freqs_sig[1], |
| 56 | l_trans_bandwidth=1, |
| 57 | h_trans_bandwidth=1, |
| 58 | fir_design="firwin", |
| 59 | ) |
| 60 | |
| 61 | # generate an orthogonal mixin matrix |
| 62 | mixing_mat = np.linalg.svd(rng.randn(n_channels, n_channels))[0] |
| 63 | # define sources |
| 64 | S_s = rng.randn(n_trials * n_samples, n_components) |
| 65 | # filter source in the specific freq. band of interest |
| 66 | S_s = filter_data(S_s.T, samples_per_second, **filt_params_signal).T |
| 67 | S_n = rng.randn(n_trials * n_samples, n_channels - n_components) |
| 68 | S = np.hstack((S_s, S_n)) |
| 69 | # mix data |
| 70 | X_s = np.dot(mixing_mat[:, :n_components], S_s.T).T |
| 71 | X_n = np.dot(mixing_mat[:, n_components:], S_n.T).T |
| 72 | # add noise |
| 73 | X_s = X_s / np.linalg.norm(X_s, "fro") |
| 74 | X_n = X_n / np.linalg.norm(X_n, "fro") |
| 75 | X = SNR * X_s + (1 - SNR) * X_n |
| 76 | X = X.T |
| 77 | S = S.T |
| 78 | return X, mixing_mat, S |
| 79 | |
| 80 | |
| 81 | @pytest.mark.slowtest |
no test coverage detected