neurotorch.visualisation package¶
Submodules¶
neurotorch.visualisation.connectome module¶
- neurotorch.visualisation.connectome.visualize_init_final_weights(initial_wights: Any, final_weights: Any, filename: str | None = None, show: bool = False, fig: Figure | None = None, axes: Iterable[Axes] | None = None, **kwargs) Tuple[Figure, Axes] ¶
neurotorch.visualisation.report module¶
neurotorch.visualisation.time_series_visualisation module¶
- class neurotorch.visualisation.time_series_visualisation.Visualise(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = False)¶
Bases:
object
This class is used to visualise the time series without any form of clustering. The time series can be visualised in the following ways:
Animate the time series
Heatmap of the time series
Rigid plot of the time series
Plot all the neuronal activity in one figure
Further visualisation are already added. You can visualise the time series with clustering methods. You can then visualise those clustered time series in scatter/trajectory in their clustered space.
- __init__(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = False)¶
- Parameters:
timeseries – Time series of shape (Batch size, Time Steps, Features).
shape – Shape of the time series. If shape is None, the shape is inferred from the time series. Useful
to identify the dtype of the time series. If the shape is Size, make sure to set the name of the dimensions as you want them to be displayed.
- Note:
If the times series is 3+ dimensional, the first dimension is assumed to be the batch size. The time series will be mean over the batch size.
- animate(weights: ndarray, dt: float = 1.0, step: int = 1, time_interval: float = 1.0, node_size: float = 50, alpha: float | None = None, filename: str | None = None, file_extension: str | None = None, show: bool = False, **kwargs)¶
Animate the time series. The position of the nodes are obtained using the spring layout. Spring-Layout use the Fruchterman-Reingold force-directed algorithm. For more information, please refer to the following documentation of networkx: https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.spring_layout.html
- Parameters:
weights – Weight matrix of size (number of neurons, number of neurons).
dt – Time step between two time steps.
step – Number of time step between two animation frames. example: if step = 4, the animation will play at t = 0, t = 4, t = 8, t = 12 …
time_interval – Time interval between two animation frames (in milliseconds)
node_size – Size of the nodes
alpha – Density of the connections. Small network should have a higher alpha value.
filename – Name of the file to save the animation. If filename is None, the animation will not be saved.
The application imagemagick is required to save the animation. :param file_extension: Extension of the file to save the animation. The available extensions are: mp4 and gif. :param show: If True, the animation will be displayed. :param kwargs: Keyword arguments.
- Keyword Arguments:
fps – Frames per second. Default is 30.
- heatmap(show_axis: bool = True, interpolation: str = 'nearest', cmap: str = 'RdBu_r', v: Tuple[float, float] = (0.0, 1.0), filename: str | None = None, show: bool = False, fig: Figure | None = None, ax: Axes | None = None, **kwargs) Tuple[Figure, Axes] ¶
Plot the heatmap of the time series.
- Parameters:
show_axis – Whether to show the axis or not.
interpolation – Type of interpolation between the time step.
cmap – Colormap of the heatmap.
v – Range of the colorbar.
filename – Name of the file to save the figure. If filename is None, the figure will not be saved.
show – If True, the figure will be displayed.
fig – Figure to plot the heatmap. If fig is None, a new figure will be created.
ax – Axes to plot the heatmap. If ax is None, a new axes will be created.
kwargs – Keyword arguments.
- Keyword Arguments:
figsize – Size of the figure. Default is (12, 8).
dpi – DPI of the figure. Default is 300.
- static number_axes(axes: Sequence[Axes], **kwargs) Sequence[Axes] ¶
Number the axes.
- Parameters:
axes (Sequence[plt.Axes]) – Axes to number.
kwargs – Keyword arguments.
- Keyword Arguments:
num_type (str) – Type of number to display. Can be either “alpha” or “numeric”.
start (int) – Number to start with.
x (float) – x position of the number in the axes coordinate (see ax.transAxes). Default is 0.0.
y (float) – y position of the number in the axes coordinate (see ax.transAxes). Default is 1.2.
fontsize (float) – Font size of the number. Default is 12.
fontweight (str) – Font weight of the number. Default is “bold”.
method – Method to use to number the axes. Available methods are “text”, “title” and “set_title”. The “text” method will add a text to the axes. The “title” method will add the number to the existing title. The “set_title” method will set the title of the axes, so the existing title will be overwritten. Default is “text”.
- Returns:
The axes with the number.
- Return type:
Sequence[plt.Axes]
- plot_single_timeseries_comparison(feature_index: int, ax: Axes, target: Any, spikes: Any | None = None, n_spikes_steps: int | None = None, title: str = '', desc: str = 'Predicted time series', **kwargs) Axes ¶
- plot_timeseries(filename: str | None = None, show: bool = False, fig: Figure | None = None, ax: Axes | None = None, **kwargs) Tuple[Figure, Axes] ¶
Plot all the neuronal activity in one figure.
- Parameters:
filename – Name of the file to save the figure. If filename is None, the figure will not be saved.
show – If True, the figure will be displayed.
fig – Figure to plot the timeseries. If fig is None, a new figure will be created.
ax – Axes to plot the timeseries. If ax is None, a new axes will be created.
kwargs – Keyword arguments.
- Keyword Arguments:
figsize – Size of the figure. Default is (12, 8).
dpi – DPI of the figure. Default is 300.
- plot_timeseries_comparison(target: Any, spikes: Any | None = None, n_spikes_steps: int | None = None, title: str = '', desc: str = 'Prediction', filename: str | None = None, show: bool = False, fig: Figure | None = None, axes: Sequence[Axes] | None = None, **kwargs) Tuple[Figure, Sequence[Axes]] ¶
Plot the timeseries comparison.
- Parameters:
target – Target timeseries. Must be in shape (n_time_steps, n_features).
spikes – Spikes of the latent space. Must be in shape (n_time_steps, n_spikes_steps, n_spikes).
n_spikes_steps – Number of spikes steps. If None, spikes must be None.
title – Title of the plot.
desc – Description of the prediction.
filename – Filename to save the plot to.
show – Whether to show the plot.
fig – Figure to plot on. If None, a new figure is created.
axes – Axes to plot on. If None, new axes are created.
kwargs – Additional keyword arguments.
- Keyword Arguments:
close (bool) – Whether to close the figure after saving. Default: False.
dpi (int) – DPI of the figure. Default: 300.
legend_loc (str) – Location of the legend. Default: “upper right”.
traces_to_show (List[str]) – List of traces to show. Available: [“error_quad”, “best”, “most_var”, “worst”, “typical_<int>”] where <int> is the index of the typical trace, starting from 0. The typical ones refers to the ones that are closest to the mean pVar. Default: [“error_quad”, “best”, “most_var”, “worst”].
numbered (bool) – Whether to number the traces. Default: False.
- Returns:
Figure and axes.
- plot_timeseries_comparison_report(target: Any, spikes: Any | None = None, n_spikes_steps: int | None = None, title: str = '', desc: str = 'Prediction', filename: str | None = None, show: bool = False, fig: Figure | None = None, axes: Sequence[Axes] | None = None, **kwargs) Tuple[Figure, Sequence[Axes]] ¶
- rigidplot(show_axis: bool = False, filename: str | None = None, show: bool = False, fig: Figure | None = None, ax: Axes | None = None, **kwargs) Tuple[Figure, Axes] ¶
Plot the rigid plot of the time series.
- Parameters:
show_axis – Whether to show the axis or not.
filename – Name of the file to save the figure. If filename is None, the figure will not be saved.
show – If True, the figure will be displayed.
fig – Figure to plot the rigid plot. If fig is None, a new figure will be created.
ax – Axes to plot the rigid plot. If ax is None, a new axes will be created.
kwargs – Keyword arguments.
- Keyword Arguments:
figsize – Size of the figure. Default is (12, 8).
dpi – DPI of the figure. Default is 300.
- class neurotorch.visualisation.time_series_visualisation.VisualiseDBSCAN(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = True, eps: float = 25, min_samples: int = 3)¶
Bases:
Visualise
TODO: generalise the class to work with Size and to save the results in a file.
- __init__(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = True, eps: float = 25, min_samples: int = 3)¶
- Parameters:
timeseries – Time series of shape (Batch size, Time Steps, Features).
shape – Shape of the time series. If shape is None, the shape is inferred from the time series. Useful
to identify the dtype of the time series. If the shape is Size, make sure to set the name of the dimensions as you want them to be displayed.
- Note:
If the times series is 3+ dimensional, the first dimension is assumed to be the batch size. The time series will be mean over the batch size.
- class neurotorch.visualisation.time_series_visualisation.VisualiseKMeans(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = False, n_clusters: int = 13, random_state: int = 0)¶
Bases:
Visualise
Visualise the time series using only a K-means algorithm of clustering.
- __init__(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = False, n_clusters: int = 13, random_state: int = 0)¶
Constructor of the class.
- Parameters:
timeseries – Time series of shape (n_time_steps, n_neurons).
shape – Shape of the time series. If shape is None, the shape is inferred from the time series. Useful
to identify the dtype of the time series. If the shape is Size, make sure to set the name of the dimensions as you want them to be displayed. :param apply_zscore: Whether to apply z-score or not. :param n_clusters: Number of clusters. :param random_state: Determines random number generation for centroid initialization. Use an int to make the randomness deterministic
- permute_timeseries(timeseries: ndarray)¶
- class neurotorch.visualisation.time_series_visualisation.VisualisePCA(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = False, n_PC: int = 2)¶
Bases:
Visualise
Visualise the time series using PCA algorithm of dimensionality reduction. PCA is apply on the variable.
TODO: generalise the class to work with Size and to save the results in a file.
- __init__(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = False, n_PC: int = 2)¶
- Parameters:
timeseries – Time series of shape (n_time_steps, n_neurons).
shape – Shape of the time series. If shape is None, the shape is inferred from the time series. Useful
to identify the dtype of the time series. If the shape is Size, make sure to set the name of the dimensions as you want them to be displayed. :param apply_zscore: Whether to apply z-score or not. :param n_PC: Number of principal components.
- scatter_pca(PCs: Tuple[int, ...] = (1, 2), color_sample: bool = False)¶
Plot the scatter plot of the PCA space in 2D or 3D.
- Parameters:
PCs – List of PCs to plot. Always a list of length 2 or 3
color_sample – Whether to color the sample or not.
- trajectory_pca(target: Optional = None, PCs: Tuple[int, int] = (1, 2), with_smooth: bool = True, degree: int = 5, condition: float = 5, reduction: int = 1, traces: str = 'all', fig: Figure | None = None, axes: Axes | None = None, filename: str | None = None, show: bool = True, **kwargs)¶
Plot the trajectory of the PCA space in 2D.
- Parameters:
target – Target timeseries
PCs – List of PCs to plot. Always a list of length 2.
with_smooth – Whether to smooth the trajectory or not.
degree – Degree of the polynomial used for smoothing.
condition – Smoothing condition.
reduction – Number by which we divide the number of samples.
traces – Which traces to plot. Can be “all”, “PCA_space”, “PCA_wrt_time” or a list of indices.
- with_kmeans(n_clusters: int = 13, random_state: int = 0)¶
Apply K-means clustering to the PCA space as coloring.
- Parameters:
n_clusters – Number of clusters.
random_state – Determines random number generation for centroid initialization. Example: VisualisePCA(data).with_kmeans(n_clusters=13, random_state=0).scatter_pca()
- class neurotorch.visualisation.time_series_visualisation.VisualiseUMAP(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = False, n_neighbors: int = 10, min_dist: float = 0.5, n_components: int = 2, umap_transform: Any | None = None, random_state: int | None = None)¶
Bases:
Visualise
TODO: generalise the class to work with Size and to save the results in a file.
- __init__(timeseries: Any, shape: Dimension | Iterable[Dimension] | Size | None = None, apply_zscore: bool = False, n_neighbors: int = 10, min_dist: float = 0.5, n_components: int = 2, umap_transform: Any | None = None, random_state: int | None = None)¶
- Parameters:
timeseries – Time series of shape (Batch size, Time Steps, Features).
shape – Shape of the time series. If shape is None, the shape is inferred from the time series. Useful
to identify the dtype of the time series. If the shape is Size, make sure to set the name of the dimensions as you want them to be displayed.
- Note:
If the times series is 3+ dimensional, the first dimension is assumed to be the batch size. The time series will be mean over the batch size.
- compute_umap_transform(data: Any | None = None)¶
- reduce_timeseries(timeseries: Any)¶
- scatter_umap(UMAPs: Tuple[int, ...] = (1, 2), color_sample: bool = False)¶
Plot the scatter plot of the UMAP space in 2D or 3D. :param UMAPs: List of UMAPs to plot. Always a list of length 2 or 3 :param color_sample: Whether to color the sample or not.
- trajectory_umap(target: Visualise | None = None, UMAPs: Tuple = (1, 2), reduction: int = 1, traces: str = 'all', fig: Figure | None = None, axes: Axes | None = None, filename: str | None = None, show: bool = True, **kwargs)¶
Plot the trajectory of the UMAP space in 2D. TODO: clean up the code
- Parameters:
target – Visualise object to plot the trajectory with.
UMAPs – List of UMAPs to plot. Always a list of length 2.
reduction – Number by which we divide the number of samples.
traces – Which traces to plot. Can be “all”, “UMAP_space” or “UMAP_wrt_time”.
fig – Figure to plot on.
axes – Axes to plot on.
filename – Filename to save the figure to.
show – Whether to show the figure.
- with_kmeans(n_clusters: int = 13, random_state: int = 0)¶
Apply K-means clustering to the PCA space as coloring. :param n_clusters: Number of clusters. :param random_state: Determines random number generation for centroid initialization.
Example: VisualisePCA(data).with_kmeans(n_clusters=13, random_state=0).scatter_umap()