MCPcopy Index your code
hub / github.com/mne-tools/mne-python / simulate_data

Function simulate_data

mne/decoding/tests/test_ssd.py:36–78  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

34
35
36def 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

Callers 8

test_ssdFunction · 0.70
test_ssd_epoched_dataFunction · 0.70
test_ssd_pipelineFunction · 0.70
test_sortingFunction · 0.70
test_return_filteredFunction · 0.70
test_non_full_rank_dataFunction · 0.70
test_ssd_save_loadFunction · 0.70
test_get_spectral_ratioFunction · 0.70

Calls 2

filter_dataFunction · 0.90
normMethod · 0.80

Tested by

no test coverage detected