ngclearn.utils.viz package
Submodules
ngclearn.utils.viz.compartment_plot module
Raster visualization functions/utilities.
- ngclearn.utils.viz.compartment_plot.create_plot(history: Array, ax: Axes | None = None, indices: Sequence[int] | None = None)[source]
Generates a raster plot of a given (binary) spike train (row dimension corresponds to the discrete time dimension).
- Parameters:
history – a numpy binary array of shape (T x number_of_neurons)
ax – a hook/pointer to a currently external plot that this raster plot should be made a sub-figure of
indices – optional indices of neurons (row integer indices) to focus on plotting
s – size of the spike scatter points (Default = 0.5)
c – color of the spike scatter points (Default = black)
ngclearn.utils.viz.compartment_raster module
Raster visualization functions/utilities.
- ngclearn.utils.viz.compartment_raster.create_raster_plot(spike_train: Array, ax: Axes | None = None, indices: Sequence[int] | None = None, s=0.5, c='black')[source]
Generates a raster plot of a given (binary) spike train (row dimension corresponds to the discrete time dimension).
- Parameters:
spike_train – a numpy binary array of shape (T x number_of_neurons)
ax – a hook/pointer to a currently external plot that this raster plot should be made a sub-figure of
indices – optional indices of neurons (row integer indices) to focus on plotting
s – size of the spike scatter points (Default = 0.5)
c – color of the spike scatter points (Default = black)
ngclearn.utils.viz.dim_reduce module
- ngclearn.utils.viz.dim_reduce.extract_pca_latents(vectors)[source]
Projects collection of K vectors (stored in a matrix) to a two-dimensional (2D) visualization space via principal components analysis (PCA). Note that if the input already has a 2D dimensionality, the original input is returned.
- Parameters:
vectors – a matrix/codebook of (K x D) vectors to project
- Returns:
a matrix (K x 2) of projected vectors (to 2D space)
- ngclearn.utils.viz.dim_reduce.extract_tsne_latents(vectors, perplexity=30, n_pca_comp=32, batch_size=500)[source]
Projects collection of K vectors (stored in a matrix) to a two-dimensional (2D) visualization space via the t-distributed stochastic neighbor embedding algorithm (t-SNE). This algorithm also uses PCA to produce an intermediate project to speed up the t-SNE final mapping step. Note that if the input already has a 2D dimensionality, the original input is returned.
- Parameters:
vectors – a matrix/codebook of (K x D) vectors to project
perplexity – the perplexity control factor for t-SNE (Default: 30)
n_pca_comp – number of PCA top components (sorted by eigen-values) to retain/extract before continuing with t-SNE dimensionality reduction
batch_size – number of sampled embedding vectors to use per iteration of online internal PCA
- Returns:
a matrix (K x 2) of projected vectors (to 2D space)
- ngclearn.utils.viz.dim_reduce.plot_latents(code_vectors, labels, plot_fname='2Dcode_plot.jpg', alpha=1.0, cmap=None)[source]
Produces a label-overlaid (label map to distinct colors) scatterplot for visualizing two-dimensional latent codes (produced by either PCA or t-SNE).
- Parameters:
code_vectors – a matrix of shape (K x 2) with vectors to plot/visualize
labels – label values, either of shape (K x 1) of integer values or of shape (K x C) of binary one-hot encodings where C is the number of classes.
plot_fname – /path/to/plot_fname.<suffix> for saving the plot to disk
alpha – alpha intensity level to present colors in scatterplot
cmap – custom color-map to provide
ngclearn.utils.viz.raster module
Raster visualization functions/utilities.
- ngclearn.utils.viz.raster.create_overlay_raster_plot(spike_train, targ_train, Y, idxs, s=1.5, c='black', marker='|', plot_fname=None, indices=None, end_time=100, delay=10, suffix='.jpg')[source]
Generates a raster plot of a given (binary) spike train (row dimension corresponds to the discrete time dimension).
- Parameters:
spike_train – a numpy binary array of shape (T x number_neurons)
ax – a hook/pointer to a currently external plot that this raster plot should be made a sub-figure of
s – size of the spike scatter points (Default = 1.5)
c – color of the spike scatter points (Default = black)
marker – format of the marker used to represent each spike (Default = “|”)
plot_fname – if ax is None, then this is the file name of the raster plot saved to disk (if plot_fname and ax are both None, then default plot_fname will be “raster_plot.png” and saved locally)
indices – optional indices of neurons (row integer indices) to focus on plotting
end_time
delay
suffix – output plot file suffix name to append
- ngclearn.utils.viz.raster.create_raster_plot(spike_train, ax=None, s=0.5, c='black', plot_fname=None, indices=None, tag='', suffix='.jpg', title_font_size=20)[source]
Generates a raster plot of a given (binary) spike train (row dimension corresponds to the discrete time dimension).
- Parameters:
spike_train – a numpy binary array of shape (number_neurons x 1 x T) OR shape (number_neurons x T)
ax – a hook/pointer to a currently external plot that this raster plot should be made a sub-figure of
s – size of the spike scatter points (Default = 1.5)
c – color of the spike scatter points (Default = black)
plot_fname – if ax is None, then this is the file name of the raster plot saved to disk (if plot_fname and ax are both None, then default plot_fname will be “raster_plot.png” and saved locally)
indices – optional indices of neurons (row integer indices) to focus on plotting
tag
suffix – output plot file suffix name to append
ngclearn.utils.viz.spike_plot module
ngclearn.utils.viz.synapse_plot module
Synaptic/receptive field visualization functions/utilities.
- ngclearn.utils.viz.synapse_plot.make_video(f_start, f_end, path, prefix, suffix='.jpg', skip=1, **kwargs)[source]
- ngclearn.utils.viz.synapse_plot.visualize(thetas, sizes, prefix, order=None, suffix='.jpg')[source]
- Parameters:
thetas
sizes
prefix
suffix
- ngclearn.utils.viz.synapse_plot.visualize_frame(frame, path='.', name='tmp', suffix='.jpg', **kwargs)[source]
- ngclearn.utils.viz.synapse_plot.visualize_gif(frames, path='.', name='tmp', suffix='.jpg', **kwargs)[source]