ngclearn.utils.viz package

Submodules

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)[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)

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')[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

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')[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)

  • 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.spike_plot.plot_spiking_neuron(curr, mem, spike, ref, dt, thr_line=False, title=False, min_mem_val=0.0, max_mem_val=1.25, fname=None)[source]

Simple plotting function for visualizing the trajectory of a single neuron (where its input electrical current, membrane potential value, output spike readings, and refractory variable states have been recorded into arrays).

This is particularly useful for single neuronal dynamics demonstrations and analyses.

Parameters:
  • curr – the recorded electrical current (over T steps)

  • mem – the recorded membrane potential (over T steps)

  • spike – the recorded spike train (over T steps)

  • ref – the recorded refractory state value (over T steps)

  • dt – the integration time constant

  • thr_line – optional vertical threshold line to plot for voltage

  • title – the title of the plot

  • min_mem_val – minimum value bound on membrane potential subplot (min of y-axis)

  • max_mem_val – maximum value bound on membrane potential subplot (max of y-axis)

  • fname – the filename to save this plot as, i.e., /path/to/name.png (Default: lif_analysis.png)

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)[source]
ngclearn.utils.viz.synapse_plot.visualize(thetas, sizes, prefix, 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]
ngclearn.utils.viz.synapse_plot.visualize_labels(thetas, sizes, prefix, space_width=None, widths=None, suffix='.jpg')[source]
Parameters:
  • thetas

  • sizes

  • prefix

  • space_width

  • widths

  • suffix

Module contents