Skip to content

Commit

Permalink
Last update at 2023-11-15 20:19:19
Browse files Browse the repository at this point in the history
  • Loading branch information
NengoBones committed Nov 15, 2023
1 parent 1620e0c commit f5124c1
Show file tree
Hide file tree
Showing 262 changed files with 60,167 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: e50ace2b05ef2b4cc5db2904c86d8b23
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added .doctrees/api.doctree
Binary file not shown.
Binary file added .doctrees/contributing.doctree
Binary file not shown.
Binary file added .doctrees/dev-syntax.doctree
Binary file not shown.
Binary file added .doctrees/developer.doctree
Binary file not shown.
Binary file added .doctrees/environment.pickle
Binary file not shown.
Binary file added .doctrees/examples.doctree
Binary file not shown.
Binary file added .doctrees/examples/associative-memory.doctree
Binary file not shown.
Binary file added .doctrees/examples/convolution.doctree
Binary file not shown.
Binary file added .doctrees/examples/custom-module.doctree
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/examples/intro.doctree
Binary file not shown.
Binary file added .doctrees/examples/learning.doctree
Binary file not shown.
Binary file added .doctrees/examples/question-control.doctree
Binary file not shown.
Binary file added .doctrees/examples/question-memory.doctree
Binary file not shown.
Binary file added .doctrees/examples/question.doctree
Binary file not shown.
Binary file added .doctrees/examples/spa-parser.doctree
Binary file not shown.
Binary file added .doctrees/examples/spa-sequence-routed.doctree
Binary file not shown.
Binary file added .doctrees/examples/spa-sequence.doctree
Binary file not shown.
Binary file added .doctrees/examples/vocabulary-casting.doctree
Binary file not shown.
Binary file added .doctrees/getting-started.doctree
Binary file not shown.
Binary file added .doctrees/index.doctree
Binary file not shown.
Binary file added .doctrees/license.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.algebras.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.ast.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.examine.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.exceptions.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.math.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.modules.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.networks.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.operators.doctree
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.testing.doctree
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.types.doctree
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/modules/nengo_spa.vocabulary.doctree
Binary file not shown.
759 changes: 759 additions & 0 deletions .doctrees/nbsphinx/examples/associative-memory.ipynb

Large diffs are not rendered by default.

302 changes: 302 additions & 0 deletions .doctrees/nbsphinx/examples/convolution.ipynb

Large diffs are not rendered by default.

160 changes: 160 additions & 0 deletions .doctrees/nbsphinx/examples/custom-module.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Implementing a custom module\n",
"\n",
"This example demonstrates how custom SPA modules can be created that can take advantage\n",
"of all the features of the SPA syntax. We will adapt the `InputGatedMemory` from\n",
"`nengo`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-15T20:15:28.378489Z",
"iopub.status.busy": "2023-11-15T20:15:28.378054Z",
"iopub.status.idle": "2023-11-15T20:15:28.814483Z",
"shell.execute_reply": "2023-11-15T20:15:28.813940Z"
}
},
"outputs": [],
"source": [
"import nengo\n",
"import nengo_spa as spa"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Implementing a SPA module requires a few steps:\n",
"\n",
"1. Implement a class inheriting from `spa.Network`.\n",
"2. Use `VocabularyOrDimParam` to declare class variables for storing vocublary\n",
"parameters. This will allow the usage of integer dimensions instead of vocabularies\n",
"without any further additions.\n",
"3. Declare inputs and outputs with their respective vocabularies.\n",
"\n",
"Not that parameters in SPA modules should usually be defined as readonly because\n",
"changing them will usually not update the network accordingly."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-15T20:15:28.817439Z",
"iopub.status.busy": "2023-11-15T20:15:28.816988Z",
"iopub.status.idle": "2023-11-15T20:15:28.822749Z",
"shell.execute_reply": "2023-11-15T20:15:28.822243Z"
}
},
"outputs": [],
"source": [
"class GatedMemory(spa.Network):\n",
" # The vocabulary parameter.\n",
" vocab = spa.vocabulary.VocabularyOrDimParam(\"vocab\", default=None, readonly=True)\n",
" # The number of neurons per dimensions.\n",
" neurons_per_dimension = nengo.params.IntParam(\n",
" \"neurons_per_dimension\", default=200, low=1, readonly=True\n",
" )\n",
"\n",
" # Arguments assigned to parameters should be assigned\n",
" # nengo.params.Default as default value. This makes sure they work\n",
" # properly with nengo.Config. It is a good idea to pass on the keyword\n",
" # arguments **kwargs to the spa.Network constructor to allow the user to\n",
" # set the network label etc.\n",
" def __init__(\n",
" self,\n",
" vocab=nengo.params.Default,\n",
" neurons_per_dimension=nengo.params.Default,\n",
" **kwargs,\n",
" ):\n",
" super(GatedMemory, self).__init__(**kwargs)\n",
"\n",
" # Assign parameter values\n",
" # If vocab is an integer dimension, the appropriate Vocabulary\n",
" # instance will assigned to self.vocab.\n",
" self.vocab = vocab\n",
" self.neurons_per_dimension = neurons_per_dimension\n",
"\n",
" # Construct the network\n",
" with self:\n",
" self.mem = nengo.networks.InputGatedMemory(\n",
" self.neurons_per_dimension, self.vocab.dimensions\n",
" )\n",
"\n",
" # Assign inputs to root object for easier referencing\n",
" self.input = self.mem.input\n",
" self.input_gate = self.mem.gate\n",
" self.input_reset = self.mem.reset\n",
" self.output = self.mem.output\n",
"\n",
" # Declare inputs and outputs\n",
" # Use None as vocabulary for scalar inputs/outputs\n",
" self.declare_input(self.input, self.vocab)\n",
" self.declare_input(self.input_gate, None)\n",
" self.declare_input(self.input_reset, None)\n",
" self.declare_output(self.output, self.vocab)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can then use our new module as we would any other module."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-15T20:15:28.825047Z",
"iopub.status.busy": "2023-11-15T20:15:28.824703Z",
"iopub.status.idle": "2023-11-15T20:15:28.909594Z",
"shell.execute_reply": "2023-11-15T20:15:28.909061Z"
}
},
"outputs": [],
"source": [
"dimensions = 32\n",
"\n",
"with spa.Network() as model:\n",
" # The module can be configured\n",
" model.config[GatedMemory].neurons_per_dimension = 150\n",
"\n",
" spa_in = spa.Transcode(\"OKAY\", output_vocab=dimensions)\n",
" gate_in = nengo.Node(lambda t: 1 if t < 0.1 else 0)\n",
"\n",
" g_mem = GatedMemory(dimensions)\n",
"\n",
" # It can be in routing rules\n",
" spa_in >> g_mem\n",
" gate_in >> g_mem.input_gate"
]
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading

0 comments on commit f5124c1

Please sign in to comment.