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

Function deterministic_toy_data

mne/decoding/tests/test_csp.py:59–114  ·  view source on GitHub ↗

Generate a small deterministic toy data set. Four independent sources are modulated by the target class and mixed into signal space.

(classes=("class_a", "class_b"))

Source from the content-addressed store, hash-verified

57
58
59def deterministic_toy_data(classes=("class_a", "class_b")):
60 """Generate a small deterministic toy data set.
61
62 Four independent sources are modulated by the target class and mixed
63 into signal space.
64 """
65 sources_a = (
66 np.array(
67 [
68 [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
69 [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
70 [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1],
71 [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
72 ],
73 dtype=float,
74 )
75 * 2
76 - 1
77 )
78
79 sources_b = (
80 np.array(
81 [
82 [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
83 [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
84 [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1],
85 [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
86 ],
87 dtype=float,
88 )
89 * 2
90 - 1
91 )
92
93 sources_a[0, :] *= 1
94 sources_a[1, :] *= 2
95
96 sources_b[2, :] *= 3
97 sources_b[3, :] *= 4
98
99 mixing = np.array(
100 [
101 [1.0, 0.8, 0.6, 0.4],
102 [0.8, 1.0, 0.8, 0.6],
103 [0.6, 0.8, 1.0, 0.8],
104 [0.4, 0.6, 0.8, 1.0],
105 ]
106 )
107
108 x_class_a = mixing @ sources_a
109 x_class_b = mixing @ sources_b
110
111 x = np.stack([x_class_a, x_class_b])
112 y = np.array(classes)
113
114 return x, y
115
116

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected