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

Method fit

mne/preprocessing/xdawn.py:281–357  ·  view source on GitHub ↗

Fit Xdawn from epochs. Parameters ---------- epochs : instance of Epochs An instance of Epoch on which Xdawn filters will be fitted. y : ndarray | None (default None) If None, used epochs.events[:, 2]. Returns -------

(self, epochs, y=None)

Source from the content-addressed store, hash-verified

279 )
280
281 def fit(self, epochs, y=None):
282 """Fit Xdawn from epochs.
283
284 Parameters
285 ----------
286 epochs : instance of Epochs
287 An instance of Epoch on which Xdawn filters will be fitted.
288 y : ndarray | None (default None)
289 If None, used epochs.events[:, 2].
290
291 Returns
292 -------
293 self : instance of Xdawn
294 The Xdawn instance.
295 """
296 # Check data
297 if not isinstance(epochs, BaseEpochs):
298 raise ValueError("epochs must be an Epochs object.")
299 picks = _pick_data_channels(epochs.info)
300 use_info = pick_info(epochs.info, picks)
301 X = epochs.get_data(picks)
302 y = epochs.events[:, 2] if y is None else y
303 self.event_id_ = epochs.event_id
304
305 # Check that no baseline was applied with correct overlap
306 correct_overlap = self.correct_overlap
307 if correct_overlap == "auto":
308 # Events are overlapped if the minimal inter-stimulus
309 # interval is smaller than the time window.
310 isi = np.diff(np.sort(epochs.events[:, 0]))
311 window = int((epochs.tmax - epochs.tmin) * epochs.info["sfreq"])
312 correct_overlap = isi.min() < window
313
314 if epochs.baseline and correct_overlap:
315 raise ValueError("Cannot apply correct_overlap if epochs were baselined.")
316
317 events, tmin, sfreq = None, 0.0, 1.0
318 if correct_overlap:
319 events = epochs.events
320 tmin = epochs.tmin
321 sfreq = epochs.info["sfreq"]
322 self.correct_overlap_ = correct_overlap
323
324 # Note: In this original version of Xdawn we compute and keep all
325 # components. The selection comes at transform().
326 n_components = X.shape[1]
327
328 # Main fitting function
329 filters, patterns, evokeds = _fit_xdawn(
330 X,
331 y,
332 n_components=n_components,
333 reg=self.reg,
334 signal_cov=self.signal_cov,
335 events=events,
336 tmin=tmin,
337 sfreq=sfreq,
338 method_params=self.cov_method_params,

Callers 5

test_xdawn_picksFunction · 0.95
test_xdawn_fitFunction · 0.95
test_XdawnTransformerFunction · 0.95

Calls 5

_pick_data_channelsFunction · 0.85
pick_infoFunction · 0.85
_fit_xdawnFunction · 0.85
EvokedArrayClass · 0.85
get_dataMethod · 0.45

Tested by 5

test_xdawn_picksFunction · 0.76
test_xdawn_fitFunction · 0.76
test_XdawnTransformerFunction · 0.76