Notebook Utilities

Data

Data (generation) helpers to simplify the code flow of Jupyter notebooks.

Plot

Plotting helpers to simplify the code flow of Jupyter notebooks.

rfml.nbutils.plot.plot_IQ(iq: numpy.ndarray, title: str = None, figsize: Tuple[float, float] = (10.0, 5.0)) → matplotlib.figure.Figure[source]

Plot IQ data in the time dimension.

Parameters
  • iq (np.ndarray) – Complex samples in a 2xN numpy array (IQ x Time)

  • title (str, optional) – Title to put above the plot. Defaults to None.

  • figsize (Tuple[float, float], optional) – Size of the figure to create. Defaults to (10.0, 5.0).

Raises

ValueError – If the IQ array is not 2xN

Returns

Figure that the data was plotted onto (e.g. for saving plot)

Return type

[Figure]

rfml.nbutils.plot.plot_acc_vs_snr(acc_vs_snr: Iterable[float], snr: Iterable[float], title: str = None, figsize: Tuple[float, float] = (10.0, 5.0), annotate: bool = True) → matplotlib.figure.Figure[source]

Plot Classification Accuracy vs Signal-to-Noise Ratio (SNR).

Parameters
  • acc_vs_snr (Iterable[float]) – Classification accuracy at each SNR.

  • snr (Iterable[float]) – Signal-to-Noise Ratios (SNR) that were used for evaluation.

  • title (str, optional) – Title to put above the plot. Defaults to None.

  • figsize (Tuple[float, float], optional) – Size of the figure to create. Defaults to (10.0, 5.0).

  • annotate (bool, optional) – If True then the peak accuracy will be annotated with a horizontal line and with text describing the value. If False, no lines or text are added on top of the plotted data. Defaults to True.

Raises

ValueError – If the lengths of acc_vs_snr and snr do not match

Returns

Figure that the results were plotted onto (e.g. for saving plot)

Return type

Figure

rfml.nbutils.plot.plot_acc_vs_spr(acc_vs_spr: Iterable[float], spr: Iterable[float], title: str = None, figsize: Tuple[float, float] = (10.0, 5.0), annotate: bool = True) → matplotlib.figure.Figure[source]

Plot Classification Accuracy vs Signal-to-Perturbation Ratio (SPR).

Parameters
  • acc_vs_spr (Iterable[float]) – Classification accuracy at each SPR.

  • spr (Iterable[float]) – Signal-to-Perturbation Ratios (SPR) that were used for evaluation.

  • title (str, optional) – Title to put above the plot. Defaults to None.

  • figsize (Tuple[float, float], optional) – Size of the figure to create. Defaults to (10.0, 5.0).

  • annotate (bool, optional) – If True then the peak accuracy will be annotated with a horizontal line and with text describing the value. If False, no lines or text are added on top of the plotted data. Defaults to True.

Raises

ValueError – If the lengths of acc_vs_spr and spr do not match

Returns

Figure that the results were plotted onto (e.g. for saving plot)

Return type

Figure

rfml.nbutils.plot.plot_confusion(cm: numpy.ndarray, labels: List[str], title: str = None, figsize: Tuple[float, float] = (10.0, 5.0), cmap: matplotlib.colors.Colormap = <matplotlib.colors.LinearSegmentedColormap object>) → matplotlib.figure.Figure[source]

Plot a confusion matrix.

Parameters
  • cm (np.ndarray) – NxN array representing the confusion matrix for each true/predicted label pair.

  • labels (List[str]) – Human readable labels for each classification ID.

  • title (str, optional) – Title to put above the plot. Defaults to None.

  • figsize (Tuple[float, float], optional) – Size of the figure to create. Defaults to (10.0, 5.0).

  • cmap (Colormap, optional) – Colormap to use for the Seaborn Heatmap. Defaults to plt.cm.Blues.

Raises
  • ValueError – If the confusion matrix is not square.

  • ValueError – If the number of labels doesn’t match the confusion matrix shape.

Returns

Figure that the results were plotted onto (e.g. for saving plot)

Return type

Figure

rfml.nbutils.plot.plot_convergence(train_loss: Iterable[float], val_loss: Iterable[float], title: str = None, figsize: Tuple[float, float] = (10.0, 5.0), annotate: bool = True) → matplotlib.figure.Figure[source]

Plot the convergence of the training/validation loss vs epochs.

Parameters
  • train_loss (Iterable[float]) – Average training loss for each epoch during training.

  • val_loss (Iterable[float]) – Average validation loss for each epoch during training.

  • title (str, optional) – Title to put above the plot. Defaults to None.

  • figsize (Tuple[float, float], optional) – Size of the figure to create. Defaults to (10.0, 5.0).

  • annotate (bool, optional) – If True, this function will draw lines on the Figure to mark the best validation loss achieved. Defaults to True.

Raises
  • ValueError – If train_loss and val_loss are not the same length

  • ValueError – If train_loss and val_loss don’t have any data (length is 0)

Returns

Figure that the convergence was plotted onto (e.g. for saving plot)

Return type

Figure