├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .jscs.json ├── CHANGES.rst ├── CONTRIBUTORS.rst ├── LICENSE.rst ├── MANIFEST.in ├── README.rst ├── docs ├── codeflow.rst ├── dev_guide.rst ├── getting_started.rst ├── index.rst └── workflow.rst ├── examples ├── 2d.py ├── basic.py ├── lines.py ├── net.ipynb ├── net.py └── spa.py ├── nengo_gui ├── __init__.py ├── _vendor │ ├── README.rst │ ├── __init__.py │ ├── cookies.py │ ├── requirements.txt │ └── test_cookies.py ├── compat.py ├── completion.py ├── components │ ├── __init__.py │ ├── ace_editor.py │ ├── component.py │ ├── editor.py │ ├── htmlview.py │ ├── netgraph.py │ ├── pointer.py │ ├── progress.py │ ├── raster.py │ ├── sim_control.py │ ├── slider.py │ ├── spa_plot.py │ ├── spa_similarity.py │ ├── spike_grid.py │ ├── value.py │ ├── voltage.py │ └── xyvalue.py ├── config.py ├── conftest.py ├── examples │ ├── basics │ │ ├── 2d_representation.py │ │ ├── addition.py │ │ ├── combining.py │ │ ├── communication_channel.py │ │ ├── ensemble_array.py │ │ ├── html.py │ │ ├── html.py.cfg │ │ ├── inhibitory_gating.py │ │ ├── many_neurons.py │ │ ├── multiplication.py │ │ ├── single_neuron.py │ │ ├── squaring.py │ │ └── two_neurons.py │ ├── default.py │ ├── hbb_tutorials │ │ ├── chapter1 │ │ │ ├── singleneuron.py │ │ │ └── singleneuron.py.cfg │ │ ├── chapter2 │ │ │ ├── 1-scalars.py │ │ │ ├── 1-scalars.py.cfg │ │ │ ├── 2-vectors.py │ │ │ └── 2-vectors.py.cfg │ │ ├── chapter3 │ │ │ ├── 1-addition.py │ │ │ ├── 1-addition.py.cfg │ │ │ ├── 2-arbitrary_linear.py │ │ │ ├── 2-arbitrary_linear.py.cfg │ │ │ ├── 3-non_linear.py │ │ │ └── 3-non_linear.py.cfg │ │ ├── chapter4 │ │ │ ├── 1-structure.py │ │ │ ├── 1-structure.py.cfg │ │ │ ├── 2-spa_structure.py │ │ │ └── 2-spa_structure.py.cfg │ │ ├── chapter5 │ │ │ ├── 1-question.py │ │ │ ├── 1-question.py.cfg │ │ │ ├── 2-spa_question.py │ │ │ ├── 2-spa_question.py.cfg │ │ │ ├── 3-question-memory.py │ │ │ ├── 3-question-memory.py.cfg │ │ │ ├── 4-spa_question-memory.py │ │ │ ├── 4-spa_question-memory.py.cfg │ │ │ ├── 5-question-control.py │ │ │ ├── 5-question-control.py.cfg │ │ │ ├── 6-spa_question-control.py │ │ │ └── 6-spa_question-control.py.cfg │ │ ├── chapter6 │ │ │ ├── learn.py │ │ │ └── learn.py.cfg │ │ ├── chapter7 │ │ │ ├── 1-spa_sequence.py │ │ │ ├── 1-spa_sequence.py.cfg │ │ │ ├── 2-spa_sequencerouted.py │ │ │ ├── 2-spa_sequencerouted.py.cfg │ │ │ ├── 3-spa_sequencerouted_cleanup.py │ │ │ ├── 3-spa_sequencerouted_cleanup.py.cfg │ │ │ ├── 4-spa_sequencerouted_cleanupAll.py │ │ │ └── 4-spa_sequencerouted_cleanupAll.py.cfg │ │ ├── chapter8 │ │ │ ├── 2D_decision_integrator.py │ │ │ └── 2D_decision_integrator.py.cfg │ │ └── read_me.py │ ├── recurrent │ │ ├── controlled_integrator.py │ │ ├── controlled_oscillator.py │ │ ├── integrator.py │ │ ├── lorenz_attractor.py │ │ └── oscillator.py │ └── tutorial │ │ ├── 00-intro.py │ │ ├── 00-intro.py.cfg │ │ ├── 01-one-neuron.py │ │ ├── 01-one-neuron.py.cfg │ │ ├── 02-two-neurons.py │ │ ├── 02-two-neurons.py.cfg │ │ ├── 03-many-neurons.py │ │ ├── 03-many-neurons.py.cfg │ │ ├── 04-connecting-neurons.py │ │ ├── 04-connecting-neurons.py.cfg │ │ ├── 05-computing.py │ │ ├── 05-computing.py.cfg │ │ ├── 06-adding.py │ │ ├── 06-adding.py.cfg │ │ ├── 07-multiple-dimensions.py │ │ ├── 07-multiple-dimensions.py.cfg │ │ ├── 08-combining.py │ │ ├── 08-combining.py.cfg │ │ ├── 09-multiplication.py │ │ ├── 09-multiplication.py.cfg │ │ ├── 10-transforms.py │ │ ├── 10-transforms.py.cfg │ │ ├── 11-memory.py │ │ ├── 11-memory.py.cfg │ │ ├── 12-differential-eqns.py │ │ ├── 12-differential-eqns.py.cfg │ │ ├── 13-oscillators.py │ │ ├── 13-oscillators.py.cfg │ │ ├── 14-controlled-oscillator.py │ │ ├── 14-controlled-oscillator.py.cfg │ │ ├── 15-lorenz.py │ │ ├── 15-lorenz.py.cfg │ │ ├── 16-ensemble-properties.py │ │ ├── 16-ensemble-properties.py.cfg │ │ ├── 17-neuron-models.py │ │ ├── 17-neuron-models.py.cfg │ │ ├── 18-networks.py │ │ ├── 18-networks.py.cfg │ │ ├── 19-spa.py │ │ ├── 19-spa.py.cfg │ │ ├── 20-spa-actions.py │ │ ├── 20-spa-actions.py.cfg │ │ ├── 21-spa-sequence.py │ │ ├── 21-spa-sequence.py.cfg │ │ ├── 22-spa-sequence-controlled.py │ │ ├── 22-spa-sequence-controlled.py.cfg │ │ ├── 23-spa-binding.py │ │ ├── 23-spa-binding.py.cfg │ │ ├── 24-spa-unbinding.py │ │ ├── 24-spa-unbinding.py.cfg │ │ ├── 25-spa-parse.py │ │ └── 25-spa-parse.py.cfg ├── exec_env.py ├── grandalf │ ├── LICENSE │ ├── README.rst │ ├── __init__.py │ ├── graphs.py │ ├── layouts.py │ ├── nx.py │ ├── routing.py │ └── utils.py ├── gui.py ├── guibackend.py ├── ipython.py ├── jupyter.py ├── layout.py ├── main.py ├── modal_js.py ├── namefinder.py ├── nossl.py ├── page.py ├── password.py ├── seed_generation.py ├── server.py ├── static │ ├── ace.css │ ├── ace.js │ ├── components │ │ ├── 2d_axes.js │ │ ├── component.js │ │ ├── htmlview.js │ │ ├── image.js │ │ ├── netgraph.css │ │ ├── netgraph.js │ │ ├── netgraph_conn.js │ │ ├── netgraph_item.js │ │ ├── pointer.css │ │ ├── pointer.js │ │ ├── progress.js │ │ ├── raster.css │ │ ├── raster.js │ │ ├── slider.css │ │ ├── slider.js │ │ ├── slidercontrol.js │ │ ├── spa_similarity.css │ │ ├── spa_similarity.js │ │ ├── time_axes.js │ │ ├── value.css │ │ ├── value.js │ │ ├── xy_axes.js │ │ ├── xyvalue.css │ │ └── xyvalue.js │ ├── config.js │ ├── data_to_csv.js │ ├── datastore.js │ ├── favicon.ico │ ├── hotkeys.js │ ├── info_line.js │ ├── lib │ │ ├── css │ │ │ └── bootstrap.min.css │ │ ├── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ └── glyphicons-halflings-regular.woff2 │ │ └── js │ │ │ ├── ace-src-min │ │ │ ├── ace.js │ │ │ ├── ext-language_tools.js │ │ │ ├── ext-searchbox.js │ │ │ └── mode-python.js │ │ │ ├── bootstrap.min.js │ │ │ ├── d3.v3.min.js │ │ │ ├── interact-1.2.6.js │ │ │ ├── jquery-2.1.3.min.js │ │ │ ├── jquery-ui-1.9.2.min.js │ │ │ ├── jqueryFileTree │ │ │ ├── images │ │ │ │ ├── directory.png │ │ │ │ ├── file.png │ │ │ │ ├── folder_open.png │ │ │ │ ├── scriptgen.png │ │ │ │ └── spinner.gif │ │ │ ├── jqueryFileTree.css │ │ │ └── jqueryFileTree.js │ │ │ └── validator.js │ ├── main.css │ ├── menu.css │ ├── menu.js │ ├── modal.css │ ├── modal.js │ ├── nengo.css │ ├── nengo.js │ ├── side_menu.css │ ├── side_menu.js │ ├── sim_control.css │ ├── sim_control.js │ ├── test │ │ └── datastore_test.js │ ├── tooltips.css │ ├── tooltips.js │ ├── top_toolbar.css │ ├── top_toolbar.js │ └── viewport.js ├── static_plots.py ├── templates │ └── page.html ├── testing_tools.py ├── tests │ ├── test_basic_functionality.py │ ├── test_configuration.py │ ├── test_data_to_csv.py │ ├── test_dynamics.py │ ├── test_netgraph.py │ ├── test_pdb_error.py │ ├── test_save_as.py │ ├── test_server.py │ ├── test_spa.py │ └── test_tutorial_basic.py ├── url.py ├── user_action.py ├── version.py └── viz.py ├── pyproject.toml └── setup.py /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | --- 5 | 6 | **Describe the bug** 7 | 8 | A clear and concise description of what the bug is. 9 | 10 | **To reproduce** 11 | 12 | Steps to reproduce the behavior: 13 | 1. Go to '...' 14 | 2. Click on '....' 15 | 3. Scroll down to '....' 16 | 4. See error 17 | 18 | **Expected behavior** 19 | 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Versions** 27 | 28 | - OS: [e.g. Windows 10] 29 | - Browser: [e.g. chrome, safari] 30 | - Nengo GUI: [e.g. 0.3.0, latest master] 31 | - Other: [e.g. Nengo core v2.8.0] 32 | 33 | **Additional context** 34 | 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | --- 5 | 6 | **Is your feature request related to a problem? Please describe.** 7 | 8 | A clear and concise description of what the problem is. 9 | Ex. I'm always frustrated when [...] 10 | 11 | **Describe the solution you'd like** 12 | 13 | A clear and concise description of what you want to happen. 14 | 15 | **Describe alternatives you've considered** 16 | 17 | A clear and concise description of any alternative solutions 18 | or features you've considered. 19 | 20 | **Additional context** 21 | 22 | Add any other context or screenshots about the feature request here. 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | lib64/ 17 | parts/ 18 | sdist/ 19 | var/ 20 | *.egg-info/ 21 | .installed.cfg 22 | *.egg 23 | *.dist-info/ 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Django stuff: 48 | *.log 49 | 50 | # Sphinx documentation 51 | docs/_build/ 52 | 53 | # PyBuilder 54 | target/ 55 | 56 | # Mac OS X stuff 57 | .DS_Store 58 | 59 | # nengo_viz specific 60 | *.py.cfg 61 | .ipynb_checkpoints 62 | 63 | # Vagrant 64 | .vagrant 65 | Vagrantfile 66 | 67 | # Vim 68 | *.swp 69 | -------------------------------------------------------------------------------- /.jscs.json: -------------------------------------------------------------------------------- 1 | { 2 | "requireCurlyBraces": [ 3 | "if", 4 | "else", 5 | "for", 6 | "while", 7 | "do", 8 | "try", 9 | "catch" 10 | ], 11 | "requireOperatorBeforeLineBreak": true, 12 | "maximumLineLength": { 13 | "value": 80, 14 | "allExcept": ["comments", "regex"] 15 | }, 16 | "validateIndentation": 4, 17 | 18 | "disallowMultipleLineStrings": true, 19 | "disallowMixedSpacesAndTabs": true, 20 | "disallowTrailingWhitespace": true, 21 | "disallowSpaceAfterPrefixUnaryOperators": true, 22 | "disallowMultipleVarDecl": true, 23 | "disallowKeywordsOnNewLine": ["else"], 24 | 25 | "requireSpaceAfterKeywords": [ 26 | "if", 27 | "else", 28 | "for", 29 | "while", 30 | "do", 31 | "switch", 32 | "return", 33 | "try", 34 | "catch" 35 | ], 36 | "requireSpaceBeforeBinaryOperators": [ 37 | "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=", 38 | "&=", "|=", "^=", "+=", 39 | 40 | "+", "-", "*", "/", "%", "<<", ">>", ">>>", "&", 41 | "|", "^", "&&", "||", "===", "==", ">=", 42 | "<=", "<", ">", "!=", "!==" 43 | ], 44 | "requireSpaceAfterBinaryOperators": true, 45 | "requireSpacesInConditionalExpression": true, 46 | "requireSpaceBeforeBlockStatements": true, 47 | "requireSpacesInForStatement": true, 48 | "requireLineFeedAtFileEnd": true, 49 | "requireSpacesInFunctionExpression": { 50 | "beforeOpeningCurlyBrace": true 51 | }, 52 | "disallowSpacesInAnonymousFunctionExpression": { 53 | "beforeOpeningRoundBrace": true 54 | }, 55 | "disallowSpacesInsideObjectBrackets": "all", 56 | "disallowSpacesInsideArrayBrackets": "all", 57 | "disallowSpacesInsideParentheses": false, 58 | 59 | "disallowMultipleLineBreaks": true, 60 | "disallowNewlineBeforeBlockStatements": true, 61 | "disallowKeywords": ["with"], 62 | "disallowSpacesInFunctionExpression": { 63 | "beforeOpeningRoundBrace": true 64 | }, 65 | "disallowSpacesInFunctionDeclaration": { 66 | "beforeOpeningRoundBrace": true 67 | }, 68 | "disallowSpacesInCallExpression": true, 69 | "disallowSpaceAfterObjectKeys": true, 70 | "requireSpaceBeforeObjectValues": true, 71 | "requireCapitalizedConstructors": true, 72 | "requireDotNotation": true, 73 | "requireSemicolons": true, 74 | "validateParameterSeparator": ", ", 75 | 76 | "jsDoc": { 77 | "checkAnnotations": "closurecompiler", 78 | "checkParamNames": true, 79 | "requireParamTypes": true, 80 | "checkRedundantParams": true, 81 | "checkReturnTypes": true, 82 | "checkRedundantReturns": true, 83 | "requireReturnTypes": true, 84 | "checkTypes": true, 85 | "checkRedundantAccess": true, 86 | "requireNewlineAfterDescription": true 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /CONTRIBUTORS.rst: -------------------------------------------------------------------------------- 1 | ********************** 2 | Nengo GUI contributors 3 | ********************** 4 | 5 | This is a list of people who have contributed to Nengo GUI. 6 | Note that this is not the list of copyright holders; 7 | Applied Brain Research Inc. holds the copyright to 8 | all Nengo GUI code, except for code that is used under 9 | various licenses, as described in the ``LICENSE.rst`` file. 10 | 11 | By adding your name to this file, you are agreeing 12 | to the Contributor Assignment Agreement found in 13 | the ``LICENSE.rst`` file. If you agree, then add yourself 14 | to the file like so:: 15 | 16 | - Name 17 | 18 | Please keep this list sorted alphabetically by first name. 19 | 20 | - Aaron Voelker 21 | - Andreas Stöckel 22 | - Andrew Mundy 23 | - Brent Komer 24 | - Chris Eliasmith 25 | - Christopher Chan 26 | - Eric Hunsberger 27 | - Jan Gosmann 28 | - Petrut Bogdan 29 | - Rees Simmons 30 | - Sean Aubin 31 | - Sugandha Sharma 32 | - Terry Stewart 33 | - Travis DeWolf 34 | - Trevor Bekolay 35 | - Xuan Choo 36 | - Ziying Zhang 37 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.md 2 | include *.json 3 | include *.py 4 | include *.rst 5 | include nengo_gui/grandalf/LICENSE 6 | recursive-include docs *.rst 7 | recursive-include examples *.ipynb 8 | recursive-include examples *.py 9 | recursive-include nengo_gui *.cfg 10 | recursive-include nengo_gui *.css 11 | recursive-include nengo_gui *.eot 12 | recursive-include nengo_gui *.gif 13 | recursive-include nengo_gui *.html 14 | recursive-include nengo_gui *.ico 15 | recursive-include nengo_gui *.js 16 | recursive-include nengo_gui *.png 17 | recursive-include nengo_gui *.py 18 | recursive-include nengo_gui *.rst 19 | recursive-include nengo_gui *.svg 20 | recursive-include nengo_gui *.ttf 21 | recursive-include nengo_gui *.txt 22 | recursive-include nengo_gui *.woff 23 | recursive-include nengo_gui *.woff2 24 | -------------------------------------------------------------------------------- /docs/codeflow.rst: -------------------------------------------------------------------------------- 1 | ************************** 2 | How Nengo GUI's Code Works 3 | ************************** 4 | 5 | For details on how all the code of Nengo GUI is organised and interacts with 6 | itself, please check out this presentation: `https://docs.google.com/presentation/d/1XtAv3GDW2f7pRjKDJcRmqgwWxSQRXcsDZxUiK4hRrjs/edit?usp=sharing` by Sean Aubin. 7 | -------------------------------------------------------------------------------- /docs/dev_guide.rst: -------------------------------------------------------------------------------- 1 | *************** 2 | Developer Guide 3 | *************** 4 | 5 | If you would like access the the development version of ``nengo_gui``, 6 | you can download it from GitHub. 7 | 8 | .. code:: shell 9 | 10 | git clone https://github.com/nengo/nengo-gui.git 11 | cd nengo-gui 12 | python setup.py develop --user 13 | 14 | The following sections will help you understand how to contribute to Nengo GUI 15 | development. 16 | 17 | .. toctree:: 18 | :maxdepth: 2 19 | codeflow 20 | workflow 21 | -------------------------------------------------------------------------------- /docs/getting_started.rst: -------------------------------------------------------------------------------- 1 | *************** 2 | Getting Started 3 | *************** 4 | 5 | Installation 6 | ============ 7 | 8 | The simplest way to install is with the standard Python installation system: 9 | 10 | .. code:: shell 11 | 12 | pip install nengo-gui 13 | 14 | Running Nengo GUI 15 | ================= 16 | 17 | There are two ways to run Nengo GUI. First, you can use it from the command 18 | line by running the installed script: 19 | 20 | .. code:: shell 21 | 22 | nengo 23 | 24 | If you specify a file to load, ``nengo`` will do so: 25 | 26 | .. code:: shell 27 | 28 | nengo myfile.py 29 | 30 | Alternatively, you can start Nengo GUI manually from within your code. 31 | To do so, add this to the bottom of your file that defines your Nengo model. 32 | 33 | .. code:: python 34 | 35 | import nengo_gui 36 | nengo_gui.GUI(__file__).start() 37 | 38 | Basic usage 39 | =========== 40 | 41 | The graph of the Nengo network should appear. Rectangles are nengo.Nodes, 42 | ellipses are nengo.Ensembles, and rounded rectangles are nengo.Networks. 43 | 44 | Items can be dragged to move them and resized by dragging their edge or via 45 | the scroll wheel. 46 | 47 | To start (or continue) the simulation, click the play button in the lower 48 | right. A spinning gear icon indicates the model is in the process of being 49 | built (or re-built after new graphs are added). 50 | 51 | Clicking on an item will show a menu of options, depending on what you 52 | have clicked on. Here are some of the standard options for network items: 53 | 54 | - value: show a graph of the decoded output value over time 55 | - xy-value: show a state-space plot of two decoded values against each other 56 | - spikes: show the spiking activity of the nengo.Ensemble 57 | - slider: show sliders that let you adjust the value in a nengo.Node 58 | - expand/collapse: reveal or hide the insides of a nengo.Network 59 | 60 | Once you have graphs, you can also click on them to adjust their options. For 61 | example: 62 | 63 | - set range: adjust the limits of the graph 64 | - show label/hide label: whether to show the title at the top of the graph 65 | - remove: get rid of the graph 66 | 67 | The graphs record their data from previous time steps. You can show this 68 | previous data by dragging the transparent area in the time axis at the 69 | bottom (beside the play button). 70 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | ********* 2 | Nengo GUI 3 | ********* 4 | 5 | Nengo GUI is an HTML5 interactive visualizer for 6 | `Nengo `_. 7 | It lets you see the structure of a Nengo model, plot spiking activity and 8 | decoded representations among other visualizations, and adjust the inputs while 9 | the model is running. 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | getting_started 15 | examples 16 | user_guide 17 | dev_guide 18 | 19 | Indices and tables 20 | ================== 21 | 22 | * :ref:`genindex` 23 | * :ref:`modindex` 24 | * :ref:`search` -------------------------------------------------------------------------------- /docs/workflow.rst: -------------------------------------------------------------------------------- 1 | ******************** 2 | Development workflow 3 | ******************** 4 | 5 | Development happens on `Github `_. 6 | Feel free to fork any of our repositories and send a pull request! 7 | However, note that we ask contributors to sign 8 | `a copyright assignment agreement 9 | `_. 10 | 11 | Code style: Python 12 | ================== 13 | 14 | We adhere to 15 | `PEP8 `_, 16 | and use ``flake8`` to automatically check for adherence on all commits. 17 | 18 | We use ``numpydoc`` and 19 | `NumPy guidelines `_ 20 | for docstrings, as they are a bit nicer to read in plain text, 21 | and produce decent output with Sphinx. 22 | 23 | Code style: JavaScript 24 | ====================== 25 | 26 | We adhere to a modified version of the Google style guide using 27 | `JSCS `_. Our custom rules for JSCS are saved in the 28 | ``jscs.json`` file in the root of this repository. 29 | 30 | Unit testing 31 | ============ 32 | 33 | We use `PyTest `_ 34 | to run our Python unit tests and `Mocha `_ 35 | for JavaScript. Eventually these tests will run 36 | on `Travis-CI `_. Please contribute unit tests 37 | where possible. 38 | 39 | Git 40 | === 41 | 42 | We use a pretty strict ``git`` workflow 43 | to ensure that the history of the ``master`` branch 44 | is clean and readable. 45 | Every commit in the ``master`` branch should pass 46 | unit testing, including PEP8. 47 | 48 | Developers should never edit code on the ``master`` branch. 49 | When changing code, create a new topic branch 50 | that implements your new feature or fixes a bug. 51 | When your branch is ready to be reviewed, 52 | push it to Github and create a pull request. 53 | One or more people will review your pull request, 54 | and over one or many cycles of review, 55 | your PR will be accepted or rejected. 56 | We almost never reject PRs, 57 | though we do let them languish in the limbo 58 | of the PR queue if we're not sure 59 | if they're quite ready yet. 60 | 61 | Terry Stewart primarily repsonsible for reviewing your work, 62 | and merging it into the ``master`` branch when it's been accepted. 63 | He is the only person allowed to push to the ``master`` branch. 64 | 65 | If you have any questions about our workflow, 66 | or how you can best climb the learning curve 67 | that Nengo GUI and ``git`` present, please contact 68 | the development lead, `Sean `_. 69 | -------------------------------------------------------------------------------- /examples/2d.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | import numpy as np 3 | 4 | model = nengo.Network() 5 | with model: 6 | stimulus = nengo.Node(lambda t: (np.sin(t), np.cos(t))) 7 | ens = nengo.Ensemble(n_neurons=1000, dimensions=2) 8 | nengo.Connection(stimulus, ens) 9 | 10 | if __name__ == "__main__": 11 | import nengo_gui 12 | 13 | nengo_gui.GUI(__file__).start() 14 | -------------------------------------------------------------------------------- /examples/basic.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | import numpy as np 3 | 4 | model = nengo.Network() 5 | with model: 6 | stimulus_A = nengo.Node([1], label="stim A") 7 | stimulus_B = nengo.Node(lambda t: np.sin(2 * np.pi * t)) 8 | ens = nengo.Ensemble(n_neurons=1000, dimensions=2) 9 | result = nengo.Ensemble(n_neurons=50, dimensions=1) 10 | nengo.Connection(stimulus_A, ens[0]) 11 | nengo.Connection(stimulus_B, ens[1]) 12 | nengo.Connection(ens, result, function=lambda x: x[0] * x[1], synapse=0.01) 13 | 14 | if __name__ == "__main__": 15 | import nengo_gui 16 | 17 | nengo_gui.GUI(__file__).start() 18 | -------------------------------------------------------------------------------- /examples/lines.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | import numpy as np 3 | 4 | D = 9 5 | cols = int(np.sqrt(D)) 6 | size = 150 7 | 8 | model = nengo.Network() 9 | with model: 10 | for i in range(D): 11 | 12 | def waves(t, i=i): 13 | return np.sin(t + np.arange(i + 1) * 2 * np.pi / (i + 1)) 14 | 15 | node = nengo.Node(waves) 16 | 17 | if __name__ == "__main__": 18 | import nengo_gui 19 | 20 | nengo_gui.GUI(__file__).start() 21 | -------------------------------------------------------------------------------- /examples/net.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "name": "", 4 | "signature": "sha256:449f5777c8db5b6d5daf37b3d65fc3848ca984f8862ebb50760a896deda5adea" 5 | }, 6 | "nbformat": 3, 7 | "nbformat_minor": 0, 8 | "worksheets": [ 9 | { 10 | "cells": [ 11 | { 12 | "cell_type": "code", 13 | "collapsed": false, 14 | "input": [ 15 | "import numpy as np\n", 16 | "import nengo\n", 17 | "\n", 18 | "model = nengo.Network()\n", 19 | "with model:\n", 20 | " stimulus_A = nengo.Node([1], label='stim A')\n", 21 | " stimulus_B = nengo.Node(lambda t: np.sin(2*np.pi*t))\n", 22 | " ens = nengo.Ensemble(n_neurons=1000, dimensions=2)\n", 23 | " result = nengo.Ensemble(n_neurons=50, dimensions=1)\n", 24 | " nengo.Connection(stimulus_A, ens[0])\n", 25 | " nengo.Connection(stimulus_B, ens[1])\n", 26 | " nengo.Connection(ens, result, function=lambda x: x[0] * x[1],\n", 27 | " synapse=0.01)\n", 28 | "\n", 29 | " with nengo.Network(label='subnet') as subnet:\n", 30 | " a = nengo.Ensemble(100, 1)\n", 31 | " b = nengo.Ensemble(100, 1)\n", 32 | " nengo.Connection(a, b)\n", 33 | " nengo.Connection(b, b)\n", 34 | "\n", 35 | " with nengo.Network() as subsubnet:\n", 36 | " c = nengo.Ensemble(100, 1)\n", 37 | " d = nengo.Ensemble(100, 1)\n", 38 | " nengo.Connection(c, d)\n", 39 | " nengo.Connection(b, c)\n", 40 | " nengo.Connection(d, a)\n", 41 | " nengo.Connection(result, a)" 42 | ], 43 | "language": "python", 44 | "metadata": {}, 45 | "outputs": [] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "collapsed": false, 50 | "input": [ 51 | "from nengo_gui.ipython import IPythonViz\n", 52 | "IPythonViz(model)" 53 | ], 54 | "language": "python", 55 | "metadata": {}, 56 | "outputs": [] 57 | } 58 | ], 59 | "metadata": {} 60 | } 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /examples/net.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | import numpy as np 3 | 4 | model = nengo.Network() 5 | with model: 6 | stimulus_A = nengo.Node([1], label="stim A") 7 | stimulus_B = nengo.Node(lambda t: np.sin(2 * np.pi * t)) 8 | ens = nengo.Ensemble(n_neurons=1000, dimensions=2) 9 | result = nengo.Ensemble(n_neurons=50, dimensions=1) 10 | nengo.Connection(stimulus_A, ens[0]) 11 | nengo.Connection(stimulus_B, ens[1]) 12 | nengo.Connection(ens, result, function=lambda x: x[0] * x[1], synapse=0.01) 13 | 14 | with nengo.Network(label="subnet") as subnet: 15 | a = nengo.Ensemble(100, 1) 16 | b = nengo.Ensemble(100, 1) 17 | nengo.Connection(a, b) 18 | nengo.Connection(b, b) 19 | 20 | with nengo.Network() as subsubnet: 21 | c = nengo.Ensemble(100, 1) 22 | d = nengo.Ensemble(100, 1) 23 | nengo.Connection(c, d) 24 | nengo.Connection(b, c) 25 | nengo.Connection(d, a) 26 | nengo.Connection(result, a) 27 | 28 | 29 | if __name__ == "__main__": 30 | import nengo_gui 31 | 32 | nengo_gui.GUI(__file__).start() 33 | -------------------------------------------------------------------------------- /examples/spa.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | import nengo.spa as spa 3 | 4 | D = 16 5 | 6 | model = spa.SPA(seed=1) 7 | with model: 8 | model.a = spa.Buffer(dimensions=D) 9 | model.b = spa.Buffer(dimensions=D) 10 | model.c = spa.Buffer(dimensions=D) 11 | model.cortical = spa.Cortical( 12 | spa.Actions( 13 | "c = a+b", 14 | ) 15 | ) 16 | 17 | model.input = spa.Input( 18 | a="A", 19 | b=(lambda t: "C*~A" if (t % 0.1 < 0.05) else "D*~A"), 20 | ) 21 | 22 | if __name__ == "__main__": 23 | import nengo_gui 24 | 25 | nengo_gui.GUI(__file__).start() 26 | -------------------------------------------------------------------------------- /nengo_gui/__init__.py: -------------------------------------------------------------------------------- 1 | from .gui import GUI, InteractiveGUI 2 | from .main import main, old_main 3 | from .namefinder import NameFinder 4 | from .version import version as __version__ 5 | from .viz import Viz # deprecated 6 | -------------------------------------------------------------------------------- /nengo_gui/_vendor/README.rst: -------------------------------------------------------------------------------- 1 | *********************** 2 | Vendorized dependencies 3 | *********************** 4 | 5 | This directory contains Nengo GUI dependencies 6 | that have been vendorized. 7 | A vendorized dependency is shipped with Nengo GUI 8 | to allow for easy offline install. 9 | 10 | To add a new vendorized dependency, 11 | add it to ``nengo_gui/_vendor/requirements.txt`` and run 12 | 13 | .. code:: bash 14 | 15 | pip install --target nengo_gui/_vendor -r nengo_gui/_vendor/requirements.txt 16 | 17 | from the Nengo GUI root directory. 18 | 19 | To update a vendorized dependency, 20 | change the version number associated with that package 21 | in ``nengo_gui/_vendor/requirements.txt`` 22 | and rerun the above command 23 | from the Nengo root directory. 24 | -------------------------------------------------------------------------------- /nengo_gui/_vendor/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/_vendor/__init__.py -------------------------------------------------------------------------------- /nengo_gui/_vendor/requirements.txt: -------------------------------------------------------------------------------- 1 | cookies==2.2.1 2 | -------------------------------------------------------------------------------- /nengo_gui/compat.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | import collections.abc 4 | import sys 5 | 6 | import numpy as np 7 | 8 | # Only test for Python 2 so that we have less changes for Python 4 9 | PY2 = sys.version_info[0] == 2 10 | 11 | # If something's changed from Python 2 to 3, we handle that here 12 | if PY2: 13 | from cgi import escape as cgi_escape 14 | 15 | from StringIO import StringIO 16 | 17 | escape = lambda s, quote=True: cgi_escape(s, quote=quote) 18 | iteritems = lambda d: d.iteritems() 19 | 20 | string_types = (str, unicode) 21 | int_types = (int, long) 22 | range = xrange 23 | 24 | else: 25 | from html import escape 26 | from io import StringIO 27 | 28 | iteritems = lambda d: iter(d.items()) 29 | 30 | 31 | def is_iterable(obj): 32 | if isinstance(obj, np.ndarray): 33 | return obj.ndim > 0 # 0-d arrays give error if iterated over 34 | else: 35 | return isinstance(obj, collections.abc.Iterable) 36 | -------------------------------------------------------------------------------- /nengo_gui/completion.py: -------------------------------------------------------------------------------- 1 | import threading 2 | import warnings 3 | 4 | try: 5 | from jedi.api import Script 6 | except ImportError: 7 | warnings.warn("Install the jedi module to get autocompletion in Nengo GUI.") 8 | 9 | class Script(object): 10 | def __init__(self, *args, **kwargs): 11 | pass 12 | 13 | def completions(self): 14 | return [] 15 | 16 | 17 | _jedi_lock = threading.Lock() 18 | 19 | 20 | def get_completions(code, line, column, path=None): 21 | with _jedi_lock: 22 | script = Script(code, line, column, path=path) 23 | return script.completions() 24 | -------------------------------------------------------------------------------- /nengo_gui/components/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .ace_editor import AceEditor 3 | from .component import Component 4 | from .editor import NoEditor 5 | from .htmlview import HTMLView 6 | from .netgraph import NetGraph 7 | from .pointer import Pointer 8 | from .progress import Progress 9 | from .raster import Raster 10 | from .sim_control import SimControl 11 | from .slider import Slider 12 | from .spa_similarity import SpaSimilarity 13 | from .spike_grid import SpikeGrid 14 | from .value import Value 15 | from .voltage import Voltage 16 | from .xyvalue import XYValue 17 | 18 | # Old versions of the .cfg files used Templates which had slightly different 19 | # names than the Components currently use. This code allows us to 20 | # successfully parse those old .cfg files 21 | SliderTemplate = Slider 22 | ValueTemplate = Value 23 | XYValueTemplate = XYValue 24 | SimControlTemplate = SimControl 25 | RasterTemplate = Raster 26 | VoltageTemplate = Voltage 27 | PointerTemplate = Pointer 28 | NetGraphTemplate = NetGraph 29 | AceEditorTemplate = AceEditor 30 | -------------------------------------------------------------------------------- /nengo_gui/components/editor.py: -------------------------------------------------------------------------------- 1 | from nengo_gui.components.component import Component 2 | 3 | 4 | class Editor(Component): 5 | config_defaults = {} 6 | 7 | def __init__(self): 8 | # the IPython integration requires this component to be early 9 | # in the list 10 | super(Editor, self).__init__(component_order=-8) 11 | 12 | def update_code(self, msg): 13 | pass 14 | 15 | def javascript(self): 16 | return "Nengo.disable_editor();" 17 | 18 | 19 | class NoEditor(Editor): 20 | def __init__(self): 21 | super(NoEditor, self).__init__() 22 | 23 | def message(self, msg): 24 | pass 25 | -------------------------------------------------------------------------------- /nengo_gui/components/htmlview.py: -------------------------------------------------------------------------------- 1 | import collections 2 | 3 | from nengo_gui.components.component import Component 4 | 5 | 6 | class HTMLView(Component): 7 | """Arbitrary HTML display taking input from a Node 8 | 9 | See nengo_gui/examples/basics/html.py for example usage""" 10 | 11 | def __init__(self, obj): 12 | super(HTMLView, self).__init__() 13 | self.obj = obj 14 | self.obj_output = obj.output 15 | self.data = collections.deque() 16 | 17 | def attach(self, page, config, uid): 18 | super(HTMLView, self).attach(page, config, uid) 19 | self.label = page.get_label(self.obj) 20 | 21 | def add_nengo_objects(self, page): 22 | with page.model: 23 | self.obj.output = self.gather_data 24 | 25 | def remove_nengo_objects(self, page): 26 | self.obj.output = self.obj_output 27 | 28 | def gather_data(self, t, *x): 29 | value = self.obj_output(t, *x) 30 | data = "%g %s" % (t, self.obj_output._nengo_html_) 31 | self.data.append(data) 32 | return value 33 | 34 | def update_client(self, client): 35 | while len(self.data) > 0: 36 | item = self.data.popleft() 37 | client.write_text(item) 38 | 39 | def javascript(self): 40 | info = dict(uid=id(self), label=self.label) 41 | json = self.javascript_config(info) 42 | return "new Nengo.HTMLView(main, sim, %s);" % json 43 | 44 | def code_python_args(self, uids): 45 | return [uids[self.obj]] 46 | -------------------------------------------------------------------------------- /nengo_gui/components/progress.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from nengo.utils.progress import ProgressBar, timestamp2timedelta 4 | from nengo_gui.compat import escape 5 | from nengo_gui.components.component import Component 6 | 7 | 8 | class Progress(Component, ProgressBar): 9 | def __init__(self): 10 | super(Progress, self).__init__() 11 | self.progress = None 12 | 13 | def update(self, progress): 14 | self.progress = progress 15 | 16 | def update_client(self, client): 17 | if self.progress is not None: 18 | client.write_text( 19 | json.dumps( 20 | { 21 | "name_during": escape( 22 | getattr(self.progress, "name_during", "Building") 23 | ), 24 | "name_after": escape( 25 | getattr(self.progress, "name_after", "Build") 26 | ), 27 | "progress": self.progress.progress, 28 | "max_steps": self.progress.max_steps, 29 | "elapsed_time": str( 30 | timestamp2timedelta(self.progress.elapsed_seconds()) 31 | ), 32 | "eta": str(timestamp2timedelta(self.progress.eta())), 33 | "finished": self.progress.finished, 34 | "success": self.progress.success, 35 | } 36 | ) 37 | ) 38 | if self.progress.finished: 39 | self.progress = None 40 | 41 | def javascript(self): 42 | info = dict(uid=id(self)) 43 | js = self.javascript_config(info) 44 | return "progress = new Nengo.Progress({});\n".format(js) 45 | -------------------------------------------------------------------------------- /nengo_gui/components/raster.py: -------------------------------------------------------------------------------- 1 | import collections 2 | import struct 3 | 4 | import nengo 5 | import numpy as np 6 | from nengo_gui.components.component import Component 7 | 8 | 9 | def is_spiking(neuron_type): 10 | try: 11 | return neuron_type.spiking 12 | except AttributeError: 13 | return "spikes" in neuron_type.probeable 14 | 15 | 16 | class Raster(Component): 17 | """Plot showing spike events over time.""" 18 | 19 | config_defaults = dict(n_neurons=10, **Component.config_defaults) 20 | 21 | def __init__(self, obj): 22 | super(Raster, self).__init__() 23 | self.neuron_type = obj.neuron_type 24 | self.obj = obj.neurons 25 | self.data = collections.deque() 26 | self.max_neurons = obj.n_neurons 27 | 28 | self.conn = None 29 | self.node = None 30 | self.chosen = None 31 | 32 | def attach(self, page, config, uid): 33 | super(Raster, self).attach(page, config, uid) 34 | self.label = page.get_label(self.obj.ensemble) 35 | 36 | def add_nengo_objects(self, page): 37 | with page.model: 38 | self.node = nengo.Node(self.gather_data, size_in=self.max_neurons) 39 | if is_spiking(self.neuron_type): 40 | self.conn = nengo.Connection(self.obj, self.node, synapse=None) 41 | 42 | def remove_nengo_objects(self, page): 43 | page.model.nodes.remove(self.node) 44 | if is_spiking(self.neuron_type): 45 | page.model.connections.remove(self.conn) 46 | 47 | def gather_data(self, t, x): 48 | if self.chosen is None: 49 | self.compute_chosen_neurons() 50 | indices = np.nonzero(x[self.chosen])[0] 51 | data = struct.pack(" 0: 61 | data = self.data.popleft() 62 | client.write_binary(data) 63 | 64 | def javascript(self): 65 | info = dict(uid=id(self), label=self.label, max_neurons=self.max_neurons) 66 | json = self.javascript_config(info) 67 | return "new Nengo.Raster(main, sim, %s);" % json 68 | 69 | def code_python_args(self, uids): 70 | return [uids[self.obj.ensemble]] 71 | 72 | def message(self, msg): 73 | if msg.startswith("n_neurons:"): 74 | n_neurons = min(int(msg[10:]), self.max_neurons) 75 | self.page.config[self].n_neurons = n_neurons 76 | self.compute_chosen_neurons() 77 | self.page.modified_config() 78 | -------------------------------------------------------------------------------- /nengo_gui/components/spa_plot.py: -------------------------------------------------------------------------------- 1 | import collections 2 | 3 | import nengo.spa as spa 4 | 5 | try: 6 | import nengo_spa 7 | except ImportError: 8 | nengo_spa = None 9 | 10 | from nengo_gui.components.component import Component 11 | 12 | 13 | class SpaPlot(Component): 14 | """Parent class for pointer.Pointer and spa_similarity.SpaSimilarity""" 15 | 16 | def __init__(self, obj, **kwargs): 17 | super(SpaPlot, self).__init__() 18 | self.obj = obj 19 | self.data = collections.deque() 20 | self.target = kwargs.get("args", "default") 21 | if self.target.startswith("<"): 22 | target_obj = getattr(obj, self.target[1:-1]) 23 | self.vocab_out = obj.get_output_vocab(target_obj) 24 | else: 25 | self.vocab_out = obj.outputs[self.target][1] 26 | 27 | def attach(self, page, config, uid): 28 | super(SpaPlot, self).attach(page, config, uid) 29 | self.label = page.get_label(self.obj) 30 | self.vocab_out.include_pairs = config.show_pairs 31 | 32 | def update_client(self, client): 33 | while len(self.data) > 0: 34 | data = self.data.popleft() 35 | client.write_text(data) 36 | 37 | def code_python_args(self, uids): 38 | return [uids[self.obj], "args=%r" % self.target] 39 | 40 | @staticmethod 41 | def applicable_targets(obj): 42 | targets = [] 43 | if isinstance(obj, spa.module.Module) or ( 44 | nengo_spa is not None and isinstance(obj, nengo_spa.Network) 45 | ): 46 | 47 | if hasattr(obj, "outputs"): 48 | for target_name, (obj, vocab) in obj.outputs.items(): 49 | if vocab is not None: 50 | targets.append(target_name) 51 | elif hasattr(obj, "output"): 52 | # TODO: check for other outputs than obj.output 53 | try: 54 | v = obj.get_output_vocab(obj.output) 55 | if v is not None: 56 | targets.append("") 57 | except KeyError: 58 | # Module has no output vocab 59 | pass 60 | 61 | return targets 62 | -------------------------------------------------------------------------------- /nengo_gui/components/voltage.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | 3 | import struct 4 | 5 | import nengo 6 | import numpy as np 7 | from nengo_gui.components.component import Component 8 | 9 | 10 | class Voltage(Component): 11 | """Represents neuron voltage over time.""" 12 | 13 | config_defaults = dict( 14 | max_value=5.0, 15 | min_value=0.0, 16 | show_legend=False, 17 | legend_labels=[], 18 | **Component.config_defaults, 19 | ) 20 | 21 | def __init__(self, obj, n_neurons=5): 22 | super(Voltage, self).__init__() 23 | self.obj = obj.neurons 24 | self.data = [] 25 | self.max_neurons = int(self.obj.size_out) 26 | self.n_neurons = min(n_neurons, self.max_neurons) 27 | self.struct = struct.Struct("<%df" % (1 + self.n_neurons)) 28 | 29 | def attach(self, page, config, uid): 30 | super(Voltage, self).attach(page, config, uid) 31 | self.label = page.get_label(self.obj.ensemble) 32 | 33 | def add_nengo_objects(self, page): 34 | with page.model: 35 | self.probe = nengo.Probe(self.obj[: self.n_neurons], "voltage") 36 | 37 | def remove_nengo_objects(self, page): 38 | page.model.probes.remove(self.probe) 39 | 40 | def format_data(self, t, x): 41 | data = self.struct.pack(t, *x[: self.n_neurons]) 42 | self.data.append(data) 43 | 44 | def update_client(self, client): 45 | sim = self.page.sim 46 | if sim is None: 47 | return 48 | 49 | # TODO: this is hack to delete probe data in Nengo 2.0.1, since we 50 | # can't limit the size of probes. Fix this up with Nengo 2.1. 51 | data = sim.data.raw[self.probe][:] 52 | del sim.data.raw[self.probe][:] # clear the data 53 | trange = sim.trange()[-len(data) :] 54 | 55 | for t, datum in zip(trange, data): 56 | datum = datum + np.arange(self.n_neurons) 57 | packet = self.struct.pack(t, *datum) 58 | client.write_binary(packet) 59 | 60 | def javascript(self): 61 | info = dict(uid=id(self), label=self.label, n_lines=self.n_neurons, synapse=0) 62 | json = self.javascript_config(info) 63 | return "new Nengo.Value(main, sim, %s);" % json 64 | 65 | def code_python_args(self, uids): 66 | return [uids[self.obj.ensemble]] 67 | -------------------------------------------------------------------------------- /nengo_gui/components/xyvalue.py: -------------------------------------------------------------------------------- 1 | import collections 2 | import struct 3 | 4 | import nengo 5 | from nengo_gui.components.component import Component 6 | 7 | 8 | class XYValue(Component): 9 | """Represents (at least) two dimensional values as co-ordinates on an 10 | x-y plot.""" 11 | 12 | config_defaults = dict( 13 | max_value=1, min_value=-1, index_x=0, index_y=1, **Component.config_defaults 14 | ) 15 | 16 | def __init__(self, obj): 17 | super(XYValue, self).__init__() 18 | self.obj = obj 19 | self.data = collections.deque() 20 | self.n_lines = int(obj.size_out) 21 | self.struct = struct.Struct("<%df" % (1 + self.n_lines)) 22 | self.node = None 23 | self.conn = None 24 | 25 | def attach(self, page, config, uid): 26 | super(XYValue, self).attach(page, config, uid) 27 | self.label = page.get_label(self.obj) 28 | 29 | def add_nengo_objects(self, page): 30 | with page.model: 31 | self.node = nengo.Node(self.gather_data, size_in=self.obj.size_out) 32 | self.conn = nengo.Connection(self.obj, self.node, synapse=0.01) 33 | 34 | def remove_nengo_objects(self, page): 35 | page.model.connections.remove(self.conn) 36 | page.model.nodes.remove(self.node) 37 | 38 | def gather_data(self, t, x): 39 | self.data.append(self.struct.pack(t, *x)) 40 | 41 | def update_client(self, client): 42 | while len(self.data) > 0: 43 | data = self.data.popleft() 44 | client.write_binary(data) 45 | 46 | def javascript(self): 47 | info = dict(uid=id(self), n_lines=self.n_lines, label=self.label) 48 | json = self.javascript_config(info) 49 | return "new Nengo.XYValue(main, sim, %s);" % json 50 | 51 | def code_python_args(self, uids): 52 | return [uids[self.obj]] 53 | -------------------------------------------------------------------------------- /nengo_gui/conftest.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import os.path 4 | import socket 5 | import threading 6 | 7 | import nengo_gui 8 | import pytest 9 | from nengo_gui import guibackend 10 | from nengo_gui.gui import BaseGUI 11 | from selenium import webdriver 12 | 13 | 14 | @pytest.yield_fixture(scope="session") 15 | def gui(): 16 | host, port = ("localhost", 0) 17 | server_settings = guibackend.GuiServerSettings((host, port)) 18 | model_context = guibackend.ModelContext( 19 | filename=os.path.join(nengo_gui.__path__[0], "examples", "default.py") 20 | ) 21 | gui = BaseGUI(model_context, server_settings) 22 | server_thread = threading.Thread(target=gui.start) 23 | server_thread.daemon = True 24 | server_thread.start() 25 | port = gui.server.server_port 26 | 27 | started = False 28 | while server_thread.is_alive() and not started: 29 | try: 30 | s = socket.create_connection((host, port), 0.1) 31 | started = True 32 | except: 33 | pass 34 | else: 35 | s.close() 36 | 37 | yield gui 38 | 39 | gui.server.shutdown() 40 | gui.server.wait_for_shutdown(0.05) 41 | 42 | 43 | @pytest.yield_fixture(scope="session") 44 | def driver(gui): 45 | driver = webdriver.Firefox() 46 | driver.get("http://localhost:{port}/".format(port=gui.server.server_port)) 47 | driver.maximize_window() 48 | 49 | assert driver.title != "Problem loading page" 50 | yield driver 51 | 52 | driver.quit() 53 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/2d_representation.py: -------------------------------------------------------------------------------- 1 | # # Nengo Example: 2-Dimensional Representation 2 | # 3 | # Ensembles of neurons represent information. In Nengo, we represent that 4 | # information with real-valued vectors -- lists of numbers. In this example, 5 | # we will represent a two-dimensional vector with a single ensemble of leaky 6 | # integrate-and-fire neurons. 7 | 8 | import nengo 9 | import numpy as np 10 | 11 | model = nengo.Network() 12 | with model: 13 | neurons = nengo.Ensemble(n_neurons=100, dimensions=2) 14 | 15 | stim = nengo.Node([0, 0]) 16 | nengo.Connection(stim, neurons) 17 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/addition.py: -------------------------------------------------------------------------------- 1 | # #Nengo Example: Addition 2 | 3 | # In this example, we will construct a network that adds two inputs. The 4 | # network utilizes two communication channels into the same neural population. 5 | # Addition is thus somewhat free, since the incoming currents from 6 | # different synaptic connections interact linearly (though two inputs dont 7 | # have to combine in this way: see the combining demo). 8 | 9 | import nengo 10 | 11 | model = nengo.Network() 12 | with model: 13 | # Create 3 ensembles each containing 100 leaky integrate-and-fire neurons 14 | a = nengo.Ensemble(n_neurons=100, dimensions=1) 15 | b = nengo.Ensemble(n_neurons=100, dimensions=1) 16 | c = nengo.Ensemble(n_neurons=100, dimensions=1) 17 | 18 | # Create input nodes representing constant values 19 | stim_a = nengo.Node(0.5) 20 | stim_b = nengo.Node(0.3) 21 | 22 | # Connect the input nodes to the appropriate ensembles 23 | nengo.Connection(stim_a, a) 24 | nengo.Connection(stim_b, b) 25 | 26 | # Connect input ensembles a and b to output ensemble c 27 | nengo.Connection(a, c) 28 | nengo.Connection(b, c) 29 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/combining.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Combining 2 | # 3 | # This example demonstrates how to create a neuronal ensemble that will 4 | # combine two 1-D inputs into one 2-D representation. 5 | 6 | import nengo 7 | import numpy as np 8 | 9 | model = nengo.Network() 10 | with model: 11 | # Our input ensembles consist of 100 leaky integrate-and-fire neurons, 12 | # representing a one-dimensional signal 13 | a = nengo.Ensemble(n_neurons=100, dimensions=1) 14 | b = nengo.Ensemble(n_neurons=100, dimensions=1) 15 | 16 | # The output ensemble consists of 200 leaky integrate-and-fire neurons, 17 | # representing a two-dimensional signal 18 | output = nengo.Ensemble(200, dimensions=2) 19 | 20 | # Create input nodes generating the sine and cosine 21 | sin = nengo.Node(output=np.sin) 22 | cos = nengo.Node(output=np.cos) 23 | 24 | nengo.Connection(sin, a) 25 | nengo.Connection(cos, b) 26 | 27 | # The square brackets define which dimension the input will project to 28 | nengo.Connection(a, output[1]) 29 | nengo.Connection(b, output[0]) 30 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/communication_channel.py: -------------------------------------------------------------------------------- 1 | # Communication Channel 2 | 3 | # This example demonstrates how to create a connections from one neuronal 4 | # ensemble to another that behaves like a communication channel (that is, it 5 | # transmits information without changing it). 6 | 7 | import nengo 8 | import numpy as np 9 | 10 | model = nengo.Network() 11 | with model: 12 | # Create an abstract input signal that oscillates as sin(t) 13 | sin = nengo.Node(np.sin) 14 | 15 | # Create the neuronal ensembles 16 | a = nengo.Ensemble(n_neurons=100, dimensions=1) 17 | b = nengo.Ensemble(n_neurons=100, dimensions=1) 18 | 19 | # Connect the input to the first neuronal ensemble 20 | nengo.Connection(sin, a) 21 | 22 | # Connect the first neuronal ensemble to the second using a 23 | # neurotransmitter with a 10ms time constant 24 | # This is the communication channel. 25 | nengo.Connection(a, b, synapse=0.01) 26 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/ensemble_array.py: -------------------------------------------------------------------------------- 1 | # Nengo Network: Ensemble Array 2 | # 3 | # An ensemble array is a group of ensembles that each represent a part of the 4 | # overall signal. 5 | # 6 | # Ensemble arrays are similar to normal ensembles, but expose a slightly 7 | # different interface. Additionally, in an ensemble array, the components of 8 | # the overall signal are not related. As a result, network arrays cannot be 9 | # used to compute nonlinear functions that mix the dimensions they represent. 10 | 11 | import nengo 12 | import numpy as np 13 | 14 | model = nengo.Network() 15 | with model: 16 | # Make an input node 17 | sin = nengo.Node(lambda t: [np.cos(t), np.sin(t)]) 18 | 19 | # Make ensembles to connect 20 | a = nengo.networks.EnsembleArray(n_neurons=100, n_ensembles=2) 21 | b = nengo.Ensemble(n_neurons=100, dimensions=2) 22 | c = nengo.networks.EnsembleArray(n_neurons=100, n_ensembles=2) 23 | 24 | # Connect the model elements, just feedforward 25 | nengo.Connection(sin, a.input) 26 | nengo.Connection(a.output, b) 27 | nengo.Connection(b, c.input) 28 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/inhibitory_gating.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Inhibitory Gating of Ensembles 2 | 3 | # ## Step 1: Create the network 4 | # 5 | # Our model consists of two ensembles (called A and B) that receive inputs from 6 | # a common sine wave signal generator. 7 | # 8 | # Ensemble A is gated using the output of a node, while Ensemble B is gated 9 | # using the output of a third ensemble (C). This is to demonstrate that 10 | # ensembles can be gated using either node outputs, or decoded outputs from 11 | # ensembles. 12 | 13 | import nengo 14 | 15 | model = nengo.Network() 16 | with model: 17 | a = nengo.Ensemble(n_neurons=30, dimensions=1) 18 | b = nengo.Ensemble(n_neurons=30, dimensions=1) 19 | c = nengo.Ensemble(n_neurons=30, dimensions=1) 20 | 21 | stim = nengo.Node(0) 22 | inhibition = nengo.Node(0) 23 | 24 | nengo.Connection(stim, a) 25 | nengo.Connection(stim, b) 26 | nengo.Connection(inhibition, a.neurons, transform=[[-2.5]] * 30) 27 | nengo.Connection(inhibition, c) 28 | nengo.Connection(c, b.neurons, transform=[[-2.5]] * 30) 29 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/many_neurons.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Many neurons 2 | # 3 | # This demo shows how to construct and manipulate a population of neurons. 4 | # 5 | # These are 100 leaky integrate-and-fire (LIF) neurons. The neuron tuning 6 | # properties have been randomly selected. 7 | # 8 | # The input is a sine wave to show the effects of increasing or decreasing 9 | # input. As a population, these neurons do a good job of representing a 10 | # single scalar value. 11 | 12 | import nengo 13 | 14 | model = nengo.Network() 15 | with model: 16 | # Our ensemble consists of 100 leaky integrate-and-fire neurons, 17 | # representing a one-dimensional signal 18 | a = nengo.Ensemble(n_neurons=100, dimensions=1) 19 | 20 | stim = nengo.Node([0]) 21 | 22 | # Connect the input to the population 23 | nengo.Connection(stim, a) 24 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/multiplication.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Multiplication 2 | 3 | # This example will show you how to multiply two values. The model 4 | # architecture can be thought of as a combination of the combining demo and 5 | # the squaring demo. Essentially, we project both inputs independently into a 6 | # 2D space, and then decode a nonlinear transformation of that space (the 7 | # product of the first and second vector elements). 8 | 9 | import nengo 10 | 11 | model = nengo.Network() 12 | with model: 13 | # Create 4 ensembles of leaky integrate-and-fire neurons 14 | a = nengo.Ensemble(n_neurons=100, dimensions=1, radius=1) 15 | b = nengo.Ensemble(n_neurons=100, dimensions=1, radius=1) 16 | 17 | # Radius on this ensemble is ~sqrt(2) 18 | combined = nengo.Ensemble(n_neurons=200, dimensions=2, radius=1.5) 19 | 20 | prod = nengo.Ensemble(n_neurons=100, dimensions=1, radius=1) 21 | 22 | # These next two lines make all of the encoders in the Combined population 23 | # point at the corners of the cube. This improves the quality of the 24 | # computation. 25 | combined.encoders = nengo.dists.Choice([[1, 1], [-1, 1], [1, -1], [-1, -1]]) 26 | 27 | stim_a = nengo.Node([0]) 28 | stim_b = nengo.Node([0]) 29 | 30 | # Connect the input nodes to the appropriate ensembles 31 | nengo.Connection(stim_a, a) 32 | nengo.Connection(stim_b, b) 33 | 34 | # Connect input ensembles A and B to the 2D combined ensemble 35 | nengo.Connection(a, combined[0]) 36 | nengo.Connection(b, combined[1]) 37 | 38 | # Define a function that computes the multiplication of two inputs 39 | def product(x): 40 | return x[0] * x[1] 41 | 42 | # Connect the combined ensemble to the output ensemble 43 | nengo.Connection(combined, prod, function=product) 44 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/single_neuron.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: A Single Neuron 2 | # 3 | # This demo shows you how to construct and manipulate a single leaky 4 | # integrate-and-fire (LIF) neuron. The LIF neuron is a simple, standard 5 | # neuron model, and here it resides inside a neural population, even though 6 | # there is only one neuron. 7 | 8 | import nengo 9 | 10 | model = nengo.Network() 11 | with model: 12 | neuron = nengo.Ensemble(n_neurons=1, dimensions=1) 13 | # Set intercept to 0.5 14 | neuron.intercepts = nengo.dists.Uniform(-0.5, -0.5) 15 | # Set the maximum firing rate of the neuron to 100hz 16 | neuron.max_rates = nengo.dists.Uniform(100, 100) 17 | # Sets the neurons firing rate to increase for positive input 18 | neuron.encoders = [[1]] 19 | 20 | stim = nengo.Node(0) 21 | 22 | # Connect the input signal to the neuron 23 | nengo.Connection(stim, neuron) 24 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/squaring.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Squaring the Input 2 | 3 | # This demo shows you how to construct a network that squares the value 4 | # encoded in a first population in the output of a second population. 5 | 6 | # Create the model object 7 | import nengo 8 | 9 | model = nengo.Network() 10 | with model: 11 | # Create two ensembles of 100 leaky-integrate-and-fire neurons 12 | a = nengo.Ensemble(n_neurons=100, dimensions=1) 13 | b = nengo.Ensemble(n_neurons=100, dimensions=1) 14 | 15 | # Create an input node 16 | stim = nengo.Node([0]) 17 | 18 | # Connect the input node to ensemble A 19 | nengo.Connection(stim, a) 20 | 21 | # Define the squaring function 22 | def square(x): 23 | return x[0] * x[0] 24 | 25 | # Connection ensemble a to ensemble b 26 | nengo.Connection(a, b, function=square) 27 | -------------------------------------------------------------------------------- /nengo_gui/examples/basics/two_neurons.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Two Neurons 2 | # 3 | # This demo shows how to construct and manipulate a complementary pair of 4 | # neurons. 5 | # 6 | # These are leaky integrate-and-fire (LIF) neurons. The neuron tuning 7 | # properties have been selected so there is one on and one off neuron. 8 | # 9 | # One neuron will increase for positive input, and the other will decrease. 10 | # This can be thought of as the simplest population that is able to give a 11 | # reasonable representation of a scalar value. 12 | 13 | import nengo 14 | import numpy as np 15 | 16 | model = nengo.Network() 17 | with model: 18 | neurons = nengo.Ensemble(n_neurons=2, dimensions=1) 19 | # Set the intercepts at .5 20 | neurons.intercepts = nengo.dists.Uniform(-0.5, -0.5) 21 | # Set the max firing rate at 100hz 22 | neurons.max_rates = nengo.dists.Uniform(100, 100) 23 | # One 'on' and one 'off' neuron 24 | neurons.encoders = [[1], [-1]] 25 | 26 | # make a 27 | stim = nengo.Node([0]) 28 | 29 | nengo.Connection(stim, neurons, synapse=0.01) 30 | -------------------------------------------------------------------------------- /nengo_gui/examples/default.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | 3 | model = nengo.Network() 4 | with model: 5 | stim = nengo.Node([0]) 6 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 7 | nengo.Connection(stim, a) 8 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter1/singleneuron.py: -------------------------------------------------------------------------------- 1 | # A Single Neuron Model 2 | 3 | # All models in nengo are built inside "networks". Inside a network, you 4 | # can put more networks, and you can connect networks to each other. You can 5 | # also put other objects such as neural populations or "ensembles" (which 6 | # have individual neurons inside of them) inside the networks. For this model, 7 | # you will make a network with one neuron. 8 | 9 | # This model has parameters as described in the book, ensuring that it is an 10 | # "on" neuron. The neuron will be slightly different each time you run this 11 | # script, as many parameters are randomly chosen. 12 | 13 | # Press the play button to run the simulation. 14 | # The graph on the top left shows the input signal and the graph on the top 15 | # right shows the value represented by the neuron. The filtered spikes from the 16 | # neuron are shown in the graph on the bottom right. 17 | 18 | 19 | import nengo 20 | 21 | # Setup the environment 22 | import numpy as np 23 | 24 | # Create the network object to which we can add ensembles, connections, etc. 25 | model = nengo.Network(label="A Single Neuron") 26 | 27 | with model: 28 | # Input 29 | stim = nengo.Node(lambda t: np.cos(16 * t), label="input") 30 | 31 | # Ensemble with one neuron 32 | neuron = nengo.Ensemble( 33 | 1, dimensions=1, encoders=[[1]] # Represent a scalar 34 | ) # Sets the neurons firing rate to increase for positive input 35 | 36 | # Connecting input to ensemble 37 | nengo.Connection(stim, neuron) 38 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter1/singleneuron.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_1 = nengo_gui.components.Slider(stim) 2 | _viz_config[_viz_1].max_value = 1 3 | _viz_config[_viz_1].min_value = -1 4 | _viz_config[_viz_1].x = 0.16696898256261244 5 | _viz_config[_viz_1].y = 0.7724947912352896 6 | _viz_config[_viz_1].width = 0.05138746145940392 7 | _viz_config[_viz_1].height = 0.17145593138946888 8 | _viz_config[_viz_1].label_visible = True 9 | _viz_2 = nengo_gui.components.Value(stim) 10 | _viz_config[_viz_2].max_value = 1 11 | _viz_config[_viz_2].min_value = -1 12 | _viz_config[_viz_2].show_legend = False 13 | _viz_config[_viz_2].legend_labels = ['label_0'] 14 | _viz_config[_viz_2].synapse = 0.01 15 | _viz_config[_viz_2].x = 0.20334187977862464 16 | _viz_config[_viz_2].y = 0.22179341491190846 17 | _viz_config[_viz_2].width = 0.138881091974467 18 | _viz_config[_viz_2].height = 0.22662621793848467 19 | _viz_config[_viz_2].label_visible = True 20 | _viz_6 = nengo_gui.components.Value(neuron) 21 | _viz_config[_viz_6].max_value = 1 22 | _viz_config[_viz_6].min_value = -1 23 | _viz_config[_viz_6].show_legend = False 24 | _viz_config[_viz_6].legend_labels = ['label_0'] 25 | _viz_config[_viz_6].synapse = 0.01 26 | _viz_config[_viz_6].x = 0.9736553177544159 27 | _viz_config[_viz_6].y = 0.24753530303789228 28 | _viz_config[_viz_6].width = 0.14246482426514165 29 | _viz_config[_viz_6].height = 0.24147425820419094 30 | _viz_config[_viz_6].label_visible = True 31 | _viz_7 = nengo_gui.components.Raster(neuron) 32 | _viz_config[_viz_7].n_neurons = 1 33 | _viz_config[_viz_7].x = 0.9741828927909677 34 | _viz_config[_viz_7].y = 0.7680063857427234 35 | _viz_config[_viz_7].width = 0.14308515014399295 36 | _viz_config[_viz_7].height = 0.23579616994185387 37 | _viz_config[_viz_7].label_visible = True 38 | _viz_net_graph = nengo_gui.components.NetGraph() 39 | _viz_progress = nengo_gui.components.Progress() 40 | _viz_config[_viz_progress].x = 0 41 | _viz_config[_viz_progress].y = 0 42 | _viz_config[_viz_progress].width = 100 43 | _viz_config[_viz_progress].height = 100 44 | _viz_config[_viz_progress].label_visible = True 45 | _viz_sim_control = nengo_gui.components.SimControl() 46 | _viz_config[_viz_sim_control].shown_time = 0.5 47 | _viz_config[_viz_sim_control].kept_time = 4.0 48 | _viz_config[model].pos=(0.05622548780465381, 0.12472608298234) 49 | _viz_config[model].size=(0.7757364659745798, 0.7757364659745798) 50 | _viz_config[model].expanded=True 51 | _viz_config[model].has_layout=True 52 | _viz_config[neuron].pos=(0.6394640033427806, 0.7655498679981659) 53 | _viz_config[neuron].size=(0.08547936308538644, 0.17184177744231613) 54 | _viz_config[stim].pos=(0.16801736510464935, 0.7693955811175494) 55 | _viz_config[stim].size=(0.1, 0.19400826446280975) -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter2/1-scalars.py: -------------------------------------------------------------------------------- 1 | # Representing a scalar 2 | 3 | # You can construct and manipulate a population of neurons (ensemble) in nengo. 4 | # This model shows how the activity of neural populations can be thought 5 | # of as representing a mathematical variable (a scalar value). 6 | 7 | # The model has paramenters as described in the book and uses a single 8 | # population (ensemble) of 100 LIF neurons. Note that the default max rates 9 | # in Nengo 2.0 are (200, 400), so you have to explicitly specify them to be 10 | # (100, 200) to create the model with the same parameters as described in the 11 | # book. Moreover the 'Node Factory' feature of ensembles mentioned in the book 12 | # maps to the 'neuron_type' in Nengo 2.0 which is set to LIF by default. The 13 | # default values of tauRC, tauRef, radius and intercepts in Nengo 2.0 are the 14 | # same as those mentioned in the book. 15 | 16 | # Press the play button to run the simulation. 17 | # The graph on the top left shows the input and the graph on the top right 18 | # shows the the decoded value of the neural spiking (a linearly decoded estimate 19 | # of the input). The graph on the bottom right shows the spike raster which is 20 | # the spiking output of the neuron population (x). 21 | 22 | import nengo 23 | 24 | # Setup the environment 25 | import numpy as np 26 | from nengo.dists import Uniform 27 | 28 | # Create the network object to which we can add ensembles, connections, etc. 29 | model = nengo.Network(label="Many Neurons") 30 | 31 | with model: 32 | # Input sine wave with range 1, freq of 16 rad/s 33 | stim = nengo.Node(lambda t: np.sin(16 * t), label="input") 34 | 35 | # Input sine wave with range increased to 4 36 | # stim = nengo.Node(lambda t: 4 * np.sin(16 * t), label="input") 37 | 38 | # Ensemble with 100 LIF neurons 39 | x = nengo.Ensemble(100, dimensions=1, max_rates=Uniform(100, 200)) 40 | 41 | # Connecting input to ensemble 42 | nengo.Connection(stim, x) 43 | 44 | 45 | # Increasing the range of Input 46 | 47 | # You have seen that the population of neurons does a reasonably good job of 48 | # representing the input. However, neurons cannot represent arbitrary values 49 | # well and you can verify this by increasing the range of the input to 4 50 | # ( input = nengo.Node(lambda t: 4 * np.sin(16 t)) ). You will observe the same 51 | # saturation effects as described in the book, showing that the neurons do a 52 | # much better job at representing information within the defined radius. 53 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter2/1-scalars.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.Raster(x) 2 | _viz_config[_viz_0].n_neurons = 10 3 | _viz_config[_viz_0].x = 0.8318723001387892 4 | _viz_config[_viz_0].y = 0.6618773946360152 5 | _viz_config[_viz_0].width = 0.1059810674389772 6 | _viz_config[_viz_0].height = 0.19156486307845622 7 | _viz_config[_viz_0].label_visible = True 8 | _viz_1 = nengo_gui.components.Value(x) 9 | _viz_config[_viz_1].max_value = 1 10 | _viz_config[_viz_1].min_value = -1 11 | _viz_config[_viz_1].show_legend = False 12 | _viz_config[_viz_1].legend_labels = ['label_0'] 13 | _viz_config[_viz_1].synapse = 0.01 14 | _viz_config[_viz_1].x = 0.829689495157122 15 | _viz_config[_viz_1].y = 0.25766283524904093 16 | _viz_config[_viz_1].width = 0.10277492291880781 17 | _viz_config[_viz_1].height = 0.19157088122605365 18 | _viz_config[_viz_1].label_visible = True 19 | _viz_2 = nengo_gui.components.Value(stim) 20 | _viz_config[_viz_2].max_value = 1 21 | _viz_config[_viz_2].min_value = -1 22 | _viz_config[_viz_2].show_legend = False 23 | _viz_config[_viz_2].legend_labels = ['label_0'] 24 | _viz_config[_viz_2].synapse = 0.01 25 | _viz_config[_viz_2].x = 0.14963094459497311 26 | _viz_config[_viz_2].y = 0.19712643678160896 27 | _viz_config[_viz_2].width = 0.1079136690647482 28 | _viz_config[_viz_2].height = 0.17337164020172938 29 | _viz_config[_viz_2].label_visible = True 30 | _viz_4 = nengo_gui.components.Slider(stim) 31 | _viz_config[_viz_4].max_value = 1 32 | _viz_config[_viz_4].min_value = -1 33 | _viz_config[_viz_4].x = 0.1479946923748423 34 | _viz_config[_viz_4].y = 0.6803954764294349 35 | _viz_config[_viz_4].width = 0.051387461459403906 36 | _viz_config[_viz_4].height = 0.17337164750957854 37 | _viz_config[_viz_4].label_visible = True 38 | _viz_net_graph = nengo_gui.components.NetGraph() 39 | _viz_progress = nengo_gui.components.Progress() 40 | _viz_config[_viz_progress].x = 0 41 | _viz_config[_viz_progress].y = 0 42 | _viz_config[_viz_progress].width = 100 43 | _viz_config[_viz_progress].height = 100 44 | _viz_config[_viz_progress].label_visible = True 45 | _viz_sim_control = nengo_gui.components.SimControl() 46 | _viz_config[_viz_sim_control].shown_time = 0.5 47 | _viz_config[_viz_sim_control].kept_time = 4.0 48 | _viz_config[model].pos=(0.029152602771059466, 0.051468151167020096) 49 | _viz_config[model].size=(0.9556962965264613, 0.9556962965264613) 50 | _viz_config[model].expanded=True 51 | _viz_config[model].has_layout=True 52 | _viz_config[stim].pos=(0.14815160858326318, 0.6735537190082654) 53 | _viz_config[stim].size=(0.09808776355538941, 0.2) 54 | _viz_config[x].pos=(0.5486779407642745, 0.671487603305786) 55 | _viz_config[x].size=(0.08717711545049715, 0.17525482093663994) -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter2/2-vectors.py: -------------------------------------------------------------------------------- 1 | # Representing a Vector 2 | 3 | # In nengo, ensembles of neurons represent information. In this model, 4 | # you will represent a two-dimensional vector with a single ensemble of 5 | # LIF (leaky integrate-and-fire) neurons. Though this is a case of 6 | # two-dimensional vector representation, but the ideas naturally 7 | # generalize to any number of dimensions. 8 | 9 | # This model has paramenters as described in the book, with the neurons 10 | # in the ensemble having two dimensions. Since the default max rates in 11 | # Nengo 2.0 are (200, 400), so you have to explicitly specify them to be 12 | # (100, 200) to create the same model as in the book. The default values 13 | # of tauRC, tauRef, intercepts, radius and expected noise in Nengo 2.0 14 | # are same as those mentioned in the book. 15 | 16 | # Press the play button to run the simulation. 17 | # The cos and sin graphs show the two dimensional input provided to the 18 | # ensemble and the top right graph shows the the decoded estimate of this 19 | # two dimensional input. The graph on bottom right shows the XY-value i.e., 20 | # the state represented by one dimension of the ensemble vs the state 21 | # represented by the other dimension. 22 | 23 | # Grab and move the sliders to manually control the input to the neurons. 24 | 25 | import nengo 26 | 27 | # Setup the envirnment 28 | import numpy as np 29 | from nengo.dists import Uniform 30 | 31 | # Create the network object to which we can add ensembles, connections, etc. 32 | model = nengo.Network(label="2D Representation") 33 | 34 | with model: 35 | # Input Nodes 36 | stim_sin = nengo.Node(output=np.sin, label="sin") 37 | stim_cos = nengo.Node(output=np.cos, label="cos") 38 | 39 | # Ensemble with 100 LIF neurons which represents a 2-dimensional signal 40 | x = nengo.Ensemble(100, dimensions=2, max_rates=Uniform(100, 200)) 41 | 42 | # Get the neuron encoders 43 | encoders = x.encoders.sample(100, 2) 44 | 45 | # Connecnting input to ensemble 46 | # The indices in ensemble 'x' define which dimension the input will project to 47 | nengo.Connection(stim_sin, x[0]) 48 | nengo.Connection(stim_cos, x[1]) 49 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter3/2-arbitrary_linear.py: -------------------------------------------------------------------------------- 1 | # Arbitrary Linear Transformation 2 | 3 | # This model shows that any linear transformation between ensembles can be 4 | # easily computed by selecting an appropriate value for the "transform". It 5 | # provides an example of computing linear transformations using vector 6 | # representations. 7 | 8 | # Network diagram: [input - 2D] ---> (x - 2d) ---> (z - 3D) 9 | # A two-dimensional input signal is first fed into a two-dimensional neuronal 10 | # ensemble x, which then projects it on to another three-dimensional ensemble z. 11 | 12 | # This model contains the parameters as described in the book. Setting the 13 | # transform equal to the 'weight_matrix' is analogous to entering the weights 14 | # in the "2 to 3 Coupling Matrix" window in Nengo 1.4 GUI as described in the 15 | # book. 16 | 17 | # Press the play button to run the simulation. 18 | # The graphs show a two-dimesional input linearly projected on to a 19 | # two-dimensional ensemble of neurons (ens_X), which further linearly projects it on 20 | # to a three-dimesional neuronal ensemble (ens_Z). You can use the sliders to change 21 | # the input values provided by the input node. 22 | 23 | import nengo 24 | 25 | # Setup the environment 26 | import numpy as np 27 | 28 | # Create the network object to which we can add ensembles, connections, etc. 29 | model = nengo.Network(label="Arbitrary Linear Transformation") 30 | 31 | with model: 32 | # Two-dimensional input signal with constant value of [0.5, -0.5] 33 | stim = nengo.Node([0.5, -0.5], label="Input") 34 | 35 | # 2 and 3-dimensional ensembles each with 200 LIF neurons 36 | ens_X = nengo.Ensemble(200, dimensions=2, label="X") 37 | ens_Z = nengo.Ensemble(200, dimensions=3, label="Z") 38 | 39 | # Connect the input to ensemble x 40 | nengo.Connection(stim, ens_X) 41 | 42 | # Connect ensemble x to ensemble z using a weight matrix 43 | weight_matrix = [[0.0, 1.0], [1.0, 0.0], [0.5, 0.5]] 44 | nengo.Connection(ens_X, ens_Z, transform=weight_matrix) 45 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter3/2-arbitrary_linear.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.Slider(stim) 2 | _viz_config[_viz_0].max_value = 1 3 | _viz_config[_viz_0].min_value = -1 4 | _viz_config[_viz_0].x = 0.12308751381644006 5 | _viz_config[_viz_0].y = 0.49701619316128054 6 | _viz_config[_viz_0].width = 0.05138597794323952 7 | _viz_config[_viz_0].height = 0.2012234813762161 8 | _viz_config[_viz_0].label_visible = True 9 | _viz_1 = nengo_gui.components.Value(stim) 10 | _viz_config[_viz_1].max_value = 1 11 | _viz_config[_viz_1].min_value = -1 12 | _viz_config[_viz_1].show_legend = False 13 | _viz_config[_viz_1].legend_labels = ['label_0', 'label_1'] 14 | _viz_config[_viz_1].synapse = 0.01 15 | _viz_config[_viz_1].x = 0.12197177073001222 16 | _viz_config[_viz_1].y = 0.9226015691240084 17 | _viz_config[_viz_1].width = 0.10277492291880781 18 | _viz_config[_viz_1].height = 0.19157088122605365 19 | _viz_config[_viz_1].label_visible = True 20 | _viz_2 = nengo_gui.components.Value(ens_X) 21 | _viz_config[_viz_2].max_value = 1 22 | _viz_config[_viz_2].min_value = -1 23 | _viz_config[_viz_2].show_legend = False 24 | _viz_config[_viz_2].legend_labels = ['label_0', 'label_1'] 25 | _viz_config[_viz_2].synapse = 0.01 26 | _viz_config[_viz_2].x = 0.4779533384716156 27 | _viz_config[_viz_2].y = 0.9283908021515266 28 | _viz_config[_viz_2].width = 0.10277492291880781 29 | _viz_config[_viz_2].height = 0.19157088122605365 30 | _viz_config[_viz_2].label_visible = True 31 | _viz_3 = nengo_gui.components.Value(ens_Z) 32 | _viz_config[_viz_3].max_value = 1 33 | _viz_config[_viz_3].min_value = -1 34 | _viz_config[_viz_3].show_legend = False 35 | _viz_config[_viz_3].legend_labels = ['label_0', 'label_1', 'label_2'] 36 | _viz_config[_viz_3].synapse = 0.01 37 | _viz_config[_viz_3].x = 0.8580131928964839 38 | _viz_config[_viz_3].y = 0.9308382528850452 39 | _viz_config[_viz_3].width = 0.10277492291880781 40 | _viz_config[_viz_3].height = 0.19157088122605365 41 | _viz_config[_viz_3].label_visible = True 42 | _viz_net_graph = nengo_gui.components.NetGraph() 43 | _viz_progress = nengo_gui.components.Progress() 44 | _viz_config[_viz_progress].x = 0 45 | _viz_config[_viz_progress].y = 0 46 | _viz_config[_viz_progress].width = 100 47 | _viz_config[_viz_progress].height = 100 48 | _viz_config[_viz_progress].label_visible = True 49 | _viz_sim_control = nengo_gui.components.SimControl() 50 | _viz_config[_viz_sim_control].shown_time = 0.5 51 | _viz_config[_viz_sim_control].kept_time = 4.0 52 | _viz_config[ens_X].pos=(0.48113207547169806, 0.5) 53 | _viz_config[ens_X].size=(0.08530318602261057, 0.1714876033057853) 54 | _viz_config[ens_Z].pos=(0.8584905660377359, 0.5) 55 | _viz_config[ens_Z].size=(0.08530318602261057, 0.1714876033057853) 56 | _viz_config[model].pos=(0.019527235354573482, -0.2376033057851238) 57 | _viz_config[model].size=(1, 1) 58 | _viz_config[model].expanded=True 59 | _viz_config[model].has_layout=True 60 | _viz_config[stim].pos=(0.12418313327774438, 0.49793388429752056) 61 | _viz_config[stim].size=(0.07701332195698966, 0.20206611570247934) -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter4/2-spa_structure.py: -------------------------------------------------------------------------------- 1 | # Structured Representations using SPA 2 | 3 | # Now we will build the model again, using the spa (semantic pointer 4 | # architecture) package built into Nengo 2.0. You will see that using the spa 5 | # package considerably simplifies model construction and visualization through 6 | # nengo_gui. 7 | 8 | # Press the play button to run the simulation. 9 | # The graphs A and B show the semantic pointer representations in objects A and 10 | # B respectively. Graphs labelled C show the result of the convolution operation 11 | # (left - shows the semantic pointer representation in object C, right - shows 12 | # the similarity with the vectors in the vocabulary). The graphs labelled Sum 13 | # show the sum of A and B as represented by the object Sum (left - shows the 14 | # semantic pointer representation in Sum, right - shows high similarity with 15 | # vectors A and B). 16 | 17 | # Setup the environment 18 | import nengo 19 | import nengo.spa as spa 20 | import numpy as np 21 | from nengo.spa import Vocabulary 22 | 23 | dim = 32 # the dimensionality of the vectors 24 | 25 | # Creating a vocabulary 26 | rng = np.random.RandomState(0) 27 | vocab = Vocabulary(dimensions=dim, rng=rng) 28 | vocab.add("C", vocab.parse("A * B")) 29 | 30 | # Create the spa.SPA network to which we can add SPA objects 31 | model = spa.SPA(label="structure", vocabs=[vocab]) 32 | with model: 33 | model.A = spa.State(dim) 34 | model.B = spa.State(dim) 35 | model.C = spa.State(dim, feedback=1) 36 | model.Sum = spa.State(dim) 37 | 38 | actions = spa.Actions("C = A * B", "Sum = A", "Sum = B") 39 | 40 | model.cortical = spa.Cortical(actions) 41 | 42 | # Model input 43 | model.input = spa.Input(A="A", B="B") 44 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter5/2-spa_question.py: -------------------------------------------------------------------------------- 1 | # Question Answering using SPA 2 | 3 | # Now we will build the model again, using the spa (semantic pointer 4 | # architecture) package built into Nengo 2.0. You will see that using the spa 5 | # package considerably simplifies model construction and visualization through 6 | # nengo_gui. 7 | 8 | # Press the play button to run the simulation. 9 | # Graphs show the colour, shape and cue inputs. The last graph 10 | # shows that the output is most similar to the semantic pointer bound to the 11 | # current cue. For example, when RED and CIRCLE are being bound 12 | # and the cue is CIRCLE, the output is most similar to RED. 13 | 14 | # Setup the environment 15 | import nengo 16 | import nengo.spa as spa 17 | import numpy as np 18 | from nengo.spa import Vocabulary 19 | 20 | dim = 32 # The dimensionality of the vectors 21 | rng = np.random.RandomState(4) 22 | vocab = Vocabulary(dimensions=dim, rng=rng, max_similarity=0.1) 23 | 24 | # Adding semantic pointers to the vocabulary 25 | CIRCLE = vocab.parse("CIRCLE") 26 | BLUE = vocab.parse("BLUE") 27 | RED = vocab.parse("RED") 28 | SQUARE = vocab.parse("SQUARE") 29 | ZERO = vocab.add("ZERO", [0] * dim) 30 | 31 | # Create the spa.SPA network to which we can add SPA objects 32 | model = spa.SPA(label="Question Answering", vocabs=[vocab]) 33 | with model: 34 | model.A = spa.State(dim) 35 | model.B = spa.State(dim) 36 | model.C = spa.State(dim) 37 | model.D = spa.State(dim) 38 | model.E = spa.State(dim) 39 | 40 | actions = spa.Actions( 41 | "D = A * B", 42 | "E = D * ~C", 43 | ) 44 | 45 | model.cortical = spa.Cortical(actions) 46 | 47 | # Function for providing color input 48 | def color_input(t): 49 | if (t // 0.5) % 2 == 0: 50 | return "RED" 51 | return "BLUE" 52 | 53 | # Function for providing shape input 54 | def shape_input(t): 55 | if (t // 0.5) % 2 == 0: 56 | return "CIRCLE" 57 | return "SQUARE" 58 | 59 | # Function for providing the cue 60 | def cue_input(t): 61 | sequence = ["ZERO", "CIRCLE", "RED", "ZERO", "SQUARE", "BLUE"] 62 | idx = int((t // (1.0 / len(sequence))) % len(sequence)) 63 | return sequence[idx] 64 | 65 | # Inputs 66 | model.input = spa.Input(A=color_input, B=shape_input, C=cue_input) 67 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter5/4-spa_question-memory.py: -------------------------------------------------------------------------------- 1 | # Question Answering with Memory using SPA 2 | 3 | # Now we will build this model again, using the spa (semantic pointer 4 | # architecture) package built into Nengo 2.0. 5 | 6 | # Press the play button to run the simulation. 7 | # Graphs show the colour, shape and cue inputs. The last graph 8 | # shows that the output is most similar to the semantic pointer which was 9 | # initially bound to the given cue. For example, when SQUARE is 10 | # provided as a cue, the output is most similar to BLUE. 11 | 12 | import nengo 13 | import nengo.spa as spa 14 | import numpy as np 15 | from nengo.spa import Vocabulary 16 | 17 | dim = 32 # The dimensionality of the vectors 18 | rng = np.random.RandomState(4) 19 | vocab = Vocabulary(dimensions=dim, rng=rng, max_similarity=0.1) 20 | 21 | # Adding semantic pointers to the vocabulary 22 | CIRCLE = vocab.parse("CIRCLE") 23 | BLUE = vocab.parse("BLUE") 24 | RED = vocab.parse("RED") 25 | SQUARE = vocab.parse("SQUARE") 26 | ZERO = vocab.add("ZERO", [0] * dim) 27 | 28 | # Create the spa.SPA network to which we can add SPA objects 29 | model = spa.SPA(label="Question Answering with Memory", vocabs=[vocab]) 30 | with model: 31 | model.A = spa.State(dim) 32 | model.B = spa.State(dim) 33 | model.C = spa.State(dim) 34 | model.D = spa.State(dim) 35 | model.E = spa.State(dim) 36 | model.memory = spa.State(dim, feedback=1) 37 | 38 | actions = spa.Actions("D = A * B", "memory = D", "E = memory * ~C") 39 | 40 | model.cortical = spa.Cortical(actions) 41 | 42 | # Function for providing color input 43 | def color_input(t): 44 | if t < 0.25: 45 | return "RED" 46 | elif t < 0.5: 47 | return "BLUE" 48 | return "ZERO" 49 | 50 | # Function for providing shape input 51 | def shape_input(t): 52 | if t < 0.25: 53 | return "CIRCLE" 54 | elif t < 0.5: 55 | return "SQUARE" 56 | return "ZERO" 57 | 58 | # Function for providing the cue 59 | def cue_input(t): 60 | if t < 0.5: 61 | return "ZERO" 62 | sequence = ["ZERO", "CIRCLE", "RED", "ZERO", "SQUARE", "BLUE"] 63 | idx = int(((t - 0.5) // (1.0 / len(sequence))) % len(sequence)) 64 | return sequence[idx] 65 | 66 | # Inputs 67 | model.input = spa.Input(A=color_input, B=shape_input, C=cue_input) 68 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter5/6-spa_question-control.py: -------------------------------------------------------------------------------- 1 | # Question Answering with Control using SPA 2 | 3 | # Now we will build this model again, using the spa (semantic pointer 4 | # architecture) package built into Nengo 2.0. 5 | 6 | # Press the play button to run the simulation. 7 | # The top graph is the input to the visual subnet. When this input is a 8 | # STATEMENT, there is no response shown in the motor graph and the input is 9 | # stored in memory (shown in the memory graph). To see bound pairs (e.g. 10 | # RED*CIRCLE) in memory, you need to right-click on the memory graph and 11 | # select 'show pairs'. This can be cluttered but is more informative. 12 | # When the input to 'visual' is a QUESTION, the motor graph shows the 13 | # appropriate answer. For instance, when the input to visual is 14 | # QUESTION+BLUE (showin in the visual graphs), the output from motor is SQUARE. 15 | # Note this simulation is fairly sensitive to the dimensionality, you may 16 | # need multiple runs or a higher dimension to get the expected results. 17 | 18 | # Setup the environment 19 | import nengo 20 | import nengo.spa as spa 21 | import numpy as np 22 | from nengo.spa import Vocabulary 23 | 24 | dim = 32 # The dimensionality of the vectors 25 | rng = np.random.RandomState(11) 26 | vocab = Vocabulary(dimensions=dim, rng=rng, max_similarity=0.1) 27 | 28 | # Adding semantic pointers to the vocabulary 29 | CIRCLE = vocab.parse("CIRCLE") 30 | BLUE = vocab.parse("BLUE") 31 | RED = vocab.parse("RED") 32 | SQUARE = vocab.parse("SQUARE") 33 | ZERO = vocab.add("ZERO", [0] * dim) 34 | 35 | # Create the spa.SPA network to which we can add SPA objects 36 | model = spa.SPA(label="Question Answering with Control", vocabs=[vocab]) 37 | with model: 38 | model.visual = spa.State(dim) 39 | model.motor = spa.State(dim) 40 | model.memory = spa.State(dim, feedback=1, feedback_synapse=0.1) 41 | 42 | actions = spa.Actions( 43 | "dot(visual, STATEMENT) --> memory=visual", 44 | "dot(visual, QUESTION) --> motor = memory * ~visual", 45 | ) 46 | 47 | model.bg = spa.BasalGanglia(actions) 48 | model.thalamus = spa.Thalamus(model.bg) 49 | 50 | # Function for providing visual input 51 | def visual_input(t): 52 | if 0.1 < t < 0.3: 53 | return "STATEMENT+RED*CIRCLE" 54 | elif 0.35 < t < 0.5: 55 | return "STATEMENT+BLUE*SQUARE" 56 | elif 0.55 < t < 0.7: 57 | return "QUESTION+BLUE" 58 | elif 0.75 < t < 0.9: 59 | return "QUESTION+CIRCLE" 60 | return "ZERO" 61 | 62 | # Inputs 63 | model.input = spa.Input(visual=visual_input) 64 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/chapter7/2-spa_sequencerouted.py: -------------------------------------------------------------------------------- 1 | # Routed Sequencing 2 | 3 | # This model introduces routing in the sequencing model. The addition of routing 4 | # allows the system to choose between two different actions: whether to go 5 | # through the sequence, or be driven by the visual input as explained in the 6 | # book. For instance, if the visual input has its value set to 0.8*START+D, the 7 | # model will begin cycling through at D->E, etc. Thus in this model, the input 8 | # doesn't prevent the activation of the second rule in the sequence. 9 | 10 | # The parameters used in the model are as described in the book, with 16 11 | # dimensions for all semantic pointers. 12 | 13 | # In Nengo 1.4, a buffer element for representing the vision was created by 14 | # using Buffer() as described in the book. However, in Nengo 2.0, you will have 15 | # to use State() with feedback parameter set to 0 (which is the default value in 16 | # nengo). 17 | 18 | # Press the play button in the visualizer to run the simulation. 19 | # The graph on the bottom-left shows the visual input recieved by the model, 20 | # the state graph in the middle shows the semantic pointer representation of the 21 | # values stored in the state ensemble. The actions graph on bottom-right shows 22 | # the current transition or the action being executed, and the state graph on 23 | # top-right shows the utility (similarity) of the current basal ganglia input 24 | # (i.e., state) with the possible vocabulary vectors. 25 | 26 | # You can see that in this model, even though the input is applied for 400ms, it 27 | # doesn't prevent the activation of the second and subsequent rules in the 28 | # sequence. 29 | 30 | # Setup the environment 31 | import nengo 32 | from nengo import spa # import spa related packages 33 | 34 | # Number of dimensions for the semantic pointers 35 | dim = 16 36 | 37 | # Create the spa.SPA network to which we can add SPA objects 38 | model = spa.SPA(label="Routed_Sequence", seed=20) 39 | with model: 40 | # Specify the modules to be used 41 | model.state = spa.State(dimensions=dim, feedback=1, feedback_synapse=0.01) 42 | model.vision = spa.State(dimensions=dim) 43 | 44 | # Specify the action mapping 45 | actions = spa.Actions( 46 | "dot(vision, START) --> state = vision", 47 | "dot(state, A) --> state = B", 48 | "dot(state, B) --> state = C", 49 | "dot(state, C) --> state = D", 50 | "dot(state, D) --> state = E", 51 | "dot(state, E) --> state = A", 52 | ) 53 | 54 | # Creating the BG and thalamus components that confirm to the specified rules 55 | model.bg = spa.BasalGanglia(actions=actions) 56 | model.thal = spa.Thalamus(model.bg) 57 | 58 | # Function that provides the model with an initial input semantic pointer. 59 | def start(t): 60 | if t < 0.4: 61 | return "0.8*START+D" 62 | return "0" 63 | 64 | # Input 65 | model.input = spa.Input(vision=start) 66 | -------------------------------------------------------------------------------- /nengo_gui/examples/hbb_tutorials/read_me.py: -------------------------------------------------------------------------------- 1 | # The simulations in these folders reproduce the tutorials from the book 2 | # How to Build a Brain (Eliasmith, 2013, Oxford). The original tutorials 3 | # were written for Nengo 1.4. The examples in these folders provide the final 4 | # models for each of the tutorials in the relevant chapters, but implemented 5 | # in Nengo 2.0. 6 | # 7 | # You can follow the general form of each tutorial from the book, 8 | # but there are significant differences in how models are built between Nengo 9 | # versions. The comment text in these simulation files describes those 10 | # differences as they relate to each example tutorial. Consequently, you can 11 | # just look at these files for all the information in the tutorials (except 12 | # these files don't walk you through model construction). 13 | 14 | import nengo 15 | 16 | model = nengo.Network() 17 | -------------------------------------------------------------------------------- /nengo_gui/examples/recurrent/controlled_integrator.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Controlled Integrator 2 | # 3 | # A controlled integrator is a circuit that acts on two signals: 4 | # 5 | # 1. Input - the signal being integrated 6 | # 2. Control - the control signal to the integrator 7 | # 8 | # A controlled integrator accumulates input, but its state can be directly 9 | # manipulated by the control signal. 10 | # 11 | # We can use standard network-creation commands to begin creating our 12 | # controlled integrator. We create a Network, and then we create a population 13 | # of neurons (called an *ensemble*). This population of neurons will 14 | # represent the state of our integrator, and the connections between 15 | # the neurons in the ensemble will define the dynamics of our integrator. 16 | 17 | import nengo 18 | 19 | model = nengo.Network() 20 | with model: 21 | # Make a population with 200 LIF neurons representing a 2 dimensional 22 | # signal, with a larger radius to accommodate large inputs 23 | a = nengo.Ensemble(n_neurons=200, dimensions=2, radius=1.5) 24 | 25 | # Define an input signal within our model 26 | stim = nengo.Node(0) 27 | 28 | # Connect the Input signal to ensemble a, affecting only the 29 | # first dimension. The `transform` argument scales the effective 30 | # strength of the connection by tau. 31 | tau = 0.1 32 | nengo.Connection(stim, a[0], transform=tau, synapse=tau) 33 | 34 | control = nengo.Node(0) 35 | 36 | # Connect the "Control" signal to the second of a's two input channels. 37 | nengo.Connection(control, a[1], synapse=0.005) 38 | 39 | # Create a recurrent connection that first takes the product 40 | # of both dimensions in A (i.e., the value times the control) 41 | # and then adds this back into the first dimension of A using 42 | # a transform 43 | nengo.Connection(a, a[0], function=lambda x: x[0] * x[1] + x[0], synapse=tau) 44 | -------------------------------------------------------------------------------- /nengo_gui/examples/recurrent/controlled_oscillator.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Controlled Oscillator 2 | # 3 | # The controlled oscillator is an oscillator with an extra input that controls 4 | # the frequency of the oscillation. 5 | 6 | import nengo 7 | 8 | tau = 0.1 # Post-synaptic time constant for feedback 9 | w_max = 10 # Maximum frequency is w_max/(2*pi) 10 | 11 | model = nengo.Network() 12 | with model: 13 | # The ensemble for the oscillator 14 | oscillator = nengo.Ensemble(500, dimensions=3, radius=1.7) 15 | 16 | # The feedback connection 17 | def feedback(x): 18 | x0, x1, w = x # These are the three variables stored in the ensemble 19 | return x0 + w * w_max * tau * x1, x1 - w * w_max * tau * x0, 0 20 | 21 | nengo.Connection(oscillator, oscillator, function=feedback, synapse=tau) 22 | 23 | # The ensemble for controlling the speed of oscillation 24 | frequency = nengo.Ensemble(100, dimensions=1) 25 | 26 | nengo.Connection(frequency, oscillator[2]) 27 | 28 | # We need a quick input at the beginning to start the oscillator 29 | initial_stim = nengo.Node(lambda t: 1 if t < 0.15 else 0) 30 | nengo.Connection(initial_stim, oscillator[0]) 31 | 32 | # Vary the speed over time 33 | stim_frequency = nengo.Node([1]) 34 | 35 | nengo.Connection(stim_frequency, frequency) 36 | -------------------------------------------------------------------------------- /nengo_gui/examples/recurrent/integrator.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: Integrator 2 | # 3 | # This demo implements a one-dimensional neural integrator. 4 | # 5 | # This is the first example of a recurrent network in the demos. It shows how 6 | # neurons can be used to implement stable dynamics. Such dynamics are 7 | # important for memory, noise cleanup, statistical inference, and many 8 | # other dynamic transformations. 9 | # 10 | # Note that since the integrator constantly sums its input, it will 11 | # saturate quickly if you leave the input non-zero. This makes it clear 12 | # that neurons have a finite range of representation. Such saturation 13 | # effects can be exploited to perform useful computations 14 | # (e.g. soft normalization). 15 | 16 | import nengo 17 | 18 | model = nengo.Network() 19 | with model: 20 | # Our ensemble consists of 100 leaky integrate-and-fire neurons, 21 | # representing a one-dimensional signal 22 | a = nengo.Ensemble(n_neurons=100, dimensions=1) 23 | 24 | # Create a piecewise step function for input 25 | stim = nengo.Node([0]) 26 | 27 | # Connect the population to itself using a long time constant (tau) 28 | # for stability 29 | tau = 0.1 30 | nengo.Connection(a, a, synapse=tau) 31 | 32 | # Connect the input using the same time constant as on the recurrent 33 | # connection to make it more ideal 34 | nengo.Connection(stim, a, transform=tau, synapse=tau) 35 | -------------------------------------------------------------------------------- /nengo_gui/examples/recurrent/lorenz_attractor.py: -------------------------------------------------------------------------------- 1 | # The Lorenz chaotic attractor 2 | # 3 | # This example shows the construction of a classic chaotic dynamical system: 4 | # the Lorenz "butterfly" attractor. The equations are: 5 | # 6 | # dx0/dt = sigma * (x1 - x0) 7 | # dx1/dt = x0 * (rho - x2) - x1 8 | # dx2/dt = x0 * x1 - beta * x2 9 | # 10 | # Since x2 is centered around approximately rho, and since NEF ensembles 11 | # are usually optimized to represent values within a certain radius of the 12 | # origin, we substitute x2' = x2 - rho, giving these equations: 13 | # 14 | # dx0/dt = sigma * (x1 - x0) 15 | # dx1/dt = - x0 * x2' - x1 16 | # dx2/dt = x0 * x1 - beta * (x2 + rho) - rho 17 | # 18 | # For more information, see 19 | # http://compneuro.uwaterloo.ca/publications/eliasmith2005b.html 20 | # "Chris Eliasmith. A unified approach to building and controlling 21 | # spiking attractor networks. Neural computation, 7(6):1276-1314, 2005." 22 | 23 | tau = 0.1 24 | sigma = 10 25 | beta = 8.0 / 3 26 | rho = 28 27 | 28 | import nengo 29 | 30 | 31 | def feedback(x): 32 | dx0 = -sigma * x[0] + sigma * x[1] 33 | dx1 = -x[0] * x[2] - x[1] 34 | dx2 = x[0] * x[1] - beta * (x[2] + rho) - rho 35 | 36 | return [dx0 * tau + x[0], dx1 * tau + x[1], dx2 * tau + x[2]] 37 | 38 | 39 | model = nengo.Network(seed=1) 40 | with model: 41 | state = nengo.Ensemble(2000, 3, radius=30) 42 | nengo.Connection(state, state, function=feedback, synapse=tau) 43 | -------------------------------------------------------------------------------- /nengo_gui/examples/recurrent/oscillator.py: -------------------------------------------------------------------------------- 1 | # Nengo Example: A Simple Harmonic Oscillator 2 | # 3 | # This demo implements a simple harmonic oscillator in a 2D neural 4 | # population. The oscillator is more visually interesting on its own than 5 | # the integrator, but the principle at work is the same. Here, instead of 6 | # having the recurrent input just integrate (i.e. feeding the full input 7 | # value back to the population), we have two dimensions which interact. 8 | 9 | import nengo 10 | 11 | model = nengo.Network() 12 | with model: 13 | # Create the ensemble for the oscillator 14 | neurons = nengo.Ensemble(n_neurons=200, dimensions=2) 15 | 16 | # Create an input signal that gives a brief input pulse to start the 17 | # oscillator 18 | stim = nengo.Node(lambda t: 1 if t < 0.1 else 0) 19 | # Connect the input signal to the neural ensemble 20 | nengo.Connection(stim, neurons[0]) 21 | 22 | # Create the feedback connection 23 | nengo.Connection(neurons, neurons, transform=[[1, 1], [-1, 1]], synapse=0.1) 24 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/00-intro.py: -------------------------------------------------------------------------------- 1 | # Tutorial 0: Welcome to Nengo 2 | 3 | # Nengo is a tool for creating large-scale biologically 4 | # realistic neural models. It was developed by the Centre for Theoretical 5 | # Neuroscience at the University of Waterloo and the affiliated spin-off 6 | # company Applied Brain Research. It has been used to create Spaun, the 7 | # first simulated brain that is capable of performing tasks. 8 | 9 | # This sequence of tutorials takes you through the various features of Nengo. 10 | # 11 | # You can go to the next tutorial by clicking on the "Open file" icon in the 12 | # top-left of the screen and selecting the next one. 13 | # 14 | # The Nengo interface shows the script that defines the model here on the 15 | # right side of the screen, and a graphical depiction of the model on the left 16 | # side. 17 | # 18 | # If you press the "Play" button (bottom-right), the simulation will start. 19 | # You can move the slider to adjust the input to the neurons and see the 20 | # spiking activity of the neurons change. You can also see the value that 21 | # can be decoded from that spiking activity change as the neurons try to 22 | # represent whatever value you are inputting. 23 | 24 | import nengo 25 | 26 | model = nengo.Network() 27 | with model: 28 | stim = nengo.Node(0) 29 | ens = nengo.Ensemble(n_neurons=50, dimensions=1) 30 | nengo.Connection(stim, ens) 31 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/00-intro.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.SliderTemplate(stim) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.07588 4 | _viz_config[_viz_0].x = -0.0263135 5 | _viz_config[_viz_0].y = 0.506947 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.189268 9 | _viz_1 = nengo_gui.components.RasterTemplate(ens) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.187686 12 | _viz_config[_viz_1].x = 0.716812 13 | _viz_config[_viz_1].y = 0.00753914 14 | _viz_config[_viz_1].height = 0.267376 15 | _viz_2 = nengo_gui.components.ValueTemplate(ens) 16 | _viz_config[_viz_2].label_visible = 1 17 | _viz_config[_viz_2].width = 0.167601 18 | _viz_config[_viz_2].x = 1.06014 19 | _viz_config[_viz_2].y = 0.000358637 20 | _viz_config[_viz_2].max_value = 1 21 | _viz_config[_viz_2].min_value = -1 22 | _viz_config[_viz_2].height = 0.268878 23 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 24 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 25 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 26 | _viz_config[_viz_sim_control].kept_time = 4 27 | _viz_config[_viz_sim_control].shown_time = 0.5 28 | _viz_config[ens].pos=(0.7727272727272727, 0.5) 29 | _viz_config[ens].size=(0.15151515151515152, 0.25) 30 | _viz_config[model].pos=(0.348830468735809, 0.49201138799364114) 31 | _viz_config[model].size=(0.6017670646427314, 0.6017670646427314) 32 | _viz_config[model].expanded=True 33 | _viz_config[model].has_layout=True 34 | _viz_config[slowdown].pos=(-0.20466619557631088, 0.9573856355604904) 35 | _viz_config[slowdown].size=(0.046883981863295635, 0.03943425722388151) 36 | _viz_config[stim].pos=(0.19696969696969696, 0.5) 37 | _viz_config[stim].size=(0.1212121212121212, 0.2) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/01-one-neuron.py: -------------------------------------------------------------------------------- 1 | # Tutorial 1: A Single Neuron 2 | 3 | # Here we show one single neuron. The slider on the left adjusts the input 4 | # to that neuron. The top graph shows the voltage in the neuron. When that 5 | # voltage is high enough, the neuron "spikes", producing an output (middle 6 | # graph). That output releases neurotransmitter which is gradually 7 | # reabsorbed. Given only that neurotransmitter output, it is difficult 8 | # to reconstruct the original input (bottom graph). 9 | 10 | # User Interface Tip: You can adjust the amount of time shown on the graphs 11 | # by dragging the left side of the gray bar inside the timeline at the bottom 12 | # of the screen. Try reducing it down to a smaller size so you can see 13 | # the individual spikes better. 14 | 15 | import nengo 16 | 17 | model = nengo.Network() 18 | with model: 19 | stim = nengo.Node(0) 20 | ens = nengo.Ensemble(n_neurons=1, dimensions=1, seed=5) 21 | nengo.Connection(stim, ens) 22 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/01-one-neuron.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.SliderTemplate(stim) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.0620064 4 | _viz_config[_viz_0].x = -0.0377351 5 | _viz_config[_viz_0].y = 0.259579 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.189268 9 | _viz_1 = nengo_gui.components.VoltageTemplate(ens) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.131454 12 | _viz_config[_viz_1].x = 1.05074 13 | _viz_config[_viz_1].y = -0.0432292 14 | _viz_config[_viz_1].max_value = 1 15 | _viz_config[_viz_1].min_value = 0 16 | _viz_config[_viz_1].height = 0.191161 17 | _viz_2 = nengo_gui.components.RasterTemplate(ens) 18 | _viz_config[_viz_2].label_visible = 1 19 | _viz_config[_viz_2].width = 0.124013 20 | _viz_config[_viz_2].x = 1.05322 21 | _viz_config[_viz_2].y = 0.356126 22 | _viz_config[_viz_2].height = 0.189268 23 | _viz_3 = nengo_gui.components.ValueTemplate(ens) 24 | _viz_config[_viz_3].label_visible = 1 25 | _viz_config[_viz_3].width = 0.124013 26 | _viz_config[_viz_3].x = 1.0495 27 | _viz_config[_viz_3].y = 0.76116 28 | _viz_config[_viz_3].max_value = 1 29 | _viz_config[_viz_3].min_value = -1 30 | _viz_config[_viz_3].height = 0.189268 31 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 32 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 33 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 34 | _viz_config[_viz_sim_control].kept_time = 4 35 | _viz_config[_viz_sim_control].shown_time = 0.5 36 | _viz_config[ens].pos=(0.7727272727272727, 0.3030303030303031) 37 | _viz_config[ens].size=(0.15151515151515152, 0.15151515151515155) 38 | _viz_config[model].pos=(0.29008605754397315, 0.3199774777364316) 39 | _viz_config[model].size=(0.6017670646427314, 0.6017670646427314) 40 | _viz_config[model].expanded=True 41 | _viz_config[model].has_layout=True 42 | _viz_config[slowdown].pos=(0.030859781980228436, 0.9023282461839404) 43 | _viz_config[slowdown].size=(0.03391052259673938, 0.04352059432201608) 44 | _viz_config[stim].pos=(0.14178396618598132, 0.3030303030303031) 45 | _viz_config[stim].size=(0.06602639042840559, 0.12121212121212124) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/02-two-neurons.py: -------------------------------------------------------------------------------- 1 | # Tutorial 2: Two neurons 2 | 3 | # Now we show what happens with two neurons. Notice that the neurons 4 | # respond very differently to the two inputs. One neuron responds more 5 | # strongly to positive values, while the other responds more to negative 6 | # values. This is typical of real neurons (sometimes called "on" and "off" 7 | # neurons). 8 | 9 | # Given these two neurons, more information is available about what the input 10 | # is. The bottom graph shows the "decoded" value found by taking the output 11 | # of both neurons and combining them. Notice that these two neurons do a 12 | # slightly better job of representing the input than just one neuron. 13 | 14 | 15 | import nengo 16 | 17 | model = nengo.Network() 18 | with model: 19 | stim = nengo.Node(0) 20 | ens = nengo.Ensemble(n_neurons=2, dimensions=1, seed=5) 21 | nengo.Connection(stim, ens) 22 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/02-two-neurons.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.SliderTemplate(stim) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.0620064 4 | _viz_config[_viz_0].x = -0.0377351 5 | _viz_config[_viz_0].y = 0.259579 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.189268 9 | _viz_2 = nengo_gui.components.RasterTemplate(ens) 10 | _viz_config[_viz_2].label_visible = 1 11 | _viz_config[_viz_2].width = 0.124013 12 | _viz_config[_viz_2].x = 1.04453 13 | _viz_config[_viz_2].y = 0.348555 14 | _viz_config[_viz_2].height = 0.189268 15 | _viz_3 = nengo_gui.components.ValueTemplate(ens) 16 | _viz_config[_viz_3].label_visible = 1 17 | _viz_config[_viz_3].width = 0.124013 18 | _viz_config[_viz_3].x = 1.0495 19 | _viz_config[_viz_3].y = 0.76116 20 | _viz_config[_viz_3].max_value = 1 21 | _viz_config[_viz_3].min_value = -1 22 | _viz_config[_viz_3].height = 0.189268 23 | _viz_5 = nengo_gui.components.VoltageTemplate(ens) 24 | _viz_config[_viz_5].label_visible = 1 25 | _viz_config[_viz_5].width = 0.124013 26 | _viz_config[_viz_5].x = 1.03337 27 | _viz_config[_viz_5].y = -0.0337658 28 | _viz_config[_viz_5].max_value = 2 29 | _viz_config[_viz_5].min_value = 0 30 | _viz_config[_viz_5].height = 0.189268 31 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 32 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 33 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 34 | _viz_config[_viz_sim_control].kept_time = 4 35 | _viz_config[_viz_sim_control].shown_time = 0.5 36 | _viz_config[ens].pos=(0.7727272727272727, 0.3030303030303031) 37 | _viz_config[ens].size=(0.15151515151515152, 0.15151515151515155) 38 | _viz_config[model].pos=(0.17221039638865257, 0.2877231522537397) 39 | _viz_config[model].size=(0.7127747007423387, 0.7127747007423387) 40 | _viz_config[model].expanded=True 41 | _viz_config[model].has_layout=True 42 | _viz_config[slowdown].pos=(0.030859781980228436, 0.9023282461839404) 43 | _viz_config[slowdown].size=(0.03391052259673938, 0.04352059432201608) 44 | _viz_config[stim].pos=(0.14178396618598132, 0.3030303030303031) 45 | _viz_config[stim].size=(0.06602639042840559, 0.12121212121212124) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/03-many-neurons.py: -------------------------------------------------------------------------------- 1 | # Tutorial 3: Many neurons 2 | 3 | # Brains have many neurons. What happens if we use 20 neurons? 50? 100? 4 | 5 | # The code below shows 20 neurons in a group (we call groups of neurons 6 | # an "Ensemble" of neurons). The representation is much more accurate. 7 | # To see this, press Play. Now, as you move the slider, the bottom graph 8 | # should follow your movements well. 9 | 10 | # Try changing the number of neurons by editing the code below where it says 11 | # "n_neurons=20". Try 50. Try 100. The representation should get more and 12 | # more accurate. 13 | 14 | # Nengo Tip: Don't use too big a number! Depending on your computer, using 15 | # more than 1000 neurons in a single Ensemble can take a long time to compute. 16 | # This is because Nengo needs to figure out how to weight the outputs of all 17 | # the individual neurons (what we call "decoders"), in order to get the bottom 18 | # graph. 19 | 20 | import nengo 21 | 22 | model = nengo.Network() 23 | with model: 24 | stim = nengo.Node(0) 25 | ens = nengo.Ensemble(n_neurons=20, dimensions=1) 26 | nengo.Connection(stim, ens) 27 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/03-many-neurons.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.SliderTemplate(stim) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.0620064 4 | _viz_config[_viz_0].x = -0.0377351 5 | _viz_config[_viz_0].y = 0.259579 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.189268 9 | _viz_1 = nengo_gui.components.RasterTemplate(ens) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.104699 12 | _viz_config[_viz_1].x = 1.03732 13 | _viz_config[_viz_1].y = 0.296352 14 | _viz_config[_viz_1].height = 0.159791 15 | _viz_3 = nengo_gui.components.ValueTemplate(ens) 16 | _viz_config[_viz_3].label_visible = 1 17 | _viz_config[_viz_3].width = 0.124013 18 | _viz_config[_viz_3].x = 1.0495 19 | _viz_config[_viz_3].y = 0.76116 20 | _viz_config[_viz_3].max_value = 1 21 | _viz_config[_viz_3].min_value = -1 22 | _viz_config[_viz_3].height = 0.189268 23 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 24 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 25 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 26 | _viz_config[_viz_sim_control].kept_time = 4 27 | _viz_config[_viz_sim_control].shown_time = 0.5 28 | _viz_config[ens].pos=(0.7727272727272727, 0.3030303030303031) 29 | _viz_config[ens].size=(0.15151515151515152, 0.15151515151515155) 30 | _viz_config[model].pos=(0.17221039638865257, 0.2877231522537397) 31 | _viz_config[model].size=(0.7127747007423387, 0.7127747007423387) 32 | _viz_config[model].expanded=True 33 | _viz_config[model].has_layout=True 34 | _viz_config[slowdown].pos=(0.030859781980228436, 0.9023282461839404) 35 | _viz_config[slowdown].size=(0.03391052259673938, 0.04352059432201608) 36 | _viz_config[stim].pos=(0.14178396618598132, 0.3030303030303031) 37 | _viz_config[stim].size=(0.06602639042840559, 0.12121212121212124) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/04-connecting-neurons.py: -------------------------------------------------------------------------------- 1 | # Tutorial 4: Connecting neurons 2 | 3 | # So far, we have just fed input to a group of neurons and read their output. 4 | # In order to do more interesting things, we need to be able to connect one 5 | # group of neurons to another. In this example, we have two groups of neurons 6 | # connected together. 7 | 8 | # If you just make a Connection between two groups of neurons, Nengo will 9 | # find the connection weights between each of the neurons such that whatever 10 | # value is being represented by the first group of neurons will be passed on 11 | # to the second group of neurons. Notice that now if you move the slider, 12 | # this affects the value in the first group of neurons, and these in turn 13 | # affect the value in the second group of neurons. 14 | 15 | # Whenever you make a connection, you can specify a "synapse" value. This 16 | # indicates the properties of the neurotransmitters and synapses (the actual 17 | # connections between neurons). The most important paramter is the 18 | # time constant: the amount of time it takes for the effects of a single spike 19 | # to wear off. For some parts of the brain, this is very fast (0.002 seconds) 20 | # and in other parts it is very slow (0.2 seconds). If you don't specify it, 21 | # Nengo will assume you want a fairly fast connection (0.005 seconds). Try 22 | # changing the synapse value between "a" and "b" to be much slower (0.2). This 23 | # should make the value stored in b change more slowly. 24 | 25 | import nengo 26 | 27 | model = nengo.Network() 28 | with model: 29 | stim = nengo.Node(0) 30 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 31 | nengo.Connection(stim, a) 32 | 33 | b = nengo.Ensemble(n_neurons=50, dimensions=1) 34 | 35 | nengo.Connection(a, b, synapse=0.01) 36 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/04-connecting-neurons.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.ValueTemplate(b) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.118519 4 | _viz_config[_viz_0].x = 0.860568 5 | _viz_config[_viz_0].y = 0.63917 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.159994 9 | _viz_1 = nengo_gui.components.ValueTemplate(a) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.110886 12 | _viz_config[_viz_1].x = 0.480585 13 | _viz_config[_viz_1].y = 0.630803 14 | _viz_config[_viz_1].max_value = 1 15 | _viz_config[_viz_1].min_value = -1 16 | _viz_config[_viz_1].height = 0.151856 17 | _viz_2 = nengo_gui.components.SliderTemplate(stim) 18 | _viz_config[_viz_2].label_visible = 1 19 | _viz_config[_viz_2].width = 0.0595778 20 | _viz_config[_viz_2].x = 0.121884 21 | _viz_config[_viz_2].y = 0.612654 22 | _viz_config[_viz_2].max_value = 1 23 | _viz_config[_viz_2].min_value = -1 24 | _viz_config[_viz_2].height = 0.169035 25 | _viz_3 = nengo_gui.components.RasterTemplate(a) 26 | _viz_config[_viz_3].label_visible = 1 27 | _viz_config[_viz_3].width = 0.115339 28 | _viz_config[_viz_3].x = 0.483937 29 | _viz_config[_viz_3].y = -0.00377259 30 | _viz_config[_viz_3].height = 0.144623 31 | _viz_4 = nengo_gui.components.RasterTemplate(b) 32 | _viz_config[_viz_4].label_visible = 1 33 | _viz_config[_viz_4].width = 0.122336 34 | _viz_config[_viz_4].x = 0.857553 35 | _viz_config[_viz_4].y = 0.005269 36 | _viz_config[_viz_4].height = 0.144623 37 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 38 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 39 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 40 | _viz_config[_viz_sim_control].kept_time = 4 41 | _viz_config[_viz_sim_control].shown_time = 0.5 42 | _viz_config[a].pos=(0.48113207547169806, 0.3030303030303031) 43 | _viz_config[a].size=(0.09433962264150943, 0.15151515151515155) 44 | _viz_config[b].pos=(0.8584905660377359, 0.3030303030303031) 45 | _viz_config[b].size=(0.09433962264150943, 0.15151515151515155) 46 | _viz_config[model].pos=(-0.002863544871064495, 0.17841592967742728) 47 | _viz_config[model].size=(1.0, 1.0) 48 | _viz_config[model].expanded=True 49 | _viz_config[model].has_layout=True 50 | _viz_config[slowdown].pos=(0.1156716417910446, 0.10255746531373007) 51 | _viz_config[slowdown].size=(0.02485648679678531, 0.023831711189342263) 52 | _viz_config[stim].pos=(0.12264150943396226, 0.3030303030303031) 53 | _viz_config[stim].size=(0.07547169811320754, 0.12121212121212124) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/05-computing.py: -------------------------------------------------------------------------------- 1 | # Tutorial 5: Computing a function 2 | 3 | # Whenever we make a Connection between groups of neurons, we don't have to 4 | # just pass the information from one group of neurons to the next. Instead, 5 | # we can also modify that information. We do this by specifying a function, 6 | # and Nengo will connect the individual neurons to best approximate that 7 | # function. 8 | 9 | # In the example here, we are computing the square of the value. So for an 10 | # input of -1 it should output 1, for 0 it should output 0, and for 1 it should 11 | # output 1. 12 | 13 | # You can change the function by adjusting the computations done in the 14 | # part of the code labelled "compute_this". This can be any arbitrary Python 15 | # function. For example, try computing the negative of x ("return -x"). Try 16 | # the absolute value ("return abs(x)"). You can also try more complex 17 | # functions like "return 1 if x > 0 else 0". 18 | 19 | import nengo 20 | 21 | model = nengo.Network() 22 | with model: 23 | stim = nengo.Node(0) 24 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 25 | nengo.Connection(stim, a) 26 | 27 | b = nengo.Ensemble(n_neurons=50, dimensions=1) 28 | 29 | def compute_this(x): 30 | return x * x 31 | 32 | nengo.Connection(a, b, synapse=0.01, function=compute_this) 33 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/05-computing.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.ValueTemplate(b) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.121642 4 | _viz_config[_viz_0].x = 0.864868 5 | _viz_config[_viz_0].y = 0.640154 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.161162 9 | _viz_1 = nengo_gui.components.ValueTemplate(a) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.129851 12 | _viz_config[_viz_1].x = 0.481815 13 | _viz_config[_viz_1].y = 0.646459 14 | _viz_config[_viz_1].max_value = 1 15 | _viz_config[_viz_1].min_value = -1 16 | _viz_config[_viz_1].height = 0.173121 17 | _viz_2 = nengo_gui.components.SliderTemplate(stim) 18 | _viz_config[_viz_2].label_visible = 1 19 | _viz_config[_viz_2].width = 0.0615672 20 | _viz_config[_viz_2].x = 0.126472 21 | _viz_config[_viz_2].y = 0.625268 22 | _viz_config[_viz_2].max_value = 1 23 | _viz_config[_viz_2].min_value = -1 24 | _viz_config[_viz_2].height = 0.179954 25 | _viz_3 = nengo_gui.components.RasterTemplate(a) 26 | _viz_config[_viz_3].label_visible = 1 27 | _viz_config[_viz_3].width = 0.114925 28 | _viz_config[_viz_3].x = 0.468383 29 | _viz_config[_viz_3].y = -0.0158418 30 | _viz_config[_viz_3].height = 0.157745 31 | _viz_4 = nengo_gui.components.RasterTemplate(b) 32 | _viz_config[_viz_4].label_visible = 1 33 | _viz_config[_viz_4].width = 0.117537 34 | _viz_config[_viz_4].x = 0.854323 35 | _viz_config[_viz_4].y = -0.00673016 36 | _viz_config[_viz_4].height = 0.158884 37 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 38 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 39 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 40 | _viz_config[_viz_sim_control].kept_time = 4 41 | _viz_config[_viz_sim_control].shown_time = 0.5 42 | _viz_config[a].pos=(0.48113207547169806, 0.3030303030303031) 43 | _viz_config[a].size=(0.09433962264150943, 0.15151515151515155) 44 | _viz_config[b].pos=(0.8584905660377359, 0.3030303030303031) 45 | _viz_config[b].size=(0.09433962264150943, 0.15151515151515155) 46 | _viz_config[model].pos=(-0.019402985074626844, 0.18564920273348517) 47 | _viz_config[model].size=(0.9999999999999997, 0.9999999999999997) 48 | _viz_config[model].expanded=True 49 | _viz_config[model].has_layout=True 50 | _viz_config[slowdown].pos=(0.1156716417910446, 0.10255746531373007) 51 | _viz_config[slowdown].size=(0.02485648679678531, 0.023831711189342263) 52 | _viz_config[stim].pos=(0.12264150943396226, 0.3030303030303031) 53 | _viz_config[stim].size=(0.07547169811320754, 0.12121212121212124) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/06-adding.py: -------------------------------------------------------------------------------- 1 | # Tutorial 6: Adding 2 | 3 | # If we make two Connections into the same Ensemble, the Ensemble will get 4 | # input from both sources, and it will end up representing the sum of all of 5 | # its inputs. Here, we use this to add two values together. 6 | 7 | # Notice that the value being represented by Ensemble c is, most of the time, 8 | # the sum of the two inputs (a and b). However, if that value gets too large 9 | # (or too small), it does not work very well. This is because every Ensemble 10 | # has a particular range of values that it expects to work with. We call this 11 | # the "radius" of the Ensemble, and the default radius is 1, which means that 12 | # the Ensemble is best at representing values between -1 and 1. You can 13 | # change this radius by adjusting the value specified below. Try changing it 14 | # so that it says "radius=2". Now the neurons will be good at representing 15 | # -2 to 2. However, in order to see that on the graph for Ensemble c, you 16 | # will have to adjust the range it is displaying. Right-click on the graph, 17 | # select "Set range" and set it to "-2,2". Now it should add correctly over 18 | # the full range of inputs. 19 | 20 | 21 | import nengo 22 | 23 | model = nengo.Network() 24 | with model: 25 | stim_a = nengo.Node(0) 26 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 27 | nengo.Connection(stim_a, a) 28 | 29 | stim_b = nengo.Node(0) 30 | b = nengo.Ensemble(n_neurons=50, dimensions=1) 31 | nengo.Connection(stim_b, b) 32 | 33 | c = nengo.Ensemble(n_neurons=50, dimensions=1, radius=1) 34 | nengo.Connection(a, c) 35 | nengo.Connection(b, c) 36 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/06-adding.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.ValueTemplate(c) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.108707 4 | _viz_config[_viz_0].x = 1.04012 5 | _viz_config[_viz_0].y = 0.506417 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.152695 9 | _viz_1 = nengo_gui.components.SliderTemplate(stim_a) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.0620498 12 | _viz_config[_viz_1].x = -0.027051 13 | _viz_config[_viz_1].y = 0.129863 14 | _viz_config[_viz_1].max_value = 1 15 | _viz_config[_viz_1].min_value = -1 16 | _viz_config[_viz_1].height = 0.196742 17 | _viz_2 = nengo_gui.components.SliderTemplate(stim_b) 18 | _viz_config[_viz_2].label_visible = 1 19 | _viz_config[_viz_2].width = 0.0625309 20 | _viz_config[_viz_2].x = -0.0255548 21 | _viz_config[_viz_2].y = 0.842328 22 | _viz_config[_viz_2].max_value = 1 23 | _viz_config[_viz_2].min_value = -1 24 | _viz_config[_viz_2].height = 0.18573 25 | _viz_3 = nengo_gui.components.ValueTemplate(a) 26 | _viz_config[_viz_3].label_visible = 1 27 | _viz_config[_viz_3].width = 0.0962013 28 | _viz_config[_viz_3].x = 0.62554 29 | _viz_config[_viz_3].y = 0.0587097 30 | _viz_config[_viz_3].max_value = 1 31 | _viz_config[_viz_3].min_value = -1 32 | _viz_config[_viz_3].height = 0.146822 33 | _viz_4 = nengo_gui.components.ValueTemplate(b) 34 | _viz_config[_viz_4].label_visible = 1 35 | _viz_config[_viz_4].width = 0.0962013 36 | _viz_config[_viz_4].x = 0.665944 37 | _viz_config[_viz_4].y = 0.912248 38 | _viz_config[_viz_4].max_value = 1 39 | _viz_config[_viz_4].min_value = -1 40 | _viz_config[_viz_4].height = 0.146822 41 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 42 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 43 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 44 | _viz_config[_viz_sim_control].kept_time = 4 45 | _viz_config[_viz_sim_control].shown_time = 0.5 46 | _viz_config[a].pos=(0.45227168191863, 0.1627923130325655) 47 | _viz_config[a].size=(0.09433962264150943, 0.1) 48 | _viz_config[b].pos=(0.44265155073427465, 0.8577627736438034) 49 | _viz_config[b].size=(0.09433962264150943, 0.1) 50 | _viz_config[c].pos=(0.8584905660377359, 0.5) 51 | _viz_config[c].size=(0.09433962264150943, 0.1) 52 | _viz_config[model].pos=(0.11714924271351584, 0.16200000993419406) 53 | _viz_config[model].size=(0.7757364659745805, 0.7757364659745805) 54 | _viz_config[model].expanded=True 55 | _viz_config[model].has_layout=True 56 | _viz_config[stim_a].pos=(0.13899573244736746, 0.1466418877868469) 57 | _viz_config[stim_a].size=(0.07547169811320754, 0.08) 58 | _viz_config[stim_b].pos=(0.1476538505132879, 0.8621674350744541) 59 | _viz_config[stim_b].size=(0.07547169811320754, 0.08) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/07-multiple-dimensions.py: -------------------------------------------------------------------------------- 1 | # Tutorial 7: Multiple Dimensions 2 | 3 | # Ensembles of neurons do not just have to represent one thing. Instead, 4 | # a group of neurons can represent multiple values at the same time. We call 5 | # the number of values represented at once the "dimensions" of the Ensemble. 6 | # So, if a group of neurons is supposed to represent the spatial location of 7 | # something in three dimensions (x, y, z), then we say that it has dimensions=3. 8 | 9 | # In this case, three different values are being decoded from each of the 10 | # groups of neurons. Nengo decodes these values by finding different ways 11 | # of weighting together the actual spiking output (top graphs) in order to 12 | # produce the bottom graphs. 13 | 14 | # Nengo Tip: If you change the number of dimensions, the graphs and sliders 15 | # may not update to reflect those changes. You can force them to do so by 16 | # removing them and re-creating them. To remove them, right-click on the graph 17 | # or slider and select "Remove". To re-create them, right-click on the item 18 | # you want to make a graph for and select an option. "Slider" makes the 19 | # sliders for controlling input; "Value" shows the decoded value being 20 | # represented; and "Spikes" shows the individual spiking activity of the 21 | # neurons. 22 | 23 | import nengo 24 | 25 | model = nengo.Network() 26 | with model: 27 | stim = nengo.Node([0, 0, 0]) 28 | a = nengo.Ensemble(n_neurons=200, dimensions=3) 29 | nengo.Connection(stim, a) 30 | 31 | b = nengo.Ensemble(n_neurons=200, dimensions=3) 32 | nengo.Connection(a, b) 33 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/07-multiple-dimensions.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.SliderTemplate(stim) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.0679104 4 | _viz_config[_viz_0].x = 0.126098 5 | _viz_config[_viz_0].y = 0.624698 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.158884 9 | _viz_1 = nengo_gui.components.ValueTemplate(a) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.0992537 12 | _viz_config[_viz_1].x = 0.460919 13 | _viz_config[_viz_1].y = 0.641903 14 | _viz_config[_viz_1].max_value = 1 15 | _viz_config[_viz_1].min_value = -1 16 | _viz_config[_viz_1].height = 0.161731 17 | _viz_2 = nengo_gui.components.ValueTemplate(b) 18 | _viz_config[_viz_2].label_visible = 1 19 | _viz_config[_viz_2].width = 0.0977612 20 | _viz_config[_viz_2].x = 0.85992 21 | _viz_config[_viz_2].y = 0.654432 22 | _viz_config[_viz_2].max_value = 1 23 | _viz_config[_viz_2].min_value = -1 24 | _viz_config[_viz_2].height = 0.165148 25 | _viz_3 = nengo_gui.components.RasterTemplate(a) 26 | _viz_config[_viz_3].label_visible = 1 27 | _viz_config[_viz_3].width = 0.091791 28 | _viz_config[_viz_3].x = 0.485546 29 | _viz_config[_viz_3].y = 0.000103541 30 | _viz_config[_viz_3].height = 0.1418 31 | _viz_4 = nengo_gui.components.RasterTemplate(b) 32 | _viz_config[_viz_4].label_visible = 1 33 | _viz_config[_viz_4].width = 0.0955224 34 | _viz_config[_viz_4].x = 0.875591 35 | _viz_config[_viz_4].y = -0.00502174 36 | _viz_config[_viz_4].height = 0.138952 37 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 38 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 39 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 40 | _viz_config[_viz_sim_control].kept_time = 4 41 | _viz_config[_viz_sim_control].shown_time = 0.5 42 | _viz_config[a].pos=(0.48113207547169806, 0.3030303030303031) 43 | _viz_config[a].size=(0.09433962264150943, 0.15151515151515155) 44 | _viz_config[b].pos=(0.8584905660377359, 0.3030303030303031) 45 | _viz_config[b].size=(0.09433962264150943, 0.15151515151515155) 46 | _viz_config[model].pos=(0.0022388059701492543, 0.1685649202733485) 47 | _viz_config[model].size=(1.0, 1.0) 48 | _viz_config[model].expanded=True 49 | _viz_config[model].has_layout=True 50 | _viz_config[stim].pos=(0.12264150943396226, 0.3030303030303031) 51 | _viz_config[stim].size=(0.07547169811320754, 0.12121212121212124) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/08-combining.py: -------------------------------------------------------------------------------- 1 | # Tutorial 8: Combining Information 2 | 3 | # Now that we can represent multiple things using the same group of neurons, 4 | # we can also combine information together. Here we introduce a new syntax 5 | # when making Connections: just can specify which of the multiple dimensions 6 | # to use. For example, "Connection(a, c[0])" says to take the single dimension 7 | # in a and pass it into the first dimension in c. (In Python, we always start 8 | # counting at zero, so the first dimension is x[0], then x[1], then x[2], and 9 | # so on). You can also do this when connecting out of a group, so you could do 10 | # something like "Connection(c[1], d[3])". 11 | 12 | # In the example below, we combine the information from two different Ensembles 13 | # (a and b) into a third one (c) that represents both values. Notice that this 14 | # is different than the Addition tutorial in that we are keeping both values 15 | # separate, rather than adding them together. 16 | 17 | # Advanced Nengo Tip: Connections support full Python slice notation, so you 18 | # can also do things like [-1], or [1:5] or [::-1] and so on. 19 | 20 | import nengo 21 | 22 | model = nengo.Network() 23 | with model: 24 | stim_a = nengo.Node(0) 25 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 26 | nengo.Connection(stim_a, a) 27 | 28 | stim_b = nengo.Node(0) 29 | b = nengo.Ensemble(n_neurons=50, dimensions=1) 30 | nengo.Connection(stim_b, b) 31 | 32 | c = nengo.Ensemble(n_neurons=200, dimensions=2) 33 | nengo.Connection(a, c[0]) 34 | nengo.Connection(b, c[1]) 35 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/08-combining.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.SliderTemplate(stim_b) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.0569738 4 | _viz_config[_viz_0].x = -0.0457345 5 | _viz_config[_viz_0].y = 0.827805 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.173906 9 | _viz_1 = nengo_gui.components.SliderTemplate(stim_a) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.0569738 12 | _viz_config[_viz_1].x = -0.0616871 13 | _viz_config[_viz_1].y = 0.219156 14 | _viz_config[_viz_1].max_value = 1 15 | _viz_config[_viz_1].min_value = -1 16 | _viz_config[_viz_1].height = 0.173906 17 | _viz_2 = nengo_gui.components.ValueTemplate(c) 18 | _viz_config[_viz_2].label_visible = 1 19 | _viz_config[_viz_2].width = 0.146 20 | _viz_config[_viz_2].x = 1.08167 21 | _viz_config[_viz_2].y = 0.560052 22 | _viz_config[_viz_2].max_value = 1 23 | _viz_config[_viz_2].min_value = -1 24 | _viz_config[_viz_2].height = 0.222205 25 | _viz_3 = nengo_gui.components.ValueTemplate(a) 26 | _viz_config[_viz_3].label_visible = 1 27 | _viz_config[_viz_3].width = 0.166397 28 | _viz_config[_viz_3].x = 0.739591 29 | _viz_config[_viz_3].y = 0.117101 30 | _viz_config[_viz_3].max_value = 1 31 | _viz_config[_viz_3].min_value = -1 32 | _viz_config[_viz_3].height = 0.215302 33 | _viz_4 = nengo_gui.components.ValueTemplate(b) 34 | _viz_config[_viz_4].label_visible = 1 35 | _viz_config[_viz_4].width = 0.158627 36 | _viz_config[_viz_4].x = 0.731222 37 | _viz_config[_viz_4].y = 1.02502 38 | _viz_config[_viz_4].max_value = 1 39 | _viz_config[_viz_4].min_value = -1 40 | _viz_config[_viz_4].height = 0.23463 41 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 42 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 43 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 44 | _viz_config[_viz_sim_control].kept_time = 4 45 | _viz_config[_viz_sim_control].shown_time = 0.5 46 | _viz_config[a].pos=(0.48341102575958145, 0.2174141319869915) 47 | _viz_config[a].size=(0.09433962264150943, 0.1) 48 | _viz_config[b].pos=(0.49594525234294007, 0.7964983663536175) 49 | _viz_config[b].size=(0.09433962264150943, 0.1) 50 | _viz_config[c].pos=(0.817737309116357, 0.49868499274012335) 51 | _viz_config[c].size=(0.1, 0.1) 52 | _viz_config[model].pos=(0.2729728706363317, 0.2116338393468492) 53 | _viz_config[model].size=(0.6549231553528394, 0.6549231553528394) 54 | _viz_config[model].expanded=True 55 | _viz_config[model].has_layout=True 56 | _viz_config[stim_a].pos=(0.12036255914607885, 0.22437038115729602) 57 | _viz_config[stim_a].size=(0.07547169811320754, 0.08) 58 | _viz_config[stim_b].pos=(0.12719941000972898, 0.7999764909387699) 59 | _viz_config[stim_b].size=(0.07547169811320754, 0.08) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/09-multiplication.py: -------------------------------------------------------------------------------- 1 | # Tutorial 9: Multiplication 2 | 3 | # Now that we can combine information, we can use this to compute more 4 | # complex functions. For example, to multiply two numbers together, we 5 | # first make a combined Ensemble as in the previous tutorial, and then we 6 | # compute the pruduct of the two numbers by multiplying them together when 7 | # we make a Connection out of that combined Ensemble. 8 | 9 | # Notice that we had to increase the radius of the combined Ensemble to 1.5. 10 | # That is because it is representing two values, each of which can be in the 11 | # range -1 to 1. In order to make sure the Ensemble is good at representing 12 | # both values, we need to make sure the radius is large enough to include the 13 | # point [1, 1]. This requires a radius of sqrt(2), or around 1.5. 14 | 15 | import nengo 16 | 17 | model = nengo.Network() 18 | with model: 19 | stim_a = nengo.Node(0) 20 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 21 | nengo.Connection(stim_a, a) 22 | 23 | stim_b = nengo.Node(0) 24 | b = nengo.Ensemble(n_neurons=50, dimensions=1) 25 | nengo.Connection(stim_b, b) 26 | 27 | c = nengo.Ensemble(n_neurons=200, dimensions=2, radius=1.5) 28 | nengo.Connection(a, c[0]) 29 | nengo.Connection(b, c[1]) 30 | 31 | d = nengo.Ensemble(n_neurons=50, dimensions=1) 32 | 33 | def multiply(x): 34 | return x[0] * x[1] 35 | 36 | nengo.Connection(c, d, function=multiply) 37 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/10-transforms.py: -------------------------------------------------------------------------------- 1 | # Tutorial 10: Transforms and scaling 2 | 3 | # When making Connections, we may want to scale the values being represented. 4 | # For example, we might want to just multiply a value by a fixed number like 5 | # 0.1 or 10 or something like that. Since this value doesn't change, we do 6 | # not need a full multiplication system like in the previous tutorial. 7 | 8 | # We could implement this sort of connection by writing a function. However, 9 | # this is such a common thing to do that Nengo has a shortcut for this by 10 | # having a "transform" parameter. The examples below show the equivalence of 11 | # these two approaches. In particular, b1 and b2 both take the value from a 12 | # and multiply it by -0.5. For a multidimensional example, d1 and d2 both take 13 | # values from c and compute 2*c[0]-c[1]-c[2], but do so in different ways. In 14 | # both cases the resulting models are identical. 15 | 16 | # You can use this trick to quickly define any linear transformation on the 17 | # values represented by the Ensembles. 18 | 19 | import nengo 20 | 21 | model = nengo.Network() 22 | with model: 23 | stim_a = nengo.Node(0) 24 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 25 | nengo.Connection(stim_a, a) 26 | 27 | b1 = nengo.Ensemble(n_neurons=50, dimensions=1) 28 | b2 = nengo.Ensemble(n_neurons=50, dimensions=1) 29 | 30 | # the long way to do it 31 | def simple_function(a): 32 | return -0.5 * a 33 | 34 | nengo.Connection(a, b1, function=simple_function) 35 | # the shortcut way to do it 36 | nengo.Connection(a, b2, transform=-0.5) 37 | 38 | stim_c = nengo.Node([0, 0, 0]) 39 | c = nengo.Ensemble(n_neurons=200, dimensions=3) 40 | nengo.Connection(stim_c, c) 41 | 42 | d1 = nengo.Ensemble(n_neurons=50, dimensions=1) 43 | d2 = nengo.Ensemble(n_neurons=50, dimensions=1) 44 | 45 | # the long way to do it 46 | def harder_function(c): 47 | return 2 * c[0] - c[1] - c[2] 48 | 49 | nengo.Connection(c, d1, function=harder_function) 50 | # the shortcut way to do it 51 | nengo.Connection(c, d2, transform=[[2, -1, -1]]) 52 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/11-memory.py: -------------------------------------------------------------------------------- 1 | # Tutorial 11: Memory 2 | 3 | # Nengo models can also store information over time. To do this, we simply 4 | # make a Connection from an Ensemble back to itself. That is, we form a 5 | # Connection that will feed a value into an Ensemble that is the same value 6 | # that the Ensemble is currently representing. This means we can store data 7 | # over time. 8 | 9 | # To use such a system, connect into it with another Ensemble. If that input 10 | # is zero, then the stored value should stay the same as it currently is. 11 | # If the input is positive, the stored value should increase. If the input is 12 | # negative, it should decrease. 13 | 14 | # Notice that the input Connection has "transform=0.1". That is to control 15 | # how strongly the input affects the stored value. If you make the transform 16 | # larger, it will change more quickly. 17 | 18 | # Also notice that the recurrent Connection from b back to itself has 19 | # synapse=0.1. This longer time constant makes the memory more stable, and 20 | # is also commonly found in the real brain for recurrent connections. 21 | 22 | # Mathematical Note: In the case where the input transform is exactly equal to 23 | # the recurrent synapse (as it is here), it turns out that the resulting system 24 | # should compute the mathematical integral of the input. 25 | 26 | import nengo 27 | 28 | model = nengo.Network() 29 | with model: 30 | stim_a = nengo.Node(0) 31 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 32 | nengo.Connection(stim_a, a) 33 | 34 | b = nengo.Ensemble(n_neurons=50, dimensions=1) 35 | nengo.Connection(b, b, synapse=0.1) 36 | nengo.Connection(a, b, transform=0.1) 37 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/11-memory.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.SliderTemplate(stim_a) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.0569738 4 | _viz_config[_viz_0].x = -0.0639661 5 | _viz_config[_viz_0].y = 0.4774 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.173906 9 | _viz_1 = nengo_gui.components.ValueTemplate(a) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.113948 12 | _viz_config[_viz_1].x = 0.461524 13 | _viz_config[_viz_1].y = 0.141328 14 | _viz_config[_viz_1].max_value = 1 15 | _viz_config[_viz_1].min_value = -1 16 | _viz_config[_viz_1].height = 0.173906 17 | _viz_2 = nengo_gui.components.ValueTemplate(b) 18 | _viz_config[_viz_2].label_visible = 1 19 | _viz_config[_viz_2].width = 0.113948 20 | _viz_config[_viz_2].x = 0.875346 21 | _viz_config[_viz_2].y = 0.0735048 22 | _viz_config[_viz_2].max_value = 1 23 | _viz_config[_viz_2].min_value = -1 24 | _viz_config[_viz_2].height = 0.173906 25 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 26 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 27 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 28 | _viz_config[_viz_sim_control].kept_time = 4 29 | _viz_config[_viz_sim_control].shown_time = 0.5 30 | _viz_config[a].pos=(0.48113207547169806, 0.5) 31 | _viz_config[a].size=(0.09433962264150943, 0.25) 32 | _viz_config[b].pos=(0.8584905660377359, 0.5) 33 | _viz_config[b].size=(0.09433962264150943, 0.25) 34 | _viz_config[model].pos=(0.3187172769298394, 0.1534010769420336) 35 | _viz_config[model].size=(0.6549231553528394, 0.6549231553528394) 36 | _viz_config[model].expanded=True 37 | _viz_config[model].has_layout=True 38 | _viz_config[stim_a].pos=(0.12264150943396226, 0.5) 39 | _viz_config[stim_a].size=(0.07547169811320754, 0.2) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/12-differential-eqns.py: -------------------------------------------------------------------------------- 1 | # Tutorial 12: Differential Equations 2 | 3 | # Recurrent connections can be used to implement not just memory, as in the 4 | # previous tutorial, but also any differential equation. 5 | 6 | # For example, the differential equation for a low-pass filter (a system where 7 | # the output y is a smoothed version of the input x) is 8 | # dy/dt = x/tau - y/tau 9 | # where tau is the time constant for the smoothing (larger means smoother) 10 | 11 | # To implement this in nengo, we need an input Connection that computes the 12 | # x/tau part, and a recurrent Connection that computes the -y/tau part. 13 | 14 | # Because these functions are implemented by neurons, the time constant of 15 | # the synapse itself turns out to be very important here. We have to take into 16 | # account what synapse is being used when making this connection. 17 | 18 | # While the proof is outside the scope of this tutorial, the resulting rule 19 | # is that both your Connections need to get scaled by the synapse value, and 20 | # your recurrent Connection must also add the stored value back in. That is, 21 | # in this case, the input part of the equation becomes 22 | # (x/tau) * synapse 23 | # and the recurrent part becomes 24 | # (-y/tau) * synapse + y 25 | # If we tell Nengo to implement those two functions, we will get the desired 26 | # differential equation. 27 | 28 | # Nengo Tip: In this particular case, those two functions are both linear 29 | # functions, and so we could implement them much more easily using the 30 | # "transform=" approach (see tutorial 10). This is left as an exercise to the 31 | # user. 32 | 33 | # Try running the model and seeing that y is a slowed-down, smoother version 34 | # of x. What happens if you change the input up and down quickly? What 35 | # happens with tau=0.1? What about tau=0.01? 36 | 37 | import nengo 38 | 39 | model = nengo.Network() 40 | with model: 41 | stim_x = nengo.Node(0) 42 | x = nengo.Ensemble(n_neurons=50, dimensions=1) 43 | nengo.Connection(stim_x, x) 44 | 45 | y = nengo.Ensemble(n_neurons=50, dimensions=1) 46 | tau = 0.5 47 | synapse = 0.1 48 | 49 | def input_function(x): 50 | return x / tau * synapse 51 | 52 | def recurrent_function(y): 53 | return (-y / tau) * synapse + y 54 | 55 | nengo.Connection(x, y, synapse=synapse, function=input_function) 56 | nengo.Connection(y, y, synapse=synapse, function=recurrent_function) 57 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/12-differential-eqns.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.SliderTemplate(stim_x) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.0956242 4 | _viz_config[_viz_0].x = -0.430906 5 | _viz_config[_viz_0].y = 0.675563 6 | _viz_config[_viz_0].max_value = 1 7 | _viz_config[_viz_0].min_value = -1 8 | _viz_config[_viz_0].height = 0.417594 9 | _viz_1 = nengo_gui.components.ValueTemplate(x) 10 | _viz_config[_viz_1].label_visible = 1 11 | _viz_config[_viz_1].width = 0.248055 12 | _viz_config[_viz_1].x = 0.328009 13 | _viz_config[_viz_1].y = 1.34579 14 | _viz_config[_viz_1].max_value = 1 15 | _viz_config[_viz_1].min_value = -1 16 | _viz_config[_viz_1].height = 0.39303 17 | _viz_2 = nengo_gui.components.ValueTemplate(y) 18 | _viz_config[_viz_2].label_visible = 1 19 | _viz_config[_viz_2].width = 0.26131 20 | _viz_config[_viz_2].x = 1.02917 21 | _viz_config[_viz_2].y = 1.327 22 | _viz_config[_viz_2].max_value = 1 23 | _viz_config[_viz_2].min_value = -1 24 | _viz_config[_viz_2].height = 0.397365 25 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 26 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 27 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 28 | _viz_config[_viz_sim_control].kept_time = 4 29 | _viz_config[_viz_sim_control].shown_time = 0.5 30 | _viz_config[model].pos=(0.822338530929192, 0.2185671702424535) 31 | _viz_config[model].size=(0.39411118476323376, 0.39411118476323376) 32 | _viz_config[model].expanded=True 33 | _viz_config[model].has_layout=True 34 | _viz_config[stim_x].pos=(-0.1314563617650836, 0.6100472694988941) 35 | _viz_config[stim_x].size=(0.11523748625523435, 0.30537933857637106) 36 | _viz_config[x].pos=(0.4159216979472795, 0.6100472694988941) 37 | _viz_config[x].size=(0.14404685781904294, 0.3817241732204638) 38 | _viz_config[y].pos=(0.9921091292234514, 0.6100472694988941) 39 | _viz_config[y].size=(0.14404685781904294, 0.3817241732204638) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/13-oscillators.py: -------------------------------------------------------------------------------- 1 | # Tutorial 13: Oscillators 2 | 3 | # If we do differential equations in multiple dimensions, we can get 4 | # oscillators. This gives an Ensemble of neurons that can produce patterns 5 | # of behaviour all on its own without any external input. For example, here 6 | # is a standard cycle in two dimensions: 7 | # dx0/dt = -x1 * s + x0 * (r - x0**2 - x1**2) 8 | # dx1/dt = x0 * s + x1 * (r - x0**2 - x1**2) 9 | # where r is the radius of the circle and s is the speed (in radians per second). 10 | 11 | # As discussed in the previous tutorial, we can convert this into a Nengo 12 | # model. In this case there is no input connection, so all we have to do 13 | # is multiply by the synapse and add the original value. 14 | 15 | # Here we introduce a new kind of plot. The XY-value plot shows the same 16 | # information as the normal Value plot, but plots the two dimensions together 17 | # rather than using time to be the x-axis. This can be convenient for 18 | # representing multidimensional data. 19 | 20 | # Try adjusting the r value to 0.5. Try 1.5. What about 0? 21 | # Try adjusting the speed s. What happens when it is very slow (0.5)? 0.1? 22 | 23 | import nengo 24 | 25 | model = nengo.Network() 26 | with model: 27 | 28 | x = nengo.Ensemble(n_neurons=200, dimensions=2) 29 | 30 | synapse = 0.1 31 | 32 | def oscillator(x): 33 | r = 1 34 | s = 6 35 | return [ 36 | synapse * (-x[1] * s + x[0] * (r - x[0] ** 2 - x[1] ** 2)) + x[0], 37 | synapse * (x[0] * s + x[1] * (r - x[0] ** 2 - x[1] ** 2)) + x[1], 38 | ] 39 | 40 | nengo.Connection(x, x, synapse=synapse, function=oscillator) 41 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/13-oscillators.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.XYValueTemplate(x) 2 | _viz_config[_viz_0].index_x = 0 3 | _viz_config[_viz_0].index_y = 1 4 | _viz_config[_viz_0].max_value = 1 5 | _viz_config[_viz_0].min_value = -1 6 | _viz_config[_viz_0].height = 0.431682 7 | _viz_config[_viz_0].label_visible = 1 8 | _viz_config[_viz_0].width = 0.303864 9 | _viz_config[_viz_0].y = -0.114121 10 | _viz_config[_viz_0].x = 0.776768 11 | _viz_1 = nengo_gui.components.ValueTemplate(x) 12 | _viz_config[_viz_1].label_visible = 1 13 | _viz_config[_viz_1].width = 0.307228 14 | _viz_config[_viz_1].x = 0.74198 15 | _viz_config[_viz_1].y = 0.879631 16 | _viz_config[_viz_1].max_value = 1 17 | _viz_config[_viz_1].min_value = -1 18 | _viz_config[_viz_1].height = 0.529282 19 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 20 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 21 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 22 | _viz_config[_viz_sim_control].kept_time = 4 23 | _viz_config[_viz_sim_control].shown_time = 0.5 24 | _viz_config[model].pos=(0.5324477237459521, 0.6033089159345045) 25 | _viz_config[model].size=(0.4668126560658494, 0.4668126560658494) 26 | _viz_config[model].expanded=True 27 | _viz_config[model].has_layout=True 28 | _viz_config[x].pos=(0.021511885626473486, 0.3636642941566037) 29 | _viz_config[x].size=(0.33333333333333337, 0.25) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/14-controlled-oscillator.py: -------------------------------------------------------------------------------- 1 | # Tutorial 14: Controlled Oscillator 2 | 3 | # Here we do the exact same oscillator as in the previous example, but we 4 | # introduce a new dimension that lets us control the speed of the oscillation 5 | 6 | # We use the same differential equation as before: 7 | # dx0/dt = -x1 * s + x0 * (r - x0**2 - y0**2) 8 | # dx1/dt = x0 * s + x1 * (r - x0**2 - y0**2) 9 | # where r is the radius of the circle and s is the speed (in radians per 10 | # second). 11 | 12 | # But, in this case, we make the Ensemble be 3-dimensional and use the third 13 | # dimension (x[2]) to represent s. You can control it with a separate input. 14 | # This shows how neurons can affect the pattern of activity of another 15 | # group of neurons. 16 | 17 | 18 | import nengo 19 | 20 | model = nengo.Network() 21 | with model: 22 | 23 | x = nengo.Ensemble(n_neurons=400, dimensions=3) 24 | 25 | synapse = 0.1 26 | 27 | def oscillator(x): 28 | r = 1 29 | s = 10 * x[2] 30 | return [ 31 | synapse * -x[1] * s + x[0] * (r - x[0] ** 2 - x[1] ** 2) + x[0], 32 | synapse * x[0] * s + x[1] * (r - x[0] ** 2 - x[1] ** 2) + x[1], 33 | ] 34 | 35 | nengo.Connection(x, x[:2], synapse=synapse, function=oscillator) 36 | 37 | stim_speed = nengo.Node(0) 38 | speed = nengo.Ensemble(n_neurons=50, dimensions=1) 39 | nengo.Connection(stim_speed, speed) 40 | nengo.Connection(speed, x[2]) 41 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/14-controlled-oscillator.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.XYValueTemplate(x) 2 | _viz_config[_viz_0].index_x = 0 3 | _viz_config[_viz_0].index_y = 1 4 | _viz_config[_viz_0].max_value = 1 5 | _viz_config[_viz_0].min_value = -1 6 | _viz_config[_viz_0].height = 0.347546 7 | _viz_config[_viz_0].label_visible = 1 8 | _viz_config[_viz_0].width = 0.23662 9 | _viz_config[_viz_0].y = -0.264045 10 | _viz_config[_viz_0].x = 0.786498 11 | _viz_1 = nengo_gui.components.SliderTemplate(stim_speed) 12 | _viz_config[_viz_1].label_visible = 1 13 | _viz_config[_viz_1].width = 0.0795713 14 | _viz_config[_viz_1].x = -0.0788423 15 | _viz_config[_viz_1].y = 0.373985 16 | _viz_config[_viz_1].max_value = 1 17 | _viz_config[_viz_1].min_value = -1 18 | _viz_config[_viz_1].height = 0.266852 19 | _viz_2 = nengo_gui.components.ValueTemplate(speed) 20 | _viz_config[_viz_2].label_visible = 1 21 | _viz_config[_viz_2].width = 0.104699 22 | _viz_config[_viz_2].x = 0.368167 23 | _viz_config[_viz_2].y = 0.213101 24 | _viz_config[_viz_2].max_value = 1 25 | _viz_config[_viz_2].min_value = -1 26 | _viz_config[_viz_2].height = 0.159791 27 | _viz_3 = nengo_gui.components.ValueTemplate(x) 28 | _viz_config[_viz_3].label_visible = 1 29 | _viz_config[_viz_3].width = 0.104699 30 | _viz_config[_viz_3].x = 1.00186 31 | _viz_config[_viz_3].y = 0.169638 32 | _viz_config[_viz_3].max_value = 1 33 | _viz_config[_viz_3].min_value = -1 34 | _viz_config[_viz_3].height = 0.159791 35 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 36 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 37 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 38 | _viz_config[_viz_sim_control].kept_time = 4 39 | _viz_config[_viz_sim_control].shown_time = 0.5 40 | _viz_config[model].pos=(0.3004817473040991, 0.6530128881789778) 41 | _viz_config[model].size=(0.7127747007423403, 0.7127747007423403) 42 | _viz_config[model].expanded=True 43 | _viz_config[model].has_layout=True 44 | _viz_config[speed].pos=(0.48113207547169806, 0.5) 45 | _viz_config[speed].size=(0.09433962264150943, 0.25) 46 | _viz_config[stim_speed].pos=(0.12264150943396226, 0.5) 47 | _viz_config[stim_speed].size=(0.07547169811320754, 0.2) 48 | _viz_config[x].pos=(0.8017741481272881, 0.4954441913439635) 49 | _viz_config[x].size=(0.09433962264150943, 0.25) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/15-lorenz.py: -------------------------------------------------------------------------------- 1 | # Tutorial 15: The Lorenz Chaotic Attractor 2 | 3 | # Differential equations can also give chaotic behaviour. The classic example 4 | # of this is the Lorenz "butterfly" attractor. The equations for it are 5 | # 6 | # dx0/dt = sigma * (x1 - x0) 7 | # dx1/dt = - x0 * x2 - x1 8 | # dx2/dt = x0 * x1 - beta * (x2 + rho) - rho 9 | # 10 | # Note: this is a slight transformation from the standard formulation so 11 | # as to centre the value around the origin. For further information, see 12 | # http://compneuro.uwaterloo.ca/publications/eliasmith2005b.html 13 | # "Chris Eliasmith. A unified approach to building and controlling 14 | # spiking attractor networks. Neural computation, 7(6):1276-1314, 2005." 15 | 16 | # Since there are three dimensions, we can show three different XY plots 17 | # combining the different values in different ways. 18 | 19 | import nengo 20 | 21 | model = nengo.Network(seed=3) 22 | with model: 23 | 24 | x = nengo.Ensemble(n_neurons=600, dimensions=3, radius=30) 25 | 26 | synapse = 0.1 27 | 28 | def lorenz(x): 29 | sigma = 10 30 | beta = 8.0 / 3 31 | rho = 28 32 | 33 | dx0 = -sigma * x[0] + sigma * x[1] 34 | dx1 = -x[0] * x[2] - x[1] 35 | dx2 = x[0] * x[1] - beta * (x[2] + rho) - rho 36 | 37 | return [dx0 * synapse + x[0], dx1 * synapse + x[1], dx2 * synapse + x[2]] 38 | 39 | nengo.Connection(x, x, synapse=synapse, function=lorenz) 40 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/15-lorenz.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.XYValue(x) 2 | _viz_config[_viz_0].index_x = 0 3 | _viz_config[_viz_0].index_y = 1 4 | _viz_config[_viz_0].max_value = 30 5 | _viz_config[_viz_0].min_value = -30 6 | _viz_config[_viz_0].height = 0.16344 7 | _viz_config[_viz_0].label_visible = True 8 | _viz_config[_viz_0].width = 0.106716 9 | _viz_config[_viz_0].y = 0.206423 10 | _viz_config[_viz_0].x = 0.842991 11 | _viz_1 = nengo_gui.components.Value(x) 12 | _viz_config[_viz_1].label_visible = True 13 | _viz_config[_viz_1].width = 0.184872049742142 14 | _viz_config[_viz_1].x = 0.2981978314119729 15 | _viz_config[_viz_1].y = 0.7597760077522477 16 | _viz_config[_viz_1].max_value = 30 17 | _viz_config[_viz_1].min_value = -30 18 | _viz_config[_viz_1].height = 0.18086296306585412 19 | _viz_2 = nengo_gui.components.XYValue(x) 20 | _viz_config[_viz_2].index_x = 1 21 | _viz_config[_viz_2].index_y = 2 22 | _viz_config[_viz_2].max_value = 30 23 | _viz_config[_viz_2].min_value = -30 24 | _viz_config[_viz_2].height = 0.158314 25 | _viz_config[_viz_2].label_visible = True 26 | _viz_config[_viz_2].width = 0.111194 27 | _viz_config[_viz_2].y = 0.504959 28 | _viz_config[_viz_2].x = 0.826298 29 | _viz_3 = nengo_gui.components.XYValue(x) 30 | _viz_config[_viz_3].index_x = 0 31 | _viz_config[_viz_3].index_y = 2 32 | _viz_config[_viz_3].max_value = 30 33 | _viz_config[_viz_3].min_value = -30 34 | _viz_config[_viz_3].height = 0.149203 35 | _viz_config[_viz_3].label_visible = True 36 | _viz_config[_viz_3].width = 0.0996269 37 | _viz_config[_viz_3].y = 0.806341 38 | _viz_config[_viz_3].x = 0.845603 39 | _viz_4 = nengo_gui.components.Raster(x) 40 | _viz_config[_viz_4].label_visible = True 41 | _viz_config[_viz_4].width = 0.19574238956229667 42 | _viz_config[_viz_4].x = 0.29260743445423804 43 | _viz_config[_viz_4].y = 0.15537 44 | _viz_config[_viz_4].height = 0.11388401512807936 45 | _viz_ace_editor = nengo_gui.components.AceEditor() 46 | _viz_net_graph = nengo_gui.components.NetGraph() 47 | _viz_sim_control = nengo_gui.components.SimControl() 48 | _viz_config[_viz_sim_control].kept_time = 4 49 | _viz_config[_viz_sim_control].shown_time = 0.5 50 | _viz_config[model].pos=(-0.0010692667274263545, -0.001473029636967771) 51 | _viz_config[model].size=(1.00316265418783, 1.00316265418783) 52 | _viz_config[model].expanded=True 53 | _viz_config[model].has_layout=True 54 | _viz_config[x].pos=(0.5895287259049579, 0.44925836676648184) 55 | _viz_config[x].size=(0.06855354498430714, 0.08290196137637143) -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/16-ensemble-properties.py: -------------------------------------------------------------------------------- 1 | # Tutorial 16: Ensemble Properties 2 | 3 | # In addition to the number of neurons, the number of dimensions, and the 4 | # radius, there are other parameters that can be specified when creating an 5 | # Ensemble. Here are a few that may be useful. 6 | 7 | # max_rates 8 | # Each neuron has a different maximum firing rate, and this parameter 9 | # specifies the random distribution controlling this. The default is 10 | # a uniform distribution between 200Hz and 400Hz. 11 | 12 | # encoders 13 | # Each neuron has a different preferred stimulus. For a 1-dimensional 14 | # Ensemble, this means that half of the neurons prefer -1 and the other 15 | # half prefer +1. This is why some neurons fire more for large values and 16 | # some for small values. In the example below, we set all the encoders to 17 | # be +1. 18 | 19 | # intercepts 20 | # Each neuron only starts firing when the similarity between the value and 21 | # its preferred value reaches a particular limit. This is normally a 22 | # uniform distribution between -1 and 1. Notice that if you set it to a 23 | # range like 0.5 to 1, then no neurons at all will fire for any values 24 | # between -0.5 and 0.5. This means that any value between -0.5 and 0.5 25 | # will get reduced to exactly zero, which can be useful. 26 | 27 | import nengo 28 | 29 | model = nengo.Network() 30 | with model: 31 | 32 | stim = nengo.Node(0) 33 | 34 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 35 | 36 | b = nengo.Ensemble( 37 | n_neurons=50, dimensions=1, max_rates=nengo.dists.Uniform(50, 100) 38 | ) 39 | 40 | c = nengo.Ensemble(n_neurons=50, dimensions=1, encoders=nengo.dists.Choice([[1]])) 41 | 42 | d = nengo.Ensemble( 43 | n_neurons=50, dimensions=1, intercepts=nengo.dists.Uniform(0.5, 1.0) 44 | ) 45 | 46 | nengo.Connection(stim, a) 47 | nengo.Connection(stim, b) 48 | nengo.Connection(stim, c) 49 | nengo.Connection(stim, d) 50 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/17-neuron-models.py: -------------------------------------------------------------------------------- 1 | # Tutorial 17: Neuron Models 2 | 3 | # Nengo supports multiple different types of neurons. The default is the 4 | # "Leaky Integrate-and-Fire" or LIF neuron. Other supported ones are shown 5 | # here. The LIFRate neuron acts like the LIF neuron, but does not have spikes. 6 | # The Sigmoid is a standard model used in machine learning. The 7 | # RectifiedLinear model simply outputs the absolute value of its input (the 8 | # simplest possible neuron-like operation). The most complex neuron model 9 | # here is the Izhikevich neuron, which has four parameters to adjust and 10 | # has been shown to map very closely to a large number of real biological 11 | # neurons. 12 | 13 | import nengo 14 | 15 | model = nengo.Network() 16 | with model: 17 | 18 | stim = nengo.Node(0) 19 | 20 | a = nengo.Ensemble( 21 | n_neurons=50, dimensions=1, neuron_type=nengo.LIF(tau_rc=0.02, tau_ref=0.002) 22 | ) 23 | 24 | b = nengo.Ensemble( 25 | n_neurons=50, 26 | dimensions=1, 27 | neuron_type=nengo.LIFRate(tau_rc=0.02, tau_ref=0.002), 28 | ) 29 | 30 | c = nengo.Ensemble( 31 | n_neurons=50, 32 | dimensions=1, 33 | neuron_type=nengo.Sigmoid(tau_ref=0.002), 34 | max_rates=nengo.dists.Uniform(250.0, 400.0), 35 | ) 36 | 37 | d = nengo.Ensemble(n_neurons=50, dimensions=1, neuron_type=nengo.RectifiedLinear()) 38 | 39 | e = nengo.Ensemble( 40 | n_neurons=50, 41 | dimensions=1, 42 | neuron_type=nengo.Izhikevich( 43 | tau_recovery=0.02, coupling=0.2, reset_voltage=-65, reset_recovery=8 44 | ), 45 | ) 46 | 47 | nengo.Connection(stim, a) 48 | nengo.Connection(stim, b) 49 | nengo.Connection(stim, c) 50 | nengo.Connection(stim, d) 51 | nengo.Connection(stim, e) 52 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/18-networks.py: -------------------------------------------------------------------------------- 1 | # Tutorial 18: Networks 2 | 3 | # To help organize larger models, you can make Networks inside of the main 4 | # model Network. 5 | # 6 | # In the graphic interface, the items inside these Networks are not shown 7 | # by default. If you double-click on a Network you can show (or hide) its 8 | # internals. 9 | 10 | # Nengo also comes with a collection of pre-made Networks that can help 11 | # simplify the creation of large models. For example, the code below uses a 12 | # nengo.networks.EnsembleArray, which is a shortcut for creating a set of 13 | # identical Ensembles. It also provides a convenient "input" and "output" 14 | # components that let you easily connect to or from all of the Ensembles at 15 | # once. 16 | 17 | 18 | import nengo 19 | 20 | model = nengo.Network() 21 | with model: 22 | stim_a = nengo.Node([0, 0, 0]) 23 | stim_b = nengo.Node([0, 0]) 24 | 25 | part1 = nengo.Network() 26 | with part1: 27 | a = nengo.Ensemble(n_neurons=100, dimensions=3) 28 | b = nengo.Ensemble(n_neurons=100, dimensions=2) 29 | c = nengo.Ensemble(n_neurons=300, dimensions=5) 30 | nengo.Connection(a, c[:3]) 31 | nengo.Connection(b, c[3:]) 32 | nengo.Connection(stim_a, a) 33 | nengo.Connection(stim_b, b) 34 | 35 | part2 = nengo.networks.EnsembleArray(n_neurons=50, n_ensembles=5) 36 | 37 | nengo.Connection(c, part2.input) 38 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/19-spa.py: -------------------------------------------------------------------------------- 1 | # Tutorial 19: Semantic Pointers 2 | 3 | # If we want to represent conceptual information, we need a way to represent 4 | # concepts and symbol-like manipulations using Nengo. We do this by treating 5 | # concepts like vectors: high-dimensional numerical data. That is, each 6 | # concept (like DOG or CAT or VERB or RUNNING) corresponds to a particular 7 | # vector. So HOUSE might be [0.2, 0.6, -0.7, -0.2, 0] and DREAM might be 8 | # [-0.1, -0.7, 0, 0.9, 0.2]. 9 | # 10 | # We call these "semantic" because, in general, we would choose these 11 | # numerical values such that concepts with similar semantics (like DOG and 12 | # CAT) might have similar numerical values. 13 | 14 | # To help work with these vectors, we introduce a new collection of pre-built 15 | # Networks, and a new type of graph. The new pre-built Networks can be 16 | # accessed via nengo.spa ("spa" stands for "Semantic Pointer Architecture", 17 | # a collection of tools for making these sorts of models. A spa.State is 18 | # a Network that holds one vector representing a semantic pointer. 19 | # If the feedback parameter is set, then the spa.State acts like a memory, 20 | # remembering the vector even after the input has been taken away. 21 | # 22 | # The new graph is a "Semantic pointer" graph. Rather than showing the 23 | # individual values, it shows how close the currently represented vector is 24 | # to the ideal original vectors. Furthermore, you can use it as an input 25 | # system as well, and define new concepts. 26 | 27 | # Press play to start the simulation running. Now right-click on the "vision" 28 | # graph (the blank space above the "vision" box in the diagram). Select "Set 29 | # value..." and put in CAT as a value. Nengo will randomly generate a new 30 | # vector to mean CAT and will feed it into the model. Since the vision system 31 | # is connected to the memory system, the memory will gradually store CAT as 32 | # well. Now right-click on vision, go to "Set value" and just leave it blank 33 | # (click OK). The CAT in vision will go away, but the memory should continue 34 | # to store CAT. Now set the vision to DOG. This new vector will be fed into 35 | # the memory, gradually replacing the CAT. (The size and darkness of the words 36 | # indicates how similar the vector is to the ideal vectors for CAT and DOG). 37 | 38 | import nengo 39 | import nengo.spa as spa 40 | 41 | D = 32 # the dimensionality of the vectors 42 | 43 | model = spa.SPA() 44 | with model: 45 | model.vision = spa.State(D) 46 | 47 | model.memory = spa.State(D, feedback=1) 48 | 49 | nengo.Connection(model.vision.output, model.memory.input, transform=0.1) 50 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/19-spa.py.cfg: -------------------------------------------------------------------------------- 1 | _viz_0 = nengo_gui.components.PointerTemplate(model.vision) 2 | _viz_config[_viz_0].label_visible = 1 3 | _viz_config[_viz_0].width = 0.189179 4 | _viz_config[_viz_0].y = 0.394305 5 | _viz_config[_viz_0].x = 0.227748 6 | _viz_config[_viz_0].show_pairs = 0 7 | _viz_config[_viz_0].height = 0.114465 8 | _viz_1 = nengo_gui.components.PointerTemplate(model.memory) 9 | _viz_config[_viz_1].label_visible = 1 10 | _viz_config[_viz_1].width = 0.184328 11 | _viz_config[_viz_1].y = 0.403417 12 | _viz_config[_viz_1].x = 0.771336 13 | _viz_config[_viz_1].show_pairs = 0 14 | _viz_config[_viz_1].height = 0.114465 15 | _viz_ace_editor = nengo_gui.components.AceEditorTemplate() 16 | _viz_net_graph = nengo_gui.components.NetGraphTemplate() 17 | _viz_sim_control = nengo_gui.components.SimControlTemplate() 18 | _viz_config[_viz_sim_control].kept_time = 4 19 | _viz_config[_viz_sim_control].shown_time = 0.5 20 | _viz_config[model].pos=(0, 0) 21 | _viz_config[model].size=(1.0, 1.0) 22 | _viz_config[model].expanded=True 23 | _viz_config[model].has_layout=True 24 | _viz_config[model.memory].pos=(0.7727272727272727, 0.7397494305239181) 25 | _viz_config[model.memory].size=(0.18181818181818182, 0.16025056947608207) 26 | _viz_config[model.memory].expanded=False 27 | _viz_config[model.memory].has_layout=False 28 | _viz_config[model.memory.state].expanded=False 29 | _viz_config[model.memory.state].has_layout=False 30 | _viz_config[model.vision].pos=(0.2272727215791493, 0.7471526195899774) 31 | _viz_config[model.vision].size=(0.18181817612460383, 0.15284738041002283) 32 | _viz_config[model.vision].expanded=False 33 | _viz_config[model.vision].has_layout=False 34 | _viz_config[model.vision.state].expanded=False 35 | _viz_config[model.vision.state].has_layout=False -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/21-spa-sequence.py: -------------------------------------------------------------------------------- 1 | # Tutorial 21: Sequential Semantic Pointer Actions 2 | 3 | # In this example, we define a set of actions that follow through a 4 | # repeating sequence (A, B, C, D, E). This shows that you can define 5 | # actions which affect the performance of later actions. 6 | 7 | # In this example we have changed the default value of the optional argument 8 | # feedback_synapse, which is the time constant controlling the exponential 9 | # decay of the postsynaptic potential. Try using longer time constants 10 | # (e.g. 0.1 or 0.5) and observe what changes. How is the stability of 11 | # a memory representation related to the synaptic time constant? 12 | 13 | import nengo 14 | import nengo.spa as spa 15 | 16 | D = 32 # the dimensionality of the vectors 17 | 18 | model = spa.SPA() 19 | with model: 20 | model.memory = spa.State(D, feedback=1, feedback_synapse=0.01) 21 | 22 | actions = spa.Actions( 23 | "dot(memory, A) --> memory=B", 24 | "dot(memory, B) --> memory=C", 25 | "dot(memory, C) --> memory=D", 26 | "dot(memory, D) --> memory=E", 27 | "dot(memory, E) --> memory=A", 28 | ) 29 | 30 | model.bg = spa.BasalGanglia(actions) 31 | model.thalamus = spa.Thalamus(model.bg) 32 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/22-spa-sequence-controlled.py: -------------------------------------------------------------------------------- 1 | # Tutorial 22: Controlled Sequence of Semantic Pointer Actions 2 | 3 | # Here, we expand on the previous sequence example and define a model 4 | # that instead of starting from A each time, starts from whatever value 5 | # is currently seen. This shows that you can selectively route information 6 | # from one group of neurons to another, depending on what action is 7 | # selected. 8 | # 9 | # Try setting vision to A (using "Set value" on the vision graph). The 10 | # memory should go through the sequence (A, B, C, D, E) and repeat. Now 11 | # set vision to C. It should do (C, D, E) and repeat. 12 | # 13 | # Note that it takes slightly longer for the model to transfer information 14 | # from vision to memory than it does to just go to the next item in the 15 | # sequence. This is due to the time needed for the neurons to respond, 16 | # and is consistent with psychological reaction time data. 17 | 18 | import nengo 19 | import nengo.spa as spa 20 | 21 | D = 32 # the dimensionality of the vectors 22 | 23 | model = spa.SPA() 24 | with model: 25 | model.vision = spa.State(D) 26 | model.memory = spa.State(D, feedback=1, feedback_synapse=0.01) 27 | 28 | actions = spa.Actions( 29 | "dot(memory, A) --> memory=B", 30 | "dot(memory, B) --> memory=C", 31 | "dot(memory, C) --> memory=D", 32 | "dot(memory, D) --> memory=E", 33 | "dot(memory, E) --> memory=vision", 34 | "0.5 --> memory=vision", 35 | ) 36 | 37 | model.bg = spa.BasalGanglia(actions) 38 | model.thalamus = spa.Thalamus(model.bg) 39 | -------------------------------------------------------------------------------- /nengo_gui/examples/tutorial/24-spa-unbinding.py: -------------------------------------------------------------------------------- 1 | # Tutorial 24: Unbinding Concepts 2 | 3 | # Now that we can combine information together into a single structure (see 4 | # the previous tutorial), we also need to be able to extract information 5 | # back out. We do this by exploiting a pseudo-inverse property of the 6 | # binding operation. In particular, A*B*~B is approximately the same as A, 7 | # where ~ means to take the pseudo-inverse of a vector by rearranging its 8 | # elements (in particular, A*~B is the circular correlation of A and B). 9 | # 10 | # Using this approach, we can store bound information in memory and then 11 | # query that memory to ask questions. For this tutorial, we use shape and 12 | # color as inputs exactly as in the previous tutorial. Start by feeding in 13 | # TRIANGLE and BLUE until the memory contains BLUE*TRIANGLE. Now feed in 14 | # CIRCLE and RED until the memory also contains RED*CIRCLE (this is the same 15 | # as in the previous tutorial). Now take away those inputs by setting the 16 | # values of shape and color to nothing. 17 | # 18 | # Once the memory is set up in this way, we can query the memory by presenting 19 | # inputs to the query population. If you put in a query of RED you should 20 | # get an answer of CIRCLE. For CIRCLE you should get RED. For BLUE you should 21 | # get TRIANGLE. And for TRIANGLE you should get BLUE. Notice that the memory 22 | # will gradually decay and fade the longer you try to run the system for. 23 | 24 | import nengo 25 | import nengo.spa as spa 26 | 27 | D = 32 # the dimensionality of the vectors 28 | 29 | model = spa.SPA() 30 | with model: 31 | model.color = spa.State(D) 32 | model.shape = spa.State(D) 33 | model.memory = spa.State(D, feedback=1) 34 | model.query = spa.State(D) 35 | model.answer = spa.State(D) 36 | 37 | actions = spa.Actions( 38 | "memory = color * shape", 39 | "answer = memory * ~query", 40 | ) 41 | 42 | model.cortical = spa.Cortical(actions) 43 | -------------------------------------------------------------------------------- /nengo_gui/grandalf/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ["graphs", "layouts", "routing", "utils"] 2 | -------------------------------------------------------------------------------- /nengo_gui/grandalf/nx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # This code is part of Grandalf 4 | # Copyright (C) 2014 Axel Tillequin (bdcht3@gmail.com) and others 5 | # published under GPLv2 license or EPLv1 license 6 | # Contributor(s): Axel Tillequin, Fabio Zadrozny 7 | 8 | """ 9 | Some utilities to interact with networkx. 10 | """ 11 | 12 | from grandalf.graphs import Edge, Graph, Vertex 13 | 14 | 15 | def convert_grandalf_graph_to_networkx_graph(G): 16 | """ 17 | Converts a grandalf graph to a networkx graph. 18 | 19 | Note that the edge concept is the same, but a vertex in grandalf is called a node in networkx. 20 | """ 21 | import networkx 22 | 23 | networkx_graph = networkx.MultiDiGraph() 24 | for v in G.V(): 25 | networkx_graph.add_node(v.data) 26 | 27 | for e in G.E(): 28 | networkx_graph.add_edge(e.v[0].data, e.v[1].data) 29 | 30 | return networkx_graph 31 | 32 | 33 | def convert_nextworkx_graph_to_grandalf(G): 34 | """ 35 | Converts a networkx graph to a grandalf graph. 36 | 37 | Note that the edge concept is the same, but a vertex in grandalf is called a node in networkx. 38 | """ 39 | V = [] 40 | data_to_V = {} 41 | for x in G.nodes(): 42 | vertex = Vertex(x) 43 | V.append(vertex) 44 | data_to_V[x] = vertex 45 | 46 | E = [Edge(data_to_V[xy[0]], data_to_V[xy[1]], data=xy) for xy in G.edges()] 47 | g = Graph(V, E) 48 | return g 49 | -------------------------------------------------------------------------------- /nengo_gui/ipython.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | 3 | warnings.warn( 4 | DeprecationWarning("nengo_gui.ipython has been renamed to nengo_gui.jupyter.") 5 | ) 6 | 7 | from nengo_gui.jupyter import * 8 | -------------------------------------------------------------------------------- /nengo_gui/namefinder.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | 3 | 4 | class NameFinder(object): 5 | def __init__(self, terms, net): 6 | self.base_terms = terms 7 | self.known_name = {} 8 | for k, v in terms.items(): 9 | if not k.startswith("_"): 10 | try: 11 | self.known_name[v] = k 12 | except TypeError: 13 | pass 14 | self.find_names(net) 15 | 16 | def find_names(self, net): 17 | net_name = self.known_name[net] 18 | 19 | base_lists = ["ensembles", "nodes", "connections", "networks"] 20 | all_lists = [ 21 | "all_ensembles", 22 | "all_nodes", 23 | "all_connections", 24 | "all_networks", 25 | "all_objects", 26 | "all_probes", 27 | ] 28 | 29 | classes = (nengo.Node, nengo.Ensemble, nengo.Network, nengo.Connection) 30 | 31 | for inst_attr in dir(net): 32 | private = inst_attr.startswith("_") 33 | in_lists = inst_attr in base_lists + all_lists 34 | if not private and not in_lists: 35 | attr = getattr(net, inst_attr) 36 | if isinstance(attr, list): 37 | for i, obj in enumerate(attr): 38 | if obj not in self.known_name: 39 | n = "%s.%s[%d]" % (net_name, inst_attr, i) 40 | self.known_name[obj] = n 41 | elif isinstance(attr, classes): 42 | if attr not in self.known_name: 43 | self.known_name[attr] = "%s.%s" % (net_name, inst_attr) 44 | 45 | for obj_type in base_lists: 46 | for i, obj in enumerate(getattr(net, obj_type)): 47 | name = self.known_name.get(obj, None) 48 | if name is None: 49 | name = "%s.%s[%d]" % (net_name, obj_type, i) 50 | self.known_name[obj] = name 51 | 52 | for n in net.networks: 53 | self.find_names(n) 54 | 55 | def name(self, obj): 56 | return self.known_name[obj] 57 | -------------------------------------------------------------------------------- /nengo_gui/nossl.py: -------------------------------------------------------------------------------- 1 | class SSLError(Exception): 2 | pass 3 | 4 | 5 | def wrap_socket(socket, certfile, keyfile, server_side): 6 | raise SSLError("Could not import ssl") 7 | -------------------------------------------------------------------------------- /nengo_gui/password.py: -------------------------------------------------------------------------------- 1 | """Password hashing functions replicating bcrypt API.""" 2 | 3 | from __future__ import print_function 4 | 5 | import binascii 6 | import hashlib 7 | import os 8 | from getpass import getpass 9 | 10 | 11 | def gensalt(size=16): 12 | return binascii.hexlify(os.urandom(size)).decode("ascii") 13 | 14 | 15 | def hashpw(password, salt, algorithm="sha1"): 16 | h = hashlib.new(algorithm) 17 | h.update(password.encode("utf-8")) 18 | h.update(salt.encode("ascii")) 19 | return algorithm + ":" + salt + ":" + h.hexdigest() 20 | 21 | 22 | def checkpw(password, hashed): 23 | algorithm, salt, _ = hashed.split(":") 24 | return hashpw(password, salt, algorithm) == hashed 25 | 26 | 27 | def prompt_pw(): 28 | while True: 29 | p0 = getpass("Enter password: ") 30 | p1 = getpass("Enter password: ") 31 | if p0 == p1: 32 | return p0 33 | print("Passwords do not match. Please try again.") 34 | -------------------------------------------------------------------------------- /nengo_gui/seed_generation.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | import nengo.utils.numpy as npext 3 | import numpy as np 4 | 5 | 6 | def define_all_seeds(net, seeds=None): 7 | if seeds is None: 8 | seeds = {} 9 | 10 | if net.seed is None: 11 | if net not in seeds: 12 | # this only happens at the very top level 13 | seeds[net] = np.random.randint(npext.maxint) 14 | rng = np.random.RandomState(seed=seeds[net]) 15 | else: 16 | rng = np.random.RandomState(seed=net.seed) 17 | 18 | # let's use the same algorithm as the builder, just to be consistent 19 | sorted_types = sorted(net.objects, key=lambda t: t.__name__) 20 | for obj_type in sorted_types: 21 | for obj in net.objects[obj_type]: 22 | # generate a seed for each item, so that manually setting a seed 23 | # for a particular item doesn't change the generated seed for 24 | # other items 25 | generated_seed = rng.randint(npext.maxint) 26 | if obj.seed is None: 27 | seeds[obj] = generated_seed 28 | 29 | for subnet in net.networks: 30 | define_all_seeds(subnet, seeds) 31 | 32 | return seeds 33 | -------------------------------------------------------------------------------- /nengo_gui/static/ace.css: -------------------------------------------------------------------------------- 1 | #rightpane { 2 | -webkit-flex: 0 0 auto; 3 | flex: 0 0 auto; 4 | 5 | display: -webkit-flex; 6 | display: flex; 7 | -webkit-flex-direction: column; 8 | flex-direction: column; 9 | } 10 | 11 | #editor { 12 | border-left:5px solid #606060; 13 | flex: 1 1 auto; 14 | } 15 | 16 | #console { 17 | border-top:5px solid #606060; 18 | border-left:5px solid #606060; 19 | padding: 0.5em; 20 | border-radius: 0px; 21 | overflow: auto; 22 | background: white; 23 | -webkit-flex: 0 0 auto; 24 | flex: 0 0 auto; 25 | -webkit-user-select: text; 26 | -khtml-user-select: text; 27 | -moz-user-select: text; 28 | -ms-user-select: text; 29 | user-select: text; 30 | display: block; 31 | } 32 | 33 | #console pre { 34 | padding: 0px; 35 | margin: 0px; 36 | background: none; 37 | border: 0px; 38 | /* Use same font-family as Ace editor */ 39 | font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace; 40 | white-space: pre-wrap; 41 | } 42 | 43 | #console_stdout { 44 | color: #1c73b3; 45 | } 46 | 47 | #console_error { 48 | color: #d65e00; 49 | font-weight: 600; 50 | } 51 | -------------------------------------------------------------------------------- /nengo_gui/static/components/htmlview.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Arbitrary HTML display taking input from a Node 3 | * See nengo_gui/examples/basics/html.py for example usage 4 | * @constructor 5 | * 6 | * @param {DOMElement} parent - the element to add this component to 7 | * @param {Nengo.SimControl} sim - the simulation controller 8 | * @param {dict} args - A set of constructor arguments (see Nengo.Component) 9 | */ 10 | 11 | Nengo.HTMLView = function(parent, sim, args) { 12 | Nengo.Component.call(this, parent, args); 13 | var self = this; 14 | 15 | this.sim = sim; 16 | 17 | this.pdiv = document.createElement('div'); 18 | this.pdiv.style.width = '100%'; 19 | this.pdiv.style.height = '100%'; 20 | Nengo.set_transform(this.pdiv, 0, 0); 21 | this.pdiv.style.position = 'fixed'; 22 | this.pdiv.classList.add('htmlview'); 23 | this.div.appendChild(this.pdiv); 24 | 25 | /** for storing the accumulated data */ 26 | this.data_store = new Nengo.DataStore(1, this.sim, 0); 27 | 28 | /** call schedule_update whenever the time is adjusted in the SimControl */ 29 | this.sim.div.addEventListener('adjust_time', 30 | function(e) {self.schedule_update();}, false); 31 | 32 | this.on_resize(this.get_screen_width(), this.get_screen_height()); 33 | 34 | 35 | 36 | }; 37 | Nengo.HTMLView.prototype = Object.create(Nengo.Component.prototype); 38 | Nengo.HTMLView.prototype.constructor = Nengo.Pointer; 39 | 40 | 41 | /** 42 | * Receive new line data from the server 43 | */ 44 | Nengo.HTMLView.prototype.on_message = function(event) { 45 | var data = event.data.split(" ", 1); 46 | var time = parseFloat(data[0]); 47 | 48 | var msg = event.data.substring(data[0].length + 1); 49 | 50 | this.data_store.push([time, msg]); 51 | this.schedule_update(); 52 | } 53 | 54 | /** 55 | * Redraw the lines and axis due to changed data 56 | */ 57 | Nengo.HTMLView.prototype.update = function() { 58 | /** let the data store clear out old values */ 59 | this.data_store.update(); 60 | 61 | var data = this.data_store.get_last_data()[0]; 62 | 63 | if (data === undefined) { 64 | data = ''; 65 | } 66 | 67 | this.pdiv.innerHTML = data; 68 | 69 | }; 70 | 71 | /** 72 | * Adjust the graph layout due to changed size 73 | */ 74 | Nengo.HTMLView.prototype.on_resize = function(width, height) { 75 | if (width < this.minWidth) { 76 | width = this.minWidth; 77 | } 78 | if (height < this.minHeight) { 79 | height = this.minHeight; 80 | }; 81 | 82 | this.width = width; 83 | this.height = height; 84 | //this.div.style.width = width; 85 | //this.div.style.height = height; 86 | 87 | this.label.style.width = width; 88 | 89 | this.update(); 90 | }; 91 | -------------------------------------------------------------------------------- /nengo_gui/static/components/netgraph.css: -------------------------------------------------------------------------------- 1 | .netgraph { 2 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 3 | } 4 | 5 | .ensemble{ 6 | stroke-width:1; 7 | } 8 | 9 | g.node rect{ 10 | stroke-width:1; 11 | } 12 | 13 | g.net rect{ 14 | stroke-width:1; 15 | } 16 | 17 | .netgraph g text { 18 | text-anchor: middle; 19 | dominant-baseline: text-before-edge; 20 | cursor: default !important; 21 | } 22 | 23 | .netgraph g text:active { 24 | cursor: move; 25 | } 26 | 27 | .netgraph path.conn { 28 | stroke: black; 29 | stroke-width: 2px; 30 | fill: none; 31 | } 32 | 33 | .netgraph g.excitatory > .conn { 34 | stroke: #3465a4; 35 | } 36 | 37 | .netgraph g.excitatory > .marker { 38 | fill: #3465a4; 39 | } 40 | 41 | .netgraph g.inhibitory > .conn { 42 | stroke: #c00000; 43 | } 44 | 45 | .netgraph g.inhibitory > .marker { 46 | fill: #c00000; 47 | } 48 | 49 | .netgraph g.modulatory > .conn { 50 | stroke: #8eb627; 51 | stroke-dasharray: 1em; 52 | } 53 | 54 | .netgraph g.modulatory > .marker { 55 | fill: #8eb627; 56 | } 57 | 58 | .minimap { 59 | border-radius: 10px/60px; 60 | height: 100%; 61 | opacity: 0.85; 62 | position: 'relative'; 63 | width: 100%; 64 | } 65 | 66 | .minimap path.conn { 67 | stroke: black; 68 | stroke-width: 1px; 69 | fill: none; 70 | } 71 | 72 | rect.view{ 73 | fill: #d9edf7; 74 | stroke: #ccc; 75 | } 76 | 77 | .recur { 78 | stroke: black; 79 | stroke-width: 2px; 80 | fill: none; 81 | } 82 | 83 | .netgraph g.passthrough ellipse { 84 | stroke-width: 0px; 85 | fill: black; 86 | } 87 | 88 | .netgraph g.passthrough text { 89 | text-anchor: middle; 90 | dominant-baseline: text-before-edge; 91 | } 92 | 93 | -------------------------------------------------------------------------------- /nengo_gui/static/components/pointer.css: -------------------------------------------------------------------------------- 1 | .pointer span { 2 | display:block; 3 | margin:0px; 4 | padding:0px; 5 | text-align: center; 6 | } -------------------------------------------------------------------------------- /nengo_gui/static/components/progress.js: -------------------------------------------------------------------------------- 1 | Nengo.Progress = function (args) { 2 | var self = this; 3 | this.ws = Nengo.create_websocket(args.uid); 4 | this.ws.onmessage = function(event) { self.on_message(event); } 5 | }; 6 | 7 | Nengo.Progress.prototype.on_message = function(event) { 8 | var data = JSON.parse(event.data); 9 | var progress = document.getElementById('build-progress'); 10 | var text; 11 | 12 | if (data.finished) { 13 | text = data.name_after + ' finished in ' + data.elapsed_time + '.'; 14 | } else if (data.max_steps === null) { 15 | text = data.name_during + '… duration: ' + data.elapsed_time; 16 | } else { 17 | text = data.name_during + '… ' + 18 | (100 * data.progress).toFixed(0) + '%, ETA: ' + data.eta; 19 | } 20 | 21 | progress.getElementsByClassName('pb-text')[0].innerHTML = text; 22 | 23 | var fill = progress.getElementsByClassName('pb-fill')[0] 24 | if (data.max_steps === null) { 25 | fill.style.width = '100%'; 26 | fill.style.animation = 'pb-fill-anim 2s linear infinite'; 27 | fill.style.backgroundSize = '100px 100%'; 28 | fill.style.backgroundImage = 'repeating-linear-gradient(' + 29 | '90deg, #bdd2e6, #edf2f8 40%, #bdd2e6 80%, #bdd2e6)'; 30 | } else { 31 | if (data.progress > 0) { 32 | fill.style.transition = 'width 0.1s linear'; 33 | } else { 34 | fill.style.transition = 'none'; 35 | } 36 | fill.style.width = (100 * data.progress) + '%'; 37 | fill.style.animation = 'none'; 38 | fill.style.backgroundImage = 'none'; 39 | } 40 | 41 | if (data.finished) { 42 | fill.style.animation = 'none'; 43 | fill.style.backgroundImage = 'none'; 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /nengo_gui/static/components/raster.css: -------------------------------------------------------------------------------- 1 | .graph .spikes { 2 | fill: none; 3 | stroke: black; 4 | stroke-width: 1.5px; 5 | } 6 | -------------------------------------------------------------------------------- /nengo_gui/static/components/slider.css: -------------------------------------------------------------------------------- 1 | .guideline{ 2 | background-color: #ddd; 3 | z-index: -1; 4 | 5 | border: 1px solid #888; 6 | border-radius: 4px; 7 | } 8 | 9 | input#value_in_field { 10 | cursor: text !important; 11 | } 12 | -------------------------------------------------------------------------------- /nengo_gui/static/components/spa_similarity.css: -------------------------------------------------------------------------------- 1 | .graph .line { 2 | fill: none; 3 | stroke: black; 4 | stroke-width: 1.5px; 5 | } 6 | 7 | .legend { 8 | padding: 5px; 9 | font: 10px sans-serif; 10 | position: absolute; 11 | display: inline; 12 | } 13 | -------------------------------------------------------------------------------- /nengo_gui/static/components/time_axes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 2d axes set with the horizontal axis being a time axis. 3 | * @constructor 4 | * 5 | * @param {DOMElement} parent - the element to add this component to 6 | * @param {dict} args - A set of constructor arguments (see Nengo.Axes2D) 7 | * 8 | * Called by a specific component when it requires an axes set (with the 9 | * x-axis showing current model time). 10 | */ 11 | 12 | Nengo.TimeAxes = function(parent, args) { 13 | Nengo.Axes2D.call(this, parent, args); 14 | var self = this; 15 | this.display_time = args.display_time; 16 | 17 | 18 | this.axis_x.ticks(0); 19 | 20 | this.axis_time_end =this.svg.append("text") 21 | .text("Time: NULL") 22 | .attr('class', 'graph_text unselectable')[0][0]; 23 | this.axis_time_start =this.svg.append("text") 24 | .text("Time: NULL") 25 | .attr('class','graph_text unselectable')[0][0]; 26 | 27 | if (this.display_time == false) { 28 | this.axis_time_start.style.display = 'none'; 29 | this.axis_time_end.style.display = 'none'; 30 | } 31 | }; 32 | Nengo.TimeAxes.prototype = Object.create(Nengo.Axes2D.prototype); 33 | Nengo.TimeAxes.prototype.constructor = Nengo.TimeAxes; 34 | 35 | Nengo.TimeAxes.prototype.set_time_range = function(start, end) { 36 | this.scale_x.domain([start, end]); 37 | this.axis_time_start.textContent = start.toFixed(3); 38 | this.axis_time_end.textContent = end.toFixed(3); 39 | this.axis_x_g.call(this.axis_x); 40 | }; 41 | 42 | Nengo.TimeAxes.prototype.on_resize = function(width, height) { 43 | Nengo.Axes2D.prototype.on_resize.call(this, width, height); 44 | 45 | scale = parseFloat($('#main').css('font-size')); 46 | var suppression_width = 6 * scale; 47 | var text_offset = 1.2 * scale; 48 | 49 | if (width < suppression_width || this.display_time == false){ 50 | this.axis_time_start.style.display = 'none'; 51 | } else { 52 | this.axis_time_start.style.display = 'block'; 53 | } 54 | 55 | this.axis_time_start.setAttribute('y', this.ax_bottom + text_offset); 56 | this.axis_time_start.setAttribute('x', this.ax_left - text_offset); 57 | this.axis_time_end.setAttribute('y', this.ax_bottom + text_offset); 58 | this.axis_time_end.setAttribute('x', this.ax_right - text_offset); 59 | }; 60 | -------------------------------------------------------------------------------- /nengo_gui/static/components/value.css: -------------------------------------------------------------------------------- 1 | .graph .line { 2 | fill: none; 3 | stroke: black; 4 | stroke-width: 1.5px; 5 | } 6 | -------------------------------------------------------------------------------- /nengo_gui/static/components/xy_axes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Basic 2d axes set. 3 | * @constructor 4 | * 5 | * @param {float} args.width - the width of the axes (in pixels) 6 | * @param {float} args.height - the height of the axes (in pixels) 7 | * @param {float} args.min_value - minimum value on y-axis 8 | * @param {float} args.max_value - maximum value on y-axis 9 | */ 10 | 11 | Nengo.XYAxes = function(parent, args) { 12 | Nengo.Axes2D.call(this, parent, args); 13 | 14 | this.scale_x.domain([args.min_value, args.max_value]); 15 | this.axis_x.tickValues([args.min_value, args.max_value]); 16 | this.axis_x.ticks(this.axis_y.ticks()[0]); 17 | 18 | this.min_val = args.min_value; 19 | this.max_val = args.max_value; 20 | }; 21 | 22 | Nengo.XYAxes.prototype = Object.create(Nengo.Axes2D.prototype); 23 | Nengo.XYAxes.prototype.constructor = Nengo.XYAxes; 24 | 25 | /** 26 | * Adjust the graph layout due to changed size 27 | */ 28 | Nengo.XYAxes.prototype.on_resize = function(width, height) { 29 | Nengo.Axes2D.prototype.on_resize.call(this, width, height); 30 | 31 | var x_offset = this.ax_bottom - this.min_val / (this.max_val - this.min_val) * (this.ax_top - this.ax_bottom); 32 | var y_offset = this.ax_left - this.min_val / (this.max_val - this.min_val) * (this.ax_right - this.ax_left); 33 | 34 | this.axis_x_g.attr("transform", "translate(0," + x_offset + ")"); 35 | this.axis_x_g.call(this.axis_x); 36 | this.axis_y_g.attr("transform", "translate(" + y_offset + ", 0)"); 37 | this.axis_y_g.call(this.axis_y); 38 | }; 39 | -------------------------------------------------------------------------------- /nengo_gui/static/components/xyvalue.css: -------------------------------------------------------------------------------- 1 | .warning-text { 2 | color:#a94442; 3 | position: absolute; 4 | text-align: center; 5 | margin-left: 20%; 6 | margin-right: auto; 7 | width:60%; 8 | top:37%; 9 | display:box; 10 | box-align:center; 11 | box-pack:center; 12 | border: 1px dashed #a94442; 13 | background-color: white; 14 | } 15 | -------------------------------------------------------------------------------- /nengo_gui/static/config.js: -------------------------------------------------------------------------------- 1 | Nengo.Config = function(parent, args) { 2 | var self = this; 3 | 4 | define_option = function(key, default_val) { 5 | var type = typeof(default_val); 6 | Object.defineProperty(self, key, { 7 | get: function() { 8 | var val = localStorage.getItem("ng." + key) || default_val; 9 | if (type === "boolean") { 10 | return val === "true" || val === true; 11 | } else if (type === "number") { 12 | return Number(val); 13 | } else { 14 | return val; 15 | } 16 | }, 17 | set: function(val) { 18 | return localStorage.setItem("ng." + key, val); 19 | }, 20 | enumerable: true 21 | }); 22 | }; 23 | 24 | // General options accessible through Configuration Options 25 | define_option("transparent_nets", false); 26 | define_option("aspect_resize", false); 27 | define_option("zoom_fonts", false); 28 | define_option("font_size", 100); 29 | define_option("scriptdir", "."); 30 | define_option("autocomplete", true); 31 | 32 | // Ace editor options 33 | define_option("hide_editor", false); 34 | define_option("editor_width", 580); 35 | define_option("editor_font_size", 12); 36 | define_option("auto_update", true); 37 | define_option("console_height", 100); 38 | }; 39 | 40 | Nengo.Config.prototype.restore_defaults = function() { 41 | for (var option in this) { 42 | if (this.hasOwnProperty(option)) { 43 | localStorage.removeItem("ng." + option); 44 | } 45 | } 46 | } 47 | 48 | Nengo.config = new Nengo.Config(); 49 | -------------------------------------------------------------------------------- /nengo_gui/static/data_to_csv.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A function that returns simulation data as a csv, only saves data which is present in graphs. 3 | * As well it only saves the data in the datastore, which is based on the 4 | * amount of time kept in the simulation. 5 | * 6 | * @param {Nengo.Component.components} data_set: A list of the graph items in the simulation 7 | * 8 | */ 9 | 10 | 11 | var data_to_csv = function(data_set){ 12 | 13 | var values = []; 14 | var dim_values = []; 15 | var times = []; 16 | var csv = []; 17 | var csv_string = ""; 18 | 19 | var data_set = data_set.filter(function(data){ 20 | return (data.constructor === Nengo.Value || data.constructor === Nengo.XYValue) 21 | }); 22 | 23 | //Extracts all the values from the data_set variable 24 | for(var x = 0; x < data_set.length; x++){ 25 | values.push([]); 26 | for(var y = 0; y < data_set[x].data_store.data.length; y++){ 27 | values[x].push(data_set[x].data_store.data[y]); 28 | } 29 | 30 | } 31 | //Grabs all the time steps 32 | times = data_set[0].data_store.times; 33 | 34 | //Headers for the csv file 35 | csv.push(["Graph Name"]); 36 | csv.push(["Times"]); 37 | 38 | //Adds ensemble name and appropirate number of spaces to the header 39 | for(var x = 0; x < data_set.length; x++){ 40 | csv[0].push(data_set[x].label.innerHTML); 41 | for(var z = 0; z < values[x].length-1; z++){ 42 | csv[0].push([]); 43 | } 44 | 45 | } 46 | for(var x = 0; x < values.length; x++){ 47 | for(var y = 0; y < values[x].length; y++){ 48 | csv[1].push("Dimension"+(y+1)); 49 | } 50 | } 51 | 52 | //Puts the data at each time step into a row in the csv 53 | for (var x = 0; x < times.length; x++){ 54 | temp_arr = [times[x]] 55 | for(var y = 0; y < values.length; y++){ 56 | for(var z = 0; z < values[y].length; z++){ 57 | temp_arr.push(values[y][z][x]) 58 | } 59 | } 60 | csv.push(temp_arr); 61 | } 62 | 63 | //Turns the array into a CSV string 64 | csv.forEach(function(elem,index){csv[index]=elem.join(",");}); 65 | csv_string = csv.join("\n"); 66 | return csv_string; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /nengo_gui/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/favicon.ico -------------------------------------------------------------------------------- /nengo_gui/static/lib/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /nengo_gui/static/lib/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /nengo_gui/static/lib/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /nengo_gui/static/lib/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /nengo_gui/static/lib/js/jqueryFileTree/images/directory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/js/jqueryFileTree/images/directory.png -------------------------------------------------------------------------------- /nengo_gui/static/lib/js/jqueryFileTree/images/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/js/jqueryFileTree/images/file.png -------------------------------------------------------------------------------- /nengo_gui/static/lib/js/jqueryFileTree/images/folder_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/js/jqueryFileTree/images/folder_open.png -------------------------------------------------------------------------------- /nengo_gui/static/lib/js/jqueryFileTree/images/scriptgen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/js/jqueryFileTree/images/scriptgen.png -------------------------------------------------------------------------------- /nengo_gui/static/lib/js/jqueryFileTree/images/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nengo/nengo-gui/9a353d48f3fde391a7b0d4e9945ce51508120352/nengo_gui/static/lib/js/jqueryFileTree/images/spinner.gif -------------------------------------------------------------------------------- /nengo_gui/static/lib/js/jqueryFileTree/jqueryFileTree.css: -------------------------------------------------------------------------------- 1 | UL.jqueryFileTree { 2 | font-family: Verdana, sans-serif; 3 | font-size: 14px; 4 | line-height: 20px; 5 | padding: 0px; 6 | margin: 0px; 7 | } 8 | 9 | UL.jqueryFileTree LI { 10 | list-style: none; 11 | padding: 0px; 12 | padding-left: 20px; 13 | margin: 0px; 14 | white-space: nowrap; 15 | } 16 | 17 | UL.jqueryFileTree A { 18 | color: #333; 19 | text-decoration: none; 20 | display: block; 21 | padding: 0px 2px; 22 | } 23 | 24 | UL.jqueryFileTree A:hover { 25 | background: #BBB; 26 | } 27 | 28 | /* Core Styles */ 29 | .jqueryFileTree LI.directory { background: url(images/directory.png) left top no-repeat; } 30 | .jqueryFileTree LI.expanded { background: url(images/folder_open.png) left top no-repeat; } 31 | .jqueryFileTree LI.file { background: url(images/file.png) left top no-repeat; } 32 | .jqueryFileTree LI.wait { background: url(images/spinner.gif) left top no-repeat; } 33 | -------------------------------------------------------------------------------- /nengo_gui/static/main.css: -------------------------------------------------------------------------------- 1 | html { 2 | height: 100%; 3 | } 4 | 5 | body { 6 | margin: 0px; 7 | height: 100%; 8 | width: 100%; 9 | cursor: inherit; 10 | display: -webkit-flex; 11 | display: flex; 12 | -webkit-flex-direction: column; 13 | flex-direction: column; 14 | -webkit-touch-callout: none; 15 | -webkit-user-select: none; 16 | -khtml-user-select: none; 17 | -moz-user-select: none; 18 | -ms-user-select: none; 19 | user-select: none; 20 | } 21 | 22 | 23 | #main { 24 | background: white; 25 | -webkit-flex: 0 0 auto; 26 | flex: 1 1 auto; 27 | position: relative; 28 | overflow: hidden; 29 | } 30 | 31 | #vmiddle { 32 | position: relative; 33 | -webkit-flex: 1 1 auto; 34 | flex: 1 1 auto; 35 | display: -webkit-flex; 36 | display: flex; 37 | -webkit-flex-direction: row; 38 | flex-direction: row; 39 | } 40 | 41 | #control table { 42 | margin-bottom: 0; 43 | } 44 | 45 | div.minimap { 46 | background: white; 47 | border: 2px solid #787878; 48 | height: 15%; 49 | width: 15%; 50 | left: 84.5%; 51 | top: 82.5%; 52 | position: absolute; 53 | z-index: 99999999; 54 | } 55 | 56 | .graph { 57 | background: #eeeeee; 58 | } 59 | 60 | .line { 61 | fill: none; 62 | stroke: black; 63 | stroke-width: 1.5px; 64 | } 65 | 66 | #statusbar { 67 | padding: 0 0.5em 0.5em 0.5em; 68 | font-size: 85%; 69 | overflow: hidden; 70 | } 71 | 72 | #build-progress { 73 | float: right; 74 | width: 33%; 75 | overflow: hidden; 76 | border: 1px solid #ccc; 77 | border-radius: 4px; 78 | text-align: center; 79 | position: relative; 80 | background-color: #fff; 81 | box-sizing: border-box; 82 | } 83 | 84 | .pb-text { 85 | position: absolute; 86 | width: 100%; 87 | } 88 | 89 | .pb-fill { 90 | background-color: #bdd2e6; 91 | width: 0%; 92 | 93 | } 94 | 95 | @keyframes pb-fill-anim { 96 | 0% { background-position: -100px 0px }; 97 | 100% { background-position: 0px 0px }; 98 | } 99 | -------------------------------------------------------------------------------- /nengo_gui/static/menu.css: -------------------------------------------------------------------------------- 1 | .menu-item{ 2 | font-size: .8em; 3 | text-align: left; 4 | cursor: pointer !important; 5 | } 6 | -------------------------------------------------------------------------------- /nengo_gui/static/modal.css: -------------------------------------------------------------------------------- 1 | .modal-body .tab-pane { 2 | margin: 20px; 3 | } 4 | 5 | .modal-body input { 6 | cursor: text !important; 7 | } 8 | 9 | .modal-body .tab-pane .dt-connections { 10 | margin-top: 20px; 11 | } 12 | 13 | .modal-body .axis path, 14 | .modal-body .axis line { 15 | fill: none; 16 | stroke: #000; 17 | shape-rendering: crispEdges; 18 | } 19 | 20 | .modal-body .form-group { 21 | text-indent: 20px; 22 | } 23 | 24 | .modal-body .with-errors { 25 | font-size: .8em; 26 | } 27 | 28 | div.modal-backdrop { 29 | z-index: 100000000; 30 | } 31 | 32 | .alert .glyphicon { 33 | padding-right: 5px; 34 | } 35 | 36 | .modal-body .tab-pane .list-group-item { 37 | padding: 5px 10px; 38 | } 39 | 40 | .modal-body .tab-pane .list-group-item.shaded { 41 | color: #aaaaaa; 42 | } 43 | 44 | .modal-body .tab-pane > h3 { 45 | font-size: 1.3em; 46 | font-weight: bold; 47 | } 48 | 49 | .modal-body .tab-pane th { 50 | font-size: 1em; 51 | font-weight: bold; 52 | border: 0px; 53 | background-color: #dddddd; 54 | } 55 | 56 | .modal-body .tab-pane td { 57 | font-size: 0.9em; 58 | border: 0px; 59 | } 60 | 61 | .modal-body table .conn-objs { 62 | width: 30%; 63 | } 64 | 65 | .modal-body table .conn-funcs { 66 | width: 50%; 67 | } 68 | 69 | .modal-body table .conn-fan { 70 | width: 20%; 71 | } 72 | 73 | .modal-body table ul > li > .glyphicon, 74 | .modal-body table ul > li > .glyphicon { 75 | padding-right: 8px; 76 | } 77 | 78 | .modal-body th .glyphicon { 79 | padding-left: 8px; 80 | } 81 | 82 | .modal-body .tooltip-inner { 83 | white-space: pre-wrap; 84 | text-align: left; 85 | max-width: 350px; 86 | } 87 | 88 | .modal-body .popover { 89 | max-width: 350px; 90 | } 91 | 92 | .modal-body .popover-title, 93 | .modal-body .popover-content { 94 | white-space: pre-wrap; 95 | text-align: left; 96 | font-size: 0.9em; 97 | padding: 5px 10px; 98 | } 99 | 100 | .modal-body .popover-title { 101 | line-height: 1.2; 102 | } 103 | 104 | div.modal { 105 | z-index: 100000001; 106 | cursor: default !important; 107 | } 108 | 109 | #config-fontsize.form-control, #config-scriptdir.form-control { 110 | padding: 6px 6px; 111 | height: 35px; 112 | } 113 | 114 | .input-group .input-group-addon { 115 | text-indent:0px; 116 | } 117 | 118 | #myModalForm .form-group { 119 | margin-bottom: 0px; 120 | } 121 | 122 | #myModalForm .checkbox { 123 | padding-top: 0px; 124 | text-indent: 10px; 125 | } 126 | 127 | #myModalForm .form-group select, #myModalForm .form-group input[type=text] { 128 | width: calc(100% - 40px); 129 | margin-left: 20px; 130 | } 131 | 132 | .input-group.col-xs-2 { 133 | left:20px; 134 | } 135 | 136 | .modal-dialog.modal-sm td { 137 | padding: 4px; 138 | } 139 | 140 | #myModalForm .disabled { 141 | color: darkgrey; 142 | } 143 | -------------------------------------------------------------------------------- /nengo_gui/static/nengo.css: -------------------------------------------------------------------------------- 1 | .graph { 2 | background-color:rgba(255,0,0,0); 3 | border: 1px solid rgba(255,0,0,0); 4 | } 5 | 6 | .graph:hover { 7 | border: 1px solid #888888; 8 | } 9 | 10 | .graph text { 11 | cursor: default; 12 | } 13 | 14 | .graph text:active { 15 | cursor: move; 16 | } 17 | 18 | .graph .line { 19 | fill: none; 20 | stroke: black; 21 | stroke-width: 1.5px; 22 | } 23 | 24 | .graph svg .axis path { 25 | stroke: black; 26 | stroke-width: 1px; 27 | fill: none; 28 | } 29 | 30 | .graph text.graph_text { 31 | font-size: .8em; 32 | pointer-events: none; 33 | } 34 | 35 | .graph .axis text { 36 | font-size: .8em; 37 | pointer-events: none; 38 | } 39 | 40 | .graph .label { 41 | font-size: 1em; 42 | font-family: sans-serif; 43 | font-weight: normal; 44 | color: black; 45 | pointer-events: none; 46 | } 47 | -------------------------------------------------------------------------------- /nengo_gui/static/side_menu.css: -------------------------------------------------------------------------------- 1 | 2 | .sidenav-container { 3 | height: 100%; 4 | width: 250px; 5 | position: absolute; 6 | z-index: 9999; 7 | top: 0; 8 | left: 0; 9 | background-color: #eee; 10 | overflow-x: hidden; 11 | overflow-y: hidden; 12 | transition: 0.5s; 13 | border-right: 1px solid #4D4D4D; 14 | font-size: 0px; 15 | color: #333; 16 | font-family: arial; 17 | transform: translate(-250px); 18 | } 19 | 20 | .sidenav-container .tab-content{ 21 | font-size: 15px; 22 | float: left; 23 | width: 250px; 24 | height:100%; 25 | top: 0px; 26 | margin-right:0px; 27 | color:inherit; 28 | } 29 | 30 | .sidenav-container #Menu_content{ 31 | width: 2000px; 32 | height: 100%; 33 | margin: 0px; 34 | padding: 0px; 35 | } 36 | 37 | .sidenav-container a{ 38 | font-size: 15px; 39 | color: inherit; 40 | display: block; 41 | transition: 0.3s 42 | } 43 | 44 | .side-menu-item, .accordion-toggle { 45 | cursor: pointer; 46 | width: 100%; 47 | background: none; 48 | height:40px; 49 | border-top: solid #999 1px; 50 | border-bottom: solid #999 1px; 51 | margin-bottom: -1px; 52 | color: inherit; 53 | } 54 | 55 | .side-menu-item:hover, .accordion-toggle:hover { 56 | background: #666; 57 | color: #eee; 58 | } 59 | 60 | .side-menu-item .title, .accordion-toggle .title{ 61 | padding-left: 8px; 62 | padding-top: 8px; 63 | float:left; 64 | font-size: 14px; 65 | } 66 | 67 | .side-menu-item.indent{ 68 | background: #ddd; 69 | border: 0px; 70 | padding-top: 1px; 71 | } 72 | 73 | .side-menu-item.indent:hover{ 74 | background: #666; 75 | } 76 | 77 | .side-menu-item.indent .title{ 78 | padding-left: 23px; 79 | padding-top: 8px; 80 | float:left; 81 | font-size: 14px; 82 | } 83 | 84 | 85 | .side-menu-item .icon , .accordion-toggle .icon { 86 | padding-right: 8px; 87 | padding-top: 12px; 88 | float:right; 89 | font-size: 14px; 90 | } 91 | .accordion-content {display: none;} 92 | 93 | .accordion-content.default {display: block;} 94 | 95 | 96 | #filebrowser { 97 | position: relative; 98 | top: 0; 99 | left: 0; 100 | width: 250px; 101 | height: 100%; 102 | border-bottom-right-radius: 4px; 103 | color: inherit; 104 | padding: 0.2em; 105 | background-color: None; 106 | z-index: 99999; 107 | overflow: auto; 108 | cursor: pointer !important; 109 | border-top: solid #999 1px; 110 | } 111 | 112 | #filebrowser a { 113 | color: inherit; 114 | } 115 | 116 | #filebrowser a:hover { 117 | background: #666; 118 | color: #eee; 119 | } 120 | 121 | #filebrowser li.examples_dir { 122 | background-color: #ddd; 123 | } 124 | 125 | @media screen and (max-height: 450px) { 126 | .sidenav {padding-top: 15px;} 127 | .sidenav a {font-size: 18px;} 128 | } 129 | -------------------------------------------------------------------------------- /nengo_gui/static/tooltips.css: -------------------------------------------------------------------------------- 1 | dt > a > .glyphicon, 2 | td > a .glyphicon { 3 | padding-left: 8px; 4 | } 5 | -------------------------------------------------------------------------------- /nengo_gui/static/top_toolbar.css: -------------------------------------------------------------------------------- 1 | #top_toolbar_div .glyphicon { 2 | color: #333; 3 | cursor: default; 4 | top: 0; 5 | border-radius: 0; 6 | } 7 | 8 | #top_toolbar_div .selected { 9 | background: #ccc; 10 | } 11 | 12 | 13 | #top_toolbar_div .glyphicon:hover { 14 | color: #eee; 15 | background: #666; 16 | } 17 | 18 | #top_toolbar_div .deactivated .glyphicon { 19 | color: #ccc; 20 | } 21 | 22 | #top_toolbar_div .deactivated .glyphicon:hover { 23 | color: #ccc; 24 | background: none; 25 | } 26 | 27 | #top_toolbar_div .reversed { 28 | -moz-transform: scaleX(-1); 29 | -o-transform: scaleX(-1); 30 | -webkit-transform: scaleX(-1); 31 | transform: scaleX(-1); 32 | filter: FlipH; 33 | -ms-filter: "FlipH"; 34 | } 35 | 36 | #top_toolbar_div { 37 | position: relative; 38 | flex: 0 0 auto; 39 | -webkit-flex: 0 0 auto; 40 | width: 100%; 41 | z-index: 99999; 42 | } 43 | 44 | #top_toolbar_div .nav { 45 | background: #eee; 46 | box-shadow: 0px 2px 4px 0px #999; 47 | } 48 | 49 | #filename{ 50 | padding: 0.5em; 51 | cursor: default !important; 52 | } 53 | 54 | #Forum_link { 55 | padding: 0.5em; 56 | cursor: hand !important; 57 | } 58 | 59 | #filename:hover, #Forum_link:hover { 60 | color: #eee; 61 | background: #666; 62 | } 63 | 64 | #Help_button, #Forum_link{ 65 | float: right; 66 | } 67 | 68 | #Toggle_ace, #Save_file, #Sync_editor_button, #Font_increase, #Font_decrease{ 69 | float: right; 70 | } 71 | 72 | #top_toolbar_div li.disabled a.glyphicon { 73 | color: #ccc; 74 | background: #eee; 75 | } 76 | 77 | #top_toolbar_div li.in-progress a.glyphicon { 78 | color: #ccc; 79 | background: #c22; 80 | } 81 | 82 | #global_config_menu { 83 | background: purple; 84 | height: 20em; 85 | width: 20em; 86 | z-index: 99999; 87 | margin-top: 3em; 88 | position: absolute; 89 | } 90 | -------------------------------------------------------------------------------- /nengo_gui/static/viewport.js: -------------------------------------------------------------------------------- 1 | Nengo.Viewport = function() { 2 | this.x = 0; 3 | this.y = 0; 4 | this.scale = 1.0; 5 | 6 | this.w = $("#main").width(); 7 | this.h = $("#main").height(); 8 | var self = this; 9 | window.addEventListener("resize", function() {self.on_resize();}); 10 | } 11 | 12 | Nengo.Viewport.prototype.redraw_all = function(event) { 13 | for (var i in Nengo.Component.components) { 14 | var c = Nengo.Component.components[i]; 15 | c.on_resize(c.w * this.scale * this.w * 2, c.h * this.scale * this.h * 2); 16 | c.redraw_size(); 17 | c.redraw_pos(); 18 | } 19 | }; 20 | 21 | Nengo.Viewport.prototype.on_resize = function(event) { 22 | var ow = this.w; 23 | var oh = this.h; 24 | 25 | this.w = $("#main").width(); 26 | this.h = $("#main").height(); 27 | 28 | for (var i in Nengo.Component.components) { 29 | var c = Nengo.Component.components[i]; 30 | if (Nengo.netgraph.aspect_resize) { 31 | c.w = c.w * ow/this.w; 32 | c.h = c.h * oh/this.h; 33 | } 34 | c.on_resize(c.w * this.scale * this.w * 2, 35 | c.h * this.scale * this.h * 2); 36 | c.redraw_size(); 37 | c.redraw_pos(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /nengo_gui/static_plots.py: -------------------------------------------------------------------------------- 1 | import nengo 2 | import numpy as np 3 | from nengo.utils.ensemble import response_curves, tuning_curves 4 | 5 | 6 | class PlotInfo(object): 7 | def __init__(self, title, plot="none"): 8 | self.title = title 9 | self.plot = plot 10 | self.warnings = [] 11 | self.x = None 12 | self.y = None 13 | self.x_label = None 14 | self.y_label = None 15 | 16 | def to_dict(self): 17 | x, y = self.x, self.y 18 | if self.plot == "multiline": 19 | #assert self.x.shape[0] == self.y.shape[1] 20 | x = self.x.tolist() 21 | y = [yy.tolist() for yy in self.y] 22 | return { 23 | "plot": self.plot, 24 | "title": self.title, 25 | "warnings": self.warnings, 26 | "x": x, 27 | "y": y, 28 | "x_label": self.x_label if self.x_label != None else "", 29 | "y_label": self.y_label if self.y_label != None else "", 30 | } 31 | 32 | 33 | def response_curve_plot(ens, sim): 34 | rc = PlotInfo("Response curves", plot="multiline") 35 | rc.x, rc.y = response_curves(ens, sim) 36 | rc.x_label = "Input current" 37 | rc.y = rc.y.T 38 | rc.y_label = "Firing rate (Hz)" 39 | 40 | if len(rc.y.shape) == 1: 41 | rc.y.shape = 1, rc.y.shape[0] 42 | if ens.n_neurons > 200: 43 | rc.warnings.append("Only showing the first 200 neurons.") 44 | rc.y = rc.y[:200] 45 | return rc.to_dict() 46 | 47 | 48 | def tuning_curve_plot(ens, sim): 49 | tc = PlotInfo("Tuning curves") 50 | 51 | if ens.dimensions == 1: 52 | tc.plot = "multiline" 53 | tc.x, tc.y = tuning_curves(ens, sim) 54 | tc.x_label = "x" 55 | tc.y = tc.y.T 56 | tc.y_label = "Firing rate (Hz)" 57 | 58 | if ens.n_neurons > 200: 59 | tc.warnings.append("Only showing the first 200 neurons.") 60 | tc.y = tc.y[:200] 61 | else: 62 | tc.warnings.append("Tuning curves only shown for " "one-dimensional ensembles.") 63 | return tc.to_dict() 64 | 65 | 66 | def node_output_plot(node): 67 | f_out = PlotInfo("Node output") 68 | if node.size_in > 0: 69 | f_out.warnings.append("Node output only shown when 'size_in' is 0.") 70 | else: 71 | f_out.plot = "multiline" 72 | if callable(node.output): 73 | dt = 0.001 74 | f_out.x = np.arange(dt, 1.0, dt) 75 | f_out.y = np.asarray([node.output(x) for x in f_out.x]) 76 | else: 77 | # Don't bother with all the copies if it's static 78 | f_out.x = np.asarray([0, 1.0]) 79 | f_out.y = np.hstack((node.output, node.output)) 80 | if f_out.y.ndim == 1: 81 | f_out.y = f_out.y[:, np.newaxis] 82 | f_out.y = f_out.y.T 83 | return f_out.to_dict() 84 | -------------------------------------------------------------------------------- /nengo_gui/tests/test_basic_functionality.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import time 4 | 5 | import pytest 6 | from nengo_gui import testing_tools as tt 7 | from selenium.webdriver import ActionChains 8 | 9 | test_files = tt.folder_location("examples/basics") 10 | 11 | 12 | @pytest.mark.parametrize("test_file", test_files) 13 | def test_basic_functionality(driver, test_file): 14 | # Test page response by clicking the reset button and applying 15 | # new code to ace-editor 16 | tt.reset_page(driver) 17 | time.sleep(0.5) 18 | tt.update_editor(driver, test_file) 19 | tt.mouse_scroll(driver, 500) 20 | ens_elements = driver.find_elements_by_xpath('//*[@class="ens"]') 21 | assert len(ens_elements) > 0 22 | side_script = ( 23 | "var right = document.getElementById('rightpane');\n" 24 | "right.style.width = '200px';\n" 25 | ) 26 | driver.execute_script(side_script) 27 | 28 | # Creates graph objects by right clicking and selecting 29 | actions = ActionChains(driver) 30 | elements = ["node", "ens"] 31 | for elem in elements: 32 | node = driver.find_element_by_xpath('//*[@class="' + elem + '"]') 33 | actions = ActionChains(driver) 34 | actions.move_to_element(node) 35 | actions.context_click() 36 | actions.perform() 37 | time.sleep(1) 38 | actions = ActionChains(driver) 39 | 40 | menu = driver.find_element_by_xpath('//*[@class="dropdown-menu"]/li[1]') 41 | actions.move_to_element(menu) 42 | actions.click() 43 | actions.perform() 44 | time.sleep(0.5) 45 | 46 | graph_elements = driver.find_elements_by_xpath('//*[@class="graph"]') 47 | 48 | assert len(graph_elements) > 0 49 | tt.start_stop_sim(driver) 50 | time.sleep(1.5) 51 | tt.start_stop_sim(driver) 52 | time.sleep(0.5) 53 | 54 | ticker = driver.find_element_by_xpath('//*[@id="ticks_tr"]/td') 55 | sim_time = ticker.get_attribute("textContent") 56 | 57 | assert float(sim_time) > 0 58 | -------------------------------------------------------------------------------- /nengo_gui/tests/test_configuration.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from nengo_gui import testing_tools as tt 4 | from selenium.webdriver import ActionChains 5 | 6 | 7 | def test_config_persists(driver): 8 | tt.reset_page(driver) 9 | menu = driver.find_element_by_id("Config_menu") 10 | actions = ActionChains(driver) 11 | actions.move_to_element(menu) 12 | actions.click() 13 | actions.perform() 14 | time.sleep(0.5) 15 | button = driver.find_element_by_id("Config_button") 16 | actions = ActionChains(driver) 17 | actions.move_to_element(button) 18 | actions.click() 19 | actions.perform() 20 | time.sleep(1.0) 21 | 22 | actions = ActionChains(driver) 23 | checkbox = driver.find_element_by_id("zoom-fonts") 24 | actions.move_to_element(checkbox) 25 | actions.click() 26 | actions.perform() 27 | time.sleep(0.5) 28 | 29 | val = driver.execute_script("return localStorage.getItem('ng.zoom_fonts')") 30 | assert val == "true" 31 | 32 | actions.perform() # do it again to go back to default (False) 33 | val = driver.execute_script("return localStorage.getItem('ng.zoom_fonts')") 34 | assert val == "false" 35 | -------------------------------------------------------------------------------- /nengo_gui/tests/test_data_to_csv.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from nengo_gui import testing_tools as tt 4 | from selenium.webdriver import ActionChains 5 | 6 | 7 | def test_data_to_csv(driver): 8 | tt.reset_page(driver) 9 | 10 | tt.update_editor( 11 | driver, 12 | """ 13 | import nengo 14 | model = nengo.Network() 15 | with model: 16 | stim = nengo.Node([0]) 17 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 18 | nengo.Connection(stim, a) 19 | """, 20 | ) 21 | 22 | time.sleep(1) 23 | 24 | actions = ActionChains(driver) 25 | elements = ["node", "ens"] 26 | for elem in elements: 27 | for x in range(2): 28 | node = driver.find_element_by_xpath('//*[@class="' + elem + '"]') 29 | 30 | actions = ActionChains(driver) 31 | actions.move_to_element(node) 32 | actions.context_click() 33 | actions.perform() 34 | time.sleep(1) 35 | actions = ActionChains(driver) 36 | 37 | menu = driver.find_element_by_xpath( 38 | '//*[@class="dropdown-menu"]/li[%d]' % (x + 1) 39 | ) 40 | actions.move_to_element(menu) 41 | actions.click() 42 | actions.perform() 43 | 44 | time.sleep(0.5) 45 | result = driver.execute_script( 46 | """ 47 | a = function() { 48 | var data_set = Nengo.Component.components; 49 | data_set.forEach(function(data, index) { 50 | if (data.constructor === Nengo.Value) { 51 | data.data_store.reset(); 52 | data.data_store.push([1, 10+index]); 53 | } 54 | }); 55 | return data_to_csv(data_set); 56 | }; 57 | return a(); 58 | """ 59 | ) 60 | 61 | test_data = "Graph Name,stim,a\n" "Times,Dimension1,Dimension1\n" "1,11,12" 62 | 63 | assert result == test_data 64 | -------------------------------------------------------------------------------- /nengo_gui/tests/test_dynamics.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import nengo 4 | import nengo_gui 5 | import numpy as np 6 | 7 | 8 | def test_lorenz(): 9 | pyfile = os.path.join(nengo_gui.__path__[0], "examples", "tutorial", "15-lorenz.py") 10 | 11 | model_objects = {} 12 | nengo.utils.stdlib.execfile(pyfile, model_objects) 13 | 14 | with model_objects["model"]: 15 | state_p = nengo.Probe(model_objects["x"], synapse=0.01) 16 | 17 | with nengo.Simulator(model_objects["model"]) as sim: 18 | sim.run(5) 19 | 20 | variance = np.var(sim.data[state_p], axis=0) 21 | assert np.all(variance > 40) 22 | -------------------------------------------------------------------------------- /nengo_gui/tests/test_netgraph.py: -------------------------------------------------------------------------------- 1 | """ 2 | Tests for the NetGraph class. 3 | """ 4 | 5 | import nengo 6 | import numpy as np 7 | from nengo_gui.components.netgraph import NetGraph 8 | 9 | 10 | def test_get_pre_post_obj(): 11 | model = nengo.Network() 12 | with model: 13 | a = nengo.Ensemble(1, 10) 14 | b = nengo.Ensemble(1, 10) 15 | conn = nengo.Connection(a, b) 16 | assert a == NetGraph.connection_pre_obj(conn) 17 | assert b == NetGraph.connection_post_obj(conn) 18 | assert "normal" == NetGraph.connection_kind(conn) 19 | 20 | 21 | def test_get_pre_post_obj_neurons(): 22 | model = nengo.Network() 23 | with model: 24 | a = nengo.Ensemble(1, 10) 25 | b = nengo.Ensemble(1, 10) 26 | conn = nengo.Connection(a.neurons, b.neurons) 27 | assert a == NetGraph.connection_pre_obj(conn) 28 | assert b == NetGraph.connection_post_obj(conn) 29 | assert "normal" == NetGraph.connection_kind(conn) 30 | 31 | 32 | def test_get_pre_post_obj_learning_rule(): 33 | model = nengo.Network() 34 | with model: 35 | a = nengo.Ensemble(1, 10) 36 | b = nengo.Ensemble(1, 10) 37 | c = nengo.Ensemble(1, 10) 38 | conn_1 = nengo.Connection(a, b) 39 | conn_1.learning_rule_type = nengo.PES() 40 | conn_2 = nengo.Connection(c, conn_1.learning_rule) 41 | assert a == NetGraph.connection_pre_obj(conn_1) 42 | assert b == NetGraph.connection_post_obj(conn_1) 43 | assert "normal" == NetGraph.connection_kind(conn_1) 44 | 45 | assert c == NetGraph.connection_pre_obj(conn_2) 46 | assert b == NetGraph.connection_post_obj(conn_2) 47 | assert "modulatory" == NetGraph.connection_kind(conn_2) 48 | 49 | 50 | def test_connection_inhibitory(): 51 | model = nengo.Network() 52 | with model: 53 | a = nengo.Ensemble(1, 10) 54 | b = nengo.Ensemble(1, 10) 55 | conn_1 = nengo.Connection(a, b.neurons, transform=1 * np.ones((1, 10))) 56 | conn_2 = nengo.Connection(a, b.neurons, transform=-1 * np.ones((1, 10))) 57 | conn_3 = nengo.Connection( 58 | a, 59 | b.neurons, 60 | transform=np.array((0, -1, 0, 0, 0, 0, 0, 0, 0, 0)).reshape((1, 10)), 61 | ) 62 | conn_4 = nengo.Connection(a, b.neurons, transform=-1 * np.zeros((1, 10))) 63 | assert "normal" == NetGraph.connection_kind(conn_1) 64 | assert "inhibitory" == NetGraph.connection_kind(conn_2) 65 | assert "inhibitory" == NetGraph.connection_kind(conn_3) 66 | assert "normal" == NetGraph.connection_kind(conn_4) 67 | -------------------------------------------------------------------------------- /nengo_gui/tests/test_pdb_error.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import pytest 4 | from nengo_gui import testing_tools as tt 5 | 6 | 7 | @pytest.mark.skipif(True, reason="Halts future tests") 8 | def test_pdb_error(driver): 9 | test_file = """ 10 | import nengo 11 | import pdb 12 | 13 | model = nengo.Network() 14 | with model: 15 | pdb.set_trace() 16 | stim = nengo.Node([0]) 17 | a = nengo.Ensemble(n_neurons=50, dimensions=1) 18 | nengo.Connection(stim, a) 19 | """ 20 | tt.reset_page(driver) 21 | tt.update_editor(driver, test_file) 22 | time.sleep(0.5) 23 | tt.start_stop_sim(driver) 24 | time.sleep(1.5) 25 | tt.start_stop_sim(driver) 26 | time.sleep(0.5) 27 | 28 | ticker = driver.find_element_by_xpath('//*[@id="ticks_tr"]/td') 29 | sim_time = ticker.get_attribute("textContent") 30 | 31 | assert float(sim_time) > 0 32 | -------------------------------------------------------------------------------- /nengo_gui/tests/test_save_as.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | import nengo_gui # Imported to find project_root 5 | from nengo_gui import testing_tools as tt 6 | 7 | 8 | def download_file(driver, name_of_file): 9 | time.sleep(1) 10 | file_name = driver.find_element_by_xpath('//*[@id="filename"]') 11 | file_name.click() 12 | time.sleep(0.25) 13 | 14 | field = driver.find_element_by_xpath('//*[@id="save-as-filename"]') 15 | time.sleep(0.3) 16 | field.clear() 17 | time.sleep(0.25) 18 | field.send_keys(name_of_file) 19 | time.sleep(0.2) 20 | 21 | accept = driver.find_element_by_xpath('//*[@id="OK"]') 22 | accept.click() 23 | 24 | time.sleep(5) 25 | 26 | 27 | def test_save_as(driver): 28 | # Saves the default.py file as test_download, tests whether it downloaded 29 | # correctly. 30 | tt.reset_page(driver) 31 | download_file(driver, "nengo_gui/examples/test_download.py") 32 | 33 | # Finds files to be read 34 | project_root = os.path.dirname(nengo_gui.__file__) 35 | test_file = os.path.join(project_root, "examples", "test_download.py") 36 | test_file_conf = os.path.join(project_root, "examples", "test_download.py.cfg") 37 | default_file = os.path.join(project_root, "examples", "default.py") 38 | 39 | assert os.path.isfile(test_file) 40 | with open(test_file, "r") as f1: 41 | test_code = f1.read() 42 | with open(default_file, "r") as f2: 43 | default_code = f2.read() 44 | 45 | assert test_code == default_code 46 | 47 | # Deletes downloaded files 48 | os.remove(test_file) 49 | os.remove(test_file_conf) 50 | 51 | download_file(driver, "nengo_gui/examples/default.py") 52 | time.sleep(2) 53 | try: 54 | alert = driver.switch_to_alert() 55 | alert.accept() 56 | except: 57 | assert False, "No warning present" 58 | -------------------------------------------------------------------------------- /nengo_gui/tests/test_tutorial_basic.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import pytest 4 | from nengo_gui import testing_tools as tt 5 | 6 | test_files = tt.folder_location("examples/tutorial") 7 | ignore = ["spa", "networks"] 8 | test_files = [f for f in test_files if not any(i in f for i in ignore)] 9 | # Gets rid of SPA and Network files 10 | 11 | 12 | @pytest.mark.parametrize("test_file", test_files) 13 | def test_tutorial_basic(driver, test_file): 14 | # Tests the first 18 tutorials. These are the tutorials that do not 15 | # utilize networks or SPA which require a different format of test 16 | 17 | # Test page response by clicking the reset button and applying 18 | # new code to ace-editor 19 | tt.reset_page(driver) 20 | time.sleep(1) 21 | tt.update_editor(driver, test_file) 22 | tt.mouse_scroll(driver, 500) 23 | time.sleep(2) 24 | side_script = ( 25 | "var right = document.getElementById('rightpane');\n" 26 | "right.style.width = '200px';\n" 27 | ) 28 | driver.execute_script(side_script) 29 | 30 | node_objects = driver.find_elements_by_xpath('//*[@class="node"]') 31 | ens_objects = driver.find_elements_by_xpath('//*[@class="ens"]') 32 | 33 | node_number = test_file.count("nengo.Node") 34 | ens_number = test_file.count("nengo.Ensemble") 35 | 36 | # Makes sure the correct number of ensembles and nodes were rendered 37 | assert len(node_objects) / 2 == node_number 38 | assert len(ens_objects) / 2 == ens_number 39 | 40 | # Tests whether the file compiles and runs 41 | hang_time = 25 # alloted time until test fails 42 | 43 | time_script = "var time = $('#ticks_tr');\n" "return time.find('td').text()\n" 44 | tt.start_stop_sim(driver) 45 | time_start = time.time() 46 | while time.time() - time_start < hang_time: 47 | sim_time = driver.execute_script(time_script) 48 | if float(sim_time) > 0: 49 | break 50 | time.sleep(0.1) 51 | else: 52 | assert False, "Did not compile in %f seconds" % hang_time 53 | -------------------------------------------------------------------------------- /nengo_gui/url.py: -------------------------------------------------------------------------------- 1 | try: 2 | from urllib.parse import quote, urlencode 3 | except ImportError: 4 | from urllib import quote, urlencode 5 | 6 | 7 | class Resource(object): 8 | __slots__ = ["path", "query"] 9 | 10 | def __init__(self, path=None, query=None): 11 | self.path = path 12 | self.query = query 13 | 14 | def __str__(self): 15 | url = [] 16 | if self.path is not None: 17 | url.append(quote(self.path)) 18 | if self.query is not None: 19 | url.extend(("?", urlencode(self.query))) 20 | return "".join(url) 21 | 22 | 23 | class URL(object): 24 | __slots__ = ["protocol", "host", "port", "resource"] 25 | 26 | def __init__(self, host, port, protocol="http", resource=None): 27 | self.host = host 28 | self.port = port 29 | self.protocol = protocol 30 | self.resource = resource 31 | 32 | def __str__(self): 33 | url = [] 34 | if self.protocol is not None: 35 | url.append(self.protocol) 36 | url.extend(("://", self.host, ":", str(self.port))) 37 | if self.resource is not None: 38 | url.append(str(self.resource)) 39 | return "".join(url) 40 | -------------------------------------------------------------------------------- /nengo_gui/version.py: -------------------------------------------------------------------------------- 1 | """Nengo GUI version information. 2 | 3 | We use semantic versioning (see http://semver.org/). 4 | and conform to PEP440 (see https://www.python.org/dev/peps/pep-0440/). 5 | '.devN' will be added to the version unless the code base represents 6 | a release version. Release versions are git tagged with the version. 7 | """ 8 | 9 | name = "nengo_gui" 10 | version_info = (0, 6, 1) # (major, minor, patch) 11 | dev = 0 12 | 13 | version = "{v}{dev}".format( 14 | v=".".join(str(v) for v in version_info), 15 | dev=(".dev%d" % dev) if dev is not None else "", 16 | ) 17 | -------------------------------------------------------------------------------- /nengo_gui/viz.py: -------------------------------------------------------------------------------- 1 | import warnings 2 | 3 | import nengo_gui.gui 4 | 5 | 6 | # dummy fn so that old scripts still work, but get a deprecation message 7 | def Viz(*args, **kwargs): 8 | warnings.warn("nengo_gui.Viz is deprecated. Use nengo_gui.GUI instead.") 9 | return nengo_gui.GUI(*args, **kwargs) 10 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools", "wheel"] 3 | 4 | [tool.black] 5 | target-version = ['py36'] 6 | exclude = ''' 7 | ( 8 | _vendor/* 9 | ) 10 | ''' 11 | 12 | [tool.isort] 13 | profile = "black" 14 | src_paths = ["nengo"] 15 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import importlib 3 | import io 4 | import os 5 | import sys 6 | 7 | try: 8 | from setuptools import find_packages, setup 9 | except ImportError: 10 | raise ImportError( 11 | "'setuptools' is required but not installed. To install it, " 12 | "follow the instructions at " 13 | "https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py" 14 | ) 15 | 16 | 17 | def read(*filenames, **kwargs): 18 | encoding = kwargs.get("encoding", "utf-8") 19 | sep = kwargs.get("sep", "\n") 20 | buf = [] 21 | for filename in filenames: 22 | with io.open(filename, encoding=encoding) as f: 23 | buf.append(f.read()) 24 | return sep.join(buf) 25 | 26 | 27 | root = os.path.dirname(os.path.realpath(__file__)) 28 | pkg_spec = importlib.util.spec_from_file_location( 29 | "version", os.path.join(root, "nengo_gui", "version.py") 30 | ) 31 | pkg_module = importlib.util.module_from_spec(pkg_spec) 32 | sys.modules["version"] = pkg_module 33 | pkg_spec.loader.exec_module(pkg_module) 34 | 35 | setup( 36 | name="nengo-gui", 37 | version=pkg_module.version, 38 | author="Applied Brain Research", 39 | author_email="info@appliedbrainresearch.com", 40 | packages=find_packages(), 41 | scripts=[], 42 | include_package_data=True, 43 | url="https://github.com/nengo/nengo-gui", 44 | license="GNU General Public License, version 2", 45 | description="Web-based GUI for building and visualizing Nengo models.", 46 | long_description=read("README.rst", "CHANGES.rst"), 47 | zip_safe=False, 48 | entry_points={ 49 | "console_scripts": [ 50 | "nengo_gui = nengo_gui:old_main", 51 | "nengo = nengo_gui:main", 52 | ] 53 | }, 54 | install_requires=[ 55 | "nengo>=2.6.0", 56 | ], 57 | tests_require=[ 58 | "pytest", 59 | "selenium", 60 | ], 61 | classifiers=[ # https://pypi.python.org/pypi?%3Aaction=list_classifiers 62 | "Development Status :: 5 - Production/Stable", 63 | "Intended Audience :: Science/Research", 64 | "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", 65 | "Operating System :: OS Independent", 66 | "Programming Language :: JavaScript", 67 | "Programming Language :: Python :: 2.7", 68 | "Programming Language :: Python :: 3.4", 69 | "Programming Language :: Python :: 3.5", 70 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 71 | ], 72 | ) 73 | --------------------------------------------------------------------------------