Test Xdawn apply and transform.
()
| 130 | |
| 131 | |
| 132 | def test_xdawn_apply_transform(): |
| 133 | """Test Xdawn apply and transform.""" |
| 134 | # Get data |
| 135 | raw, events, picks = _get_data() |
| 136 | raw.pick(picks="eeg") |
| 137 | epochs = Epochs( |
| 138 | raw, |
| 139 | events, |
| 140 | event_id, |
| 141 | tmin, |
| 142 | tmax, |
| 143 | proj=False, |
| 144 | preload=True, |
| 145 | baseline=None, |
| 146 | verbose=False, |
| 147 | ) |
| 148 | n_components = 2 |
| 149 | # Fit Xdawn |
| 150 | xd = Xdawn(n_components=n_components, correct_overlap=False) |
| 151 | xd.fit(epochs) |
| 152 | |
| 153 | # Apply on different types of instances |
| 154 | for inst in [raw, epochs.average(), epochs]: |
| 155 | denoise = xd.apply(inst) |
| 156 | # Apply on other thing should raise an error |
| 157 | pytest.raises(ValueError, xd.apply, 42) |
| 158 | |
| 159 | # Transform on Epochs |
| 160 | xd.transform(epochs) |
| 161 | # Transform on Evoked |
| 162 | xd.transform(epochs.average()) |
| 163 | # Transform on ndarray |
| 164 | xd.transform(epochs._data) |
| 165 | xd.transform(epochs._data[0]) |
| 166 | # Transform on something else |
| 167 | pytest.raises(ValueError, xd.transform, 42) |
| 168 | |
| 169 | # Check numerical results with shuffled epochs |
| 170 | rng = np.random.RandomState(0) |
| 171 | idx = np.arange(len(epochs)) |
| 172 | rng.shuffle(idx) |
| 173 | xd.fit(epochs[idx]) |
| 174 | denoise_shfl = xd.apply(epochs) |
| 175 | assert_array_almost_equal(denoise["cond2"]._data, denoise_shfl["cond2"]._data) |
| 176 | |
| 177 | |
| 178 | def test_xdawn_regularization(): |