Note

This documentation is for a development version. Click here for the latest stable release (v1.2.0).

# nengo_spa.examine¶

Functions to examine data and vectors produced by SPA.

Functions

 pairs(vocab) Return expressions for all possible combinations to bind vocab’s keys. similarity(data, vocab[, normalize]) Return the similarity between simulation data and Semantic Pointers. text(v, vocab[, minimum_count, …]) Return a human-readable text version of the provided vector.
nengo_spa.examine.similarity(data, vocab, normalize=False)[source]

Return the similarity between simulation data and Semantic Pointers.

Computes the dot products between all Semantic Pointers in the Vocabulary and the simulation data for each timestep. If normalize=True, normalizes all vectors to compute the cosine similarity.

Parameters
• data ((D,) or (T, D) array_like) – The D-dimensional data for T timesteps used for comparison.

• vocab (Vocabulary or array_like) – Vocabulary (or list of vectors) used to calculate the similarity values.

• normalize (bool, optional) – Whether to normalize all vectors, to compute the cosine similarity.

nengo_spa.examine.pairs(vocab)[source]

Return expressions for all possible combinations to bind vocab’s keys.

Examples

>>> vocab = nengo_spa.Vocabulary(32)
>>> vocab.populate('A; B; C')
>>> sorted(nengo_spa.pairs(vocab))
['A*B', 'A*C', 'B*C']

nengo_spa.examine.text(v, vocab, minimum_count=1, maximum_count=None, threshold=0.1, join=';', terms=None, normalize=False)[source]

Return a human-readable text version of the provided vector.

This is meant to give a quick text version of a vector for display purposes. To do this, compute the dot product between the vector and all the terms in the vocabulary. The top few vectors are chosen for inclusion in the text. It will try to only return terms with a match above the threshold, but will always return at least minimum_count and at most maximum_count terms. Terms are sorted from most to least similar.

Parameters
• v (SemanticPointer or array_like) – The vector to convert into text.

• minimum_count (int, optional) – Always return at least this many terms in the text.

• maximum_count (int, optional) – Never return more than this many terms in the text. If None, all terms will be returned.

• threshold (float, optional) – How small a similarity for a term to be ignored.

• join (str, optional) – The text separator to use between terms.

• terms (list, optional) – Only consider terms in this list of strings.

• normalize (bool) – Whether to normalize the vector before computing similarity.