Visualization#

class src.visualization.VisualizationManager.VisualizationManager(fontsize: int = 15, figsize_signal: tuple = (16, 10), figsize_snn: tuple = (20, 20), nb_xticklabels: int = 10, nb_yticklabels: int = 8)#

Bases: object

Class that handles data visualization.

plot_ann_layers(out_rec: List[array], out: Tensor, x_data: Tensor, y_data: Tensor, model_name: str, plot_hidden: bool = True, z_max: int | None = 64, plot_title: str = 'output', imshow: bool = True, data_idx: int = 0, experiment: Experiment | None = None, epoch: int | None = None, show_flag: bool = False) None#

Method that plots output of SNN layers.

Parameters:
  • out_rec (List[np.array]) -- List of output of ANN layers.

  • out (torch.Tensor) -- ANN output.

  • x_data (torch.Tensor) -- ANN input.

  • y_data (torch.Tensor) -- ANN target output.

  • model_name (str) -- ANN model name.

  • plot_hidden (bool) -- Boolean that indicates weather to plot output of hidden layers.

  • z_max (Optional[int]) -- Maximum number of channels if input has 3 dimensions.

  • plot_title (str) -- Plot title.

  • imshow (bool) -- Boolean that indicates weather to use imshow function.

  • data_idx (int) -- Data index.

  • experiment (Optional[Experiment]) -- Comet ML experiment instance.

  • epoch (int) -- Training iteration.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

plot_coefficients(coefficients: ndarray, signal_type: str | None = None, spec_cmap: str = 'turbo', plot_title: str = 'coefficients', show_flag: bool = True, fig_dir: str | None = None, fig_format: str = 'jpg') None#

Method that plots the activation.

Parameters:
  • coefficients (np.ndarray) -- A numpy array of coefficients.

  • signal_type (str) -- Signal type.

  • spec_cmap (str) -- Colormap.

  • plot_title (str) -- Plot title.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • fig_dir (Optional[str]) -- Path to save figure.

  • fig_format (str) -- Format for figure saving.

plot_dist(coefficients: Tensor, experiment: Experiment | None = None, signal_type: str | None = None, bins: int = 50, kde: bool = False, log_scale: bool = False, plot_title: str = 'distribution', show_flag: bool = True, fig_dir: str | None = None, fig_format: str = 'jpg') None#

Method that plots data distribution.

Parameters:
  • coefficients (torch.Tensor) -- A numpy array of coefficients.

  • experiment (Optional[Experiment]) -- Comet ML experiment instance.

  • signal_type (str) -- Signal type.

  • bins (int) -- Number of bins.

  • kde (bool) -- Boolean that indicates weather to compute a kernel density estimate.

  • log_scale (bool) -- Boolean that indicates weather to set axis scale(s) to log.

  • plot_title (str) -- Plot title.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • fig_dir (Optional[str]) -- Path to save figure.

  • fig_format (str) -- Format for figure saving.

plot_loss(training_loss_hist: List[float], validation_loss_hist: List[float] | None = None, plot_title: str = 'Loss per epoch', show_flag: bool = True, fig_dir: str | None = None, fig_format: str = 'jpg') None#

Method that plots the loss history.

Parameters:
  • training_loss_hist (List[float]) -- Training loss history list.

  • validation_loss_hist (List[float]) -- Validation loss history list.

  • plot_title (str) -- Plot title.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • fig_dir (Optional[str]) -- Path to save figure.

  • fig_format (str) -- Format for figure saving.

plot_membrane_potential(membrane_potential_records: ndarray, imshow: bool = True, z_max: int | None = 32, channel_idx: bool = False, collated: bool = False, n_channels: int = 5, experiment: Experiment | None = None, epoch: int | None = None, signal_type: str | None = None, cmap: str = 'turbo', plot_title: str = 'Membrane potential', show_flag: bool = True, fig_dir: str | None = None, fig_format: str = 'jpg') None#

Method that plots the membrane potential records.

Parameters:
  • membrane_potential_records (np.ndarray) -- Membrane potential records.

  • imshow (bool) -- Boolean that indicates weather to use imshow function.

  • z_max (Optional[int]) -- Maximum number of channels if input has 3 dimensions.

  • channel_idx (bool) -- Boolean that indicates weather to show channel index.

  • collated (bool) -- Boolean that indicates weather to collate multiple figures.

  • n_channels (int) -- Number of channels within plot.

  • experiment (Optional[Experiment]) -- Comet ML experiment instance.

  • epoch (int) -- Training iteration.

  • signal_type (str) -- Signal type.

  • cmap (str) -- Colormap.

  • plot_title (str) -- Plot title.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • fig_dir (Optional[str]) -- Path to save figure.

  • fig_format (str) -- Format for figure saving.

plot_perceptual_metric(training_perceptual_metric_hist: List[float], validation_perceptual_metric_hist: List[float] | None = None, show_flag: bool = True, fig_dir: str | None = None, fig_format: str = 'jpg') None#

Method that plots a perceptual metric history.

Parameters:
  • training_perceptual_metric_hist (List[float]) -- Training perceptual metric history list.

  • validation_perceptual_metric_hist (List[float]) -- Validation perceptual metric history list.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • fig_dir (Optional[str]) -- Path to save figure.

  • fig_format (str) -- Format for figure saving.

plot_raster(spikes, scatter_plot: bool = False, z_max: int | None = 64, channel_idx: bool = False, collated: bool = False, experiment: Experiment | None = None, epoch: int | None = None, signal_type: str | None = None, plot_title: str = 'Raster plot', show_flag: bool = True, fig_dir: str | None = None, fig_format: str = 'jpg') None#

Method that plots the raster plot.

Parameters:
  • spikes (np.ndarray) -- Spike trains.

  • scatter_plot (bool) -- Boolean that indicates weather to use scatter function.

  • z_max (Optional[int]) -- Maximum number of channels if input has 3 dimensions.

  • channel_idx (bool) -- Boolean that indicates weather to show channel index.

  • collated (bool) -- Boolean that indicates weather to collate multiple figures.

  • experiment (Optional[Experiment]) -- Comet ML experiment instance.

  • epoch (int) -- Training iteration.

  • signal_type (str) -- Signal type.

  • plot_title (str) -- Plot title.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • fig_dir (Optional[str]) -- Path to save figure.

  • fig_format (str) -- Format for figure saving.

plot_signal(signal: ndarray | List[ndarray], signal_name: str, sample_rate: int, signal_label: List[str] = [], alpha: float = 0.5, show_flag: bool = True, fig_dir: str | None = None, fig_format: str = 'jpg') None#

Method that plots the audio signal.

Parameters:
  • signal (np.ndarray) -- A numpy array of audio signal.

  • signal_name (str) -- Audio signal name.

  • sample_rate (int) -- Sampling rate.

  • signal_label (List[str]) -- Signal label.

  • alpha (float) -- Sacalar value to adjust the transparency.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • fig_dir (Optional[str]) -- Path to save figure.

  • fig_format (str) -- Format for figure saving.

plot_signal_data(audio_dir: str | Path, index: int, plots_dir: str | Path, representation_name: str, coefficients: ndarray, signal_type: str, experiment: Experiment | None = None, scatter_plot: bool = False, plot_coefficients: bool = True, show_flag: bool = False, example_fig_format: str = 'jpg', verbose: bool = False) None#

Method that plots signal data: audio waveform and data representation.

Parameters:
  • audio_dir (Union[str, Path]) -- Directory of the audio dataset.

  • index (int) -- Signal index.

  • plots_dir (Union[str, Path]) -- Plots directory.

  • representation_name (str) -- Representation name.

  • coefficients (np.ndarray) -- Representation coefficients.

  • signal_type (str) -- Signal type.

  • experiment (Optional[Experiment]) -- Comet ML experiment instance.

  • scatter_plot (bool) -- Boolean that indicates weather to use scatter function.

  • plot_coefficients (bool) -- Boolean that indicates weather to plot representation coefficients.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • example_fig_format (str) -- Format for figure saving.

  • verbose (bool) -- Boolean that indicates weather to print specific output.

plot_snn_layers(spk_rec: List[array], mem_rec: List[array], mem: Tensor, x_data: Tensor, y_data: Tensor, output: List[Tensor], plot_hidden: bool = True, z_max: int | None = 16, scatter_plot: bool = False, imshow: bool = True, data_idx: int = 0, experiment: Experiment | None = None, epoch: int | None = None, show_flag: bool = False) None#

Method that plots output of SNN layers.

Parameters:
  • spk_rec (List[np.array]) -- List of spike trains of SNN layers.

  • mem_rec (List[np.array]) -- List of membrane potential of SNN layers.

  • mem (torch.Tensor) -- SNN output.

  • x_data (torch.Tensor) -- SNN input.

  • y_data (torch.Tensor) -- SNN target output.

  • output (List[torch.Tensor]) -- SNN intermediate output if use_intermediate_output parameter is True.

  • plot_hidden (bool) -- Boolean that indicates weather to plot output of hidden layers.

  • z_max (Optional[int]) -- Maximum number of channels if input has 3 dimensions.

  • scatter_plot (bool) -- Boolean that indicates weather to use scatter function.

  • imshow (bool) -- Boolean that indicates weather to use imshow function.

  • data_idx (int) -- Data index.

  • experiment (Optional[Experiment]) -- Comet ML experiment instance.

  • epoch (int) -- Training iteration.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

plot_spectrogram(coefficients: ndarray, transform_name: str | None = 'log_power', z_max: int | None = 64, channel_idx: bool = False, collated: bool = False, experiment: Experiment | None = None, epoch: int | None = None, signal_type: str | None = None, epsilon: float = 1e-08, cmap: str = 'turbo', vmax: float | None = None, vmin: float | None = None, plot_title: str = 'Spectrogram (dB)', show_flag: bool = True, fig_dir: str | None = None, fig_format: str = 'jpg') None#

Method that plots the STFT magnitude.

Parameters:
  • coefficients (np.ndarray) -- A numpy array of STFT magnitude coefficients.

  • transform_name (Optional[str]) -- Transform function name.

  • z_max (Optional[int]) -- Maximum number of channels if input has 3 dimensions.

  • channel_idx (int) -- Boolean that indicates weather to show channel index.

  • collated (bool) -- Boolean that indicates weather to collate multiple figures.

  • experiment (Optional[Experiment]) -- Comet ML experiment instance.

  • epoch (int) -- Training iteration.

  • signal_type (str) -- Signal type.

  • epsilon (float) -- A small value to avoid computation error.

  • cmap (str) -- Colormap.

  • vmax (Optional[float]) -- Maximum value of figure data range.

  • vmin (Optional[float]) -- Minimum value of figure data range.

  • plot_title (str) -- Plot title.

  • show_flag (bool) -- Boolean that indicates weather to show figure.

  • fig_dir (Optional[str]) -- Path to save figure.

  • fig_format (str) -- Format for figure saving.