macro_eeg_model.evaluation.evaluator#

Classes#

Evaluator

A class responsible for evaluating simulated EEG data .

Module Contents#

class macro_eeg_model.evaluation.evaluator.Evaluator[source]#

A class responsible for evaluating simulated EEG data . It computes metrics such as coherence and power spectra across different brain regions (nodes).

frequencies#

The frequency range for evaluating the data ([0, 30] Hz).

Type:

list

simulation_data_extractor#

An instance of the src.evaluation.simulation_data_extractor.SimulationDataExtractor class used to extract and process simulated EEG data.

Type:

SimulationDataExtractor

__init__()[source]#

Initializes the Evaluator class, setting up the frequency range and loading real and simulated data.

evaluate(plot_overview=True)[source]#

Evaluates and compares the coherence and power metrics using _evaluate_metric().

Parameters:

plot_overview (bool, optional) – If True, generates overview plots for the evaluated metrics; if False, generates individual plots for (pairs of) brain regions. (default is True).

_evaluate_metric(evaluation_func, desc, plot_overview, rows, cols, save_file_name)[source]#

A helper function to evaluate a specific metric (e.g., coherence or power) across nodes or node pairs.

Parameters:
  • evaluation_func (function) – The function to evaluate the metric (_evaluate_coherence_node_pair() or _evaluate_power_node()).

  • desc (str) – The description for the tqdm progress bar.

  • plot_overview (bool) – If True, generates overview plots for the evaluated metrics; if False, generates individual plots for (pairs of) brain regions.

  • rows (int) – The number of rows in the overview plot.

  • cols (int) – The number of columns in the overview plot.

  • save_file_name (str) – The file name for saving the overview plot.

_get_nodes(pairwise=False)[source]#

Generates nodes or node pairs for evaluation.

Parameters:

pairwise (bool, optional) – If True, generates pairs of nodes (for coherence evaluation), otherwise generates individual nodes (for power evaluation) (default is False).

Returns:

A tuple containing one or two nodes, depending on the value of pairwise.

Return type:

tuple

_evaluate_peaks(node, fig=None, ax=None, show_legend=True)[source]#

Evaluates the presence of alpha peaks (using _get_peaks()) and plots (using _plot_metric()) detrended power spectrum for a given node.

Parameters:
  • node (str) – The name of the brain region to evaluate.

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

_evaluate_fooof(node, fig=None, ax=None, show_legend=True)[source]#

Evaluates the presence of peaks (using _get_fooof_peaks()) and plots (using _plot_metric()) the peaks.

Parameters:
  • node (str) – The name of the brain region to evaluate.

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

_evaluate_power_node(node, fig=None, ax=None, show_legend=True)[source]#

Evaluates (using _get_simulated_power()) and plots (using _plot_metric()) the power spectrum for a given node.

Parameters:
  • node (str) – The name of the brain region to evaluate.

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

_evaluate_coherence_node_pair(node1, node2, fig=None, ax=None, show_legend=True)[source]#

Evaluates (using _get_simulated_coherences()) and plots (using _plot_metric()) the coherence between a pair of nodes.

Parameters:
  • node1 (str) – The name of the first brain region (node).

  • node2 (str) – The name of the second brain region (node).

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

_get_fooof_peaks(node)[source]#

Computes the peaks in the power spectrum for a given node using FooofTester.

Parameters:

node (str) – The name of the brain region for which to compute the peaks.

Returns:

A tuple containing:

  • frequencies (numpy.ndarray): The array of frequencies.

  • all_binary_peaks (dict): A dictionary of binary peaks for each simulation, keyed by simulation name.

Return type:

tuple

_get_peaks(node)[source]#

Computes the peaks in the power spectrum for a given node using PeakTester.

Parameters:

node (str) – The name of the brain region for which to compute the peaks.

Returns:

A tuple containing:

  • frequencies (numpy.ndarray): The array of frequencies.

  • powers (dict): A dictionary of simulated power spectra, keyed by simulation name.

  • p_values (dict): A dictionary of p-values for the peak test, keyed by simulation name.

  • test_names (dict): A dictionary of test names for the peak test, keyed by simulation name.

Return type:

tuple

_get_simulated_power(node)[source]#

Retrieves the simulated power spectrum for a given node.

Parameters:

node (str) – The name of the brain region for which to retrieve the simulated power spectrum.

Returns:

A tuple containing:

  • frequencies (numpy.ndarray): The array of frequencies.

  • powers (dict): A dictionary of simulated power spectra, keyed by simulation name.

Return type:

tuple

_get_simulated_coherences(node1, node2)[source]#

Computes the simulated coherence between a pair of nodes for each simulation using src.simulation.coherence_computer.CoherenceComputer.compute_coherence_matched() .

Parameters:
  • node1 (str) – The name of the first brain region.

  • node2 (str) – The name of the second brain region.

Returns:

A tuple containing:

  • frequencies (numpy.ndarray): The array of frequencies for coherence.

  • coherences (dict): A dictionary of simulated coherence values, keyed by simulation name.

Return type:

tuple

_plot_metric(title, sim_frequencies, sim_data, plot_type='line', fig=None, ax=None, show_legend=True, y_label=None, xlim=None, ylim=None, file_label=None, label_addons=None)[source]#

Plots a metric (e.g., coherence or power) of data using _plot_simulated_data().

Parameters:
  • title (str) – The title of the plot.

  • sim_frequencies (numpy.ndarray) – The array of frequencies for the simulated data.

  • sim_data (dict) – The simulated data (e.g., power or coherence) to plot, keyed by simulation name.

  • plot_type (str, optional) – The type of plot to create (default is “line”). Currently, “line”, “scatter”, “mean_std” are supported.

  • fig (matplotlib.figure.Figure, optional) – The figure object for plotting (default is None).

  • ax (matplotlib.axes.Axes, optional) – The axis object for plotting (default is None).

  • show_legend (bool, optional) – If True, shows the legend on the plot (default is True).

  • y_label (str, optional) – The label for the y-axis (default is None).

  • xlim (list, optional) – The x-axis limits for the plot (default is None).

  • ylim (list, optional) – The y-axis limits for the plot (default is None).

  • file_label (str, optional) – The file name label for saving the plot (default is None).

  • label_addons (dict, optional) – The dictionary of label addons to append to the name of the data (default is None).

static _plot_simulated_data(ax, frequencies, data, label_addons, plot_type='line')[source]#

Plots the simulated EEG data on a given axis.

Parameters:
  • ax (matplotlib.axes.Axes) – The axis object for plotting.

  • frequencies (numpy.ndarray) – The array of frequencies for the simulated data.

  • data (dict) – The simulated data (e.g., power or coherence) to plot, keyed by simulation name.

  • label_addons (dict) – The dictionary of label addons to append to the name of the data.

  • plot_type (str, optional) – The type of plot to create (default is “line”). Currently, “line”, “scatter”, “mean_std” are supported.

static _get_ax(ax, rows, cols, i)[source]#

Helper function to get the appropriate subplot axis.

Parameters:
  • ax (numpy.ndarray) – The array of axis objects for subplots.

  • rows (int) – The number of rows in the subplot grid.

  • cols (int) – The number of columns in the subplot grid.

  • i (int) – The index of the current plot.

Returns:

The appropriate axis object for the current subplot.

Return type:

matplotlib.axes.Axes