Examples and tutorials
nengo_extras.graphviz.net_diagram(net) |
Create a .dot file showing nodes, ensmbles, and connections. |
nengo_extras.graphviz.obj_conn_diagram(objs, …) |
Create a .dot file showing nodes, ensmbles, and connections. |
nengo_extras.graphviz.net_diagram(net)[source]¶Create a .dot file showing nodes, ensmbles, and connections.
This can be useful for debugging and testing builders that manipulate the model graph before construction.
| Parameters: | net : Network
|
|---|---|
| Returns: | text : string
|
nengo_extras.graphviz.obj_conn_diagram(objs, connections)[source]¶Create a .dot file showing nodes, ensmbles, and connections.
This can be useful for debugging and testing builders that manipulate the model graph before construction.
| Parameters: | objs : list of Nodes and Ensembles
connections : list of Connections
|
|---|---|
| Returns: | text : string
|
nengo_extras.gui.preprocess_display(x[, …]) |
Basic preprocessing that reshapes, transposes, and scales an image |
nengo_extras.gui.image_function(image_shape) |
Make a function to turn an array into a PIL Image. |
nengo_extras.gui.image_string_function(…) |
Make a function to turn an array into an image string. |
nengo_extras.gui.image_html_function(image_shape) |
Make a function to turn an image into HTML to display as an SVG. |
nengo_extras.gui.image_display_function(…) |
Make a function to display images in Nengo GUI |
nengo_extras.gui.preprocess_display(x, transpose=(1, 2, 0), scale=255.0, offset=0.0)[source]¶Basic preprocessing that reshapes, transposes, and scales an image
nengo_extras.gui.image_function(image_shape, preprocess=<function preprocess_display>, **preprocess_args)[source]¶Make a function to turn an array into a PIL Image.
| Parameters: | image_shape : array_like (3,)
preprocess : callable
preprocess_args : dict
|
|---|---|
| Returns: | to_pil : callable (x)
|
nengo_extras.gui.image_string_function(image_shape, format='PNG', preprocess=<function preprocess_display>, **preprocess_args)[source]¶Make a function to turn an array into an image string.
| Parameters: | image_shape : array_like (3,)
format : string
preprocess : callable
preprocess_args : dict
|
|---|---|
| Returns: | string_function : callable (x)
|
See also
nengo_extras.gui.image_html_function(image_shape, preprocess=<function preprocess_display>, **preprocess_args)[source]¶Make a function to turn an image into HTML to display as an SVG.
| Parameters: | image_shape : array_like (3,)
preprocess : callable
preprocess_args : dict
|
|---|---|
| Returns: | html_function : callable (x)
|
See also
nengo_extras.gui.image_display_function(image_shape, preprocess=<function preprocess_display>, **preprocess_args)[source]¶Make a function to display images in Nengo GUI
Examples
>>> u = nengo.Node(nengo.processes.PresentInput(images, 0.1))
>>> display_f = nengo_extras.gui.image_display_function(image_shape)
>>> display_node = nengo.Node(display_f, size_in=u.size_out)
>>> nengo.Connection(u, display_node, synapse=None)
nengo_extras.matplotlib.imshow(image[, ax, …]) |
Nicer version of Matplotlib’s imshow. |
nengo_extras.matplotlib.tile(images[, ax, …]) |
Plot a grid of images |
nengo_extras.matplotlib.compare(image_sets) |
Compare sets of images in a grid. |
nengo_extras.plot_spikes.plot_spikes(t, spikes) |
Plots a spike raster. |
nengo_extras.plot_spikes.preprocess_spikes(t, …) |
Applies a default preprocessing to spike data for plotting. |
nengo_extras.plot_spikes.cluster(t, spikes, …) |
Change order of spike trains to have similar ones close together. |
nengo_extras.plot_spikes.merge(t, spikes, num) |
|
nengo_extras.plot_spikes.sample_by_variance(t, …) |
Samples the spike trains with the highest variance. |
nengo_extras.plot_spikes.sample_by_activity(t, …) |
Samples the spike trains with the highest spiking activity. |
nengo_extras.matplotlib.imshow(image, ax=None, vmin=None, vmax=None, invert=False, interpolation='none', axes=False)[source]¶Nicer version of Matplotlib’s imshow.
nengo_extras.matplotlib.tile(images, ax=None, rows=9, cols=12, grid=False, gridwidth=1, gridcolor='r', **show_params)[source]¶Plot a grid of images
| Parameters: | images : ndarray (n_images, height, width, channels)
|
|---|
nengo_extras.matplotlib.compare(image_sets, ax=None, rows=4, cols=12, grid=True, gridwidth=1, gridcolor='r', **show_params)[source]¶Compare sets of images in a grid.
| Parameters: | image_sets : list of (n_images, height, width, channels) ndarray
|
|---|
nengo_extras.plot_spikes.plot_spikes(t, spikes, contrast_scale=1.0, ax=None, **kwargs)[source]¶Plots a spike raster.
Will use an alpha channel by default which allows to plot colored regions below the spike raster to add highlights. You can set the cmap keyword argument to a different color map like matplotlib.cm.gray_r to get an opaque spike raster.
Utilizes Matplotlib’s imshow.
| Parameters: | t : (n,) array
spikes : (n, m) array
contrast_scale : float, optional
ax : matplotlib.axes.Axes, optional
kwargs : dict
|
|---|---|
| Returns: | matplotlib.image.AxesImage
|
nengo_extras.plot_spikes.preprocess_spikes(t, spikes, num=50, sample_size=200, sample_filter_width=0.02, cluster_filter_width=0.002)[source]¶Applies a default preprocessing to spike data for plotting.
This will first sample by variance, then cluster the spike trains, and
finally merge them. See sample_by_variance, cluster, and merge for
details.
| Parameters: | t : (n,) array
spikes : (n, m) array
num : int, optional
sample_size : int, optional
sample_filter_width : float, optional
cluster_filter_width : float, optional
|
|---|---|
| Returns: | tuple (t, selected_spikes)
|
nengo_extras.plot_spikes.cluster(t, spikes, filter_width)[source]¶Change order of spike trains to have similar ones close together.
Requires SciPy.
| Parameters: | t : (n,) array
spikes : (n, m) array
filter_width : float
|
|---|---|
| Returns: | tuple (t, selected_spikes)
|
nengo_extras.plot_spikes.sample_by_variance(t, spikes, num, filter_width)[source]¶Samples the spike trains with the highest variance.
Requires SciPy.
| Parameters: | t : (n,) array
spikes : (n, m) array
num : int
filter_width : float
|
|---|---|
| Returns: | tuple (t, selected_spikes)
|
nengo_extras.plot_spikes.sample_by_activity(t, spikes, num, blocksize=None)[source]¶Samples the spike trains with the highest spiking activity.
| Parameters: | t : (n,) array
spikes : (n, m) array
num : int
blocksize : int, optional
|
|---|---|
| Returns: | tuple (t, selected_spikes)
|
nengo_extras.deepview.ImageSelector(parent, …) |
Choose between images with left and right arrows |
nengo_extras.deepview.ScrollCanvasFrame(parent) |
|
nengo_extras.deepview.ScrollWindow(*args, …) |
Scroll a single window |
nengo_extras.deepview.VerticalImageFrame(…) |
|
nengo_extras.deepview.Viewer(images, …) |
nengo_extras.deepview.ImageSelector(parent, **kwargs)[source]¶Choose between images with left and right arrows
Attributes
| image_function | (callable) Turn an array into a PIL.Image. Can be generated by nengo_extras.gui.image_function. |
| resample | (int) Resampling mode for PIL.Image.resize. |
nengo_extras.deepview.ScrollCanvasFrame(parent, vertical=False, horizontal=False, **kwargs)[source]¶nengo_extras.gexf.DispatchTable([parent]) |
A descriptor to dispatch to other methods depending on argument type. |
nengo_extras.gexf.HierarchicalLabeler() |
Obtains labels for objects in a Nengo network. |
nengo_extras.gexf.GexfConverter([labeler, …]) |
Converts Nengo models into GEXF files. |
nengo_extras.gexf.CollapsingGexfConverter([…]) |
Converts Nengo models into GEXF files with some collapsed networks. |
nengo_extras.gexf.Attr(id, type, default) |
Create new instance of Attr(id, type, default) |
nengo_extras.gexf.DispatchTable(parent=None)[source]¶A descriptor to dispatch to other methods depending on argument type.
How to use: assign the descriptor to a class attribute and use the
register decorator to declare which functions to dispatch to
for specific types:
class MyClass(object):
dispatch = DispatchTable()
@dispatch.register(TypeA)
def handle_type_a(self, obj_of_type_a):
# ...
@dispatch.register(TypeB)
def handle_type_b(self, obj_of_type_b):
# ...
To then call the method for the appropriate type:
inst = MyClass()
inst.dispatch(obj_of_type_a_or_b)
If multiple methods would match (e.g. if TypeB inherits from TypeA), the most specific method will be used (to be precise: the first type in the method resolution order with a registered method will be used).
The DispatchTable descriptor accepts another DispatchTable as argument which will be used as a fallback. This allows to inherit the dispatch table and selectively overwrite methods like so:
class Inherited(MyClass):
dispatch = DispatchTable(MyClass.dispatch)
@dispatch.register(TypeA)
def alternate_type_a_handler(self, obj_of_type_a):
# ...
Finally, dispatch methods can also be changed on a per-instance basis:
inst.dispatch.register(TypeA, inst_type_a_handler)
nengo_extras.gexf.HierarchicalLabeler[source]¶Obtains labels for objects in a Nengo network.
The names will include the network hierarchy.
Usage example:
labels = HierarchicalLabeler().get_labels(model)
nengo_extras.gexf.GexfConverter(labeler=None, hierarchical=False)[source]¶Converts Nengo models into GEXF files.
This can be loaded in Gephi for visualization of the model graph.
Links:
This class can be inherited from to customize the conversion or
alternatively the dispatch table can be changed on a
per-instance basis.
Note that probes are currently not included in the graph.
The following attributes will be stored on graph nodes:
The following attributes will be stored on graph edges:
| Parameters: | labeler : optional
hierarchical : bool, optional (default: False)
|
|---|
Examples
Basic usage to write a GEXF file:
GexfConverter().convert(model).write('model.gexf')
convert(model)[source]¶Convert a model to GEXF format.
| Returns: | xml.etree.ElementTree.ElementTree
|
|---|
make_document(model)[source]¶Create the GEXF XML document from model.
This method is exposed so it can be overwritten in inheriting classes.
Invoke convert instead of this method to convert a model.
| Returns: | xml.etree.ElementTree.ElementTree
|
|---|
make_attr_defs(cls, defs)[source]¶Generate an attribute definition block.
| Parameters: | cls : str
defs : dict
|
|---|---|
| Returns: | xml.etree.ElementTree.Element |
make_attrs(defs, attrs)[source]¶Generates a block of attribute values.
| Parameters: | defs : dict
attrs : dict
|
|---|---|
| Returns: | xml.etree.ElementTree.Element |
make_edge(obj, source, target, **attrs)[source]¶Edge for obj from source to target with attributes attrs.
get_node_obj(obj)[source]¶Get an object with a corresponding graph node related to obj.
For certain objects like nengo.ensemble.Neurons or
nengo.connection.LearningRule no graph node will be created. This
function will resolve such an object to a related object that has a
corresponding graph node (e.g., the ensemble for a neurons object or
the pre object for a learning rule).
In GexfConverter this is used to make sure connections are between
the correct nodes and do not introduce unrelated dangling nodes.
nengo_extras.gexf.CollapsingGexfConverter(to_collapse=None, labeler=None, hierarchical=False)[source]¶Converts Nengo models into GEXF files with some collapsed networks.
See GexfConverter for general information on conversion to GEXF files.
This class will collapse certain networks to a single node in the
conversion.
| Parameters: | to_collapse : sequence, optional
labeler : optional
hierarchical : bool, optional (default: False)
|
|---|