{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Nengo Tutorial\n", "\n", "## Nengo\n", "\n", "- Our neural simulator\n", "- Implements the basics of what we cover in this class\n", " - So you don't have to worry about the implementation details\n", " - But understanding the theory will help you use it better\n", " \n", "- website: [Nengo.ca](http://nengo.ca)\n", "- install: [Download Nengo](http://nengo.ca/download)\n", " - use the \"latest development version of Nengo\"\n", " - Java application; runs on Linux, OS X, Windows\n", " - Open Source: [Github repository](https://github.com/ctn-waterloo/nengo_1.4)\n", "\n", "## How to use it\n", "\n", "- Drag and drop interface: [Tutorials](http://nengo.ca/docs/html/tutorial.html)\n", "- Python scripting: [Tutorials](http://nengo.ca/docs/html/scripting.html)\n", "- basic usage:\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import nef\n", "net = nef.Network('Example')\n", "net.make_input('input', [0])\n", "\n", "net.make('A', neurons=75, dimensions=1)\n", "net.make('B', neurons=50, dimensions=1)\n", "\n", "def square(x):\n", " return x[0]*x[0]\n", "\n", "net.connect('A', 'B', func=square)\n", "\n", "net.connect('input', 'A')\n", "\n", "net.add_to_nengo()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- More advanced usage\n", " - the ``make`` command builds ensembles\n", " - [documentation](http://nengo.ca/docs/html/nef.Network.html#nef.Network.make)\n", " - the ``connect`` command forms connections between ensembles\n", " - [documentation](http://nengo.ca/docs/html/nef.Network.html#nef.Network.connect)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The creature we made in class\n", "\n", "- Should set ``motor`` to be the direction we tell it to go in with ``command``, unless ``scared`` is 1, in which can it should try to go back to ``position`` (0,0)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import nef\n", "\n", "net = nef.Network('Creature')\n", "\n", "net.make_input('command_input', [0,0])\n", "\n", "net.make('command', neurons=100, dimensions=2)\n", "\n", "net.make('motor', neurons=100, dimensions=2)\n", "\n", "net.make('position', neurons=1000, dimensions=2, radius=5)\n", "\n", "net.make('scared_direction', neurons=100, dimensions=2)\n", "\n", "def negative(x):\n", " return -x[0], -x[1]\n", "\n", "net.connect('position', 'scared_direction', func=negative)\n", "\n", "net.connect('position', 'position')\n", "\n", "net.make('plan', neurons=500, dimensions=5)\n", "net.connect('command', 'plan', index_post=[0,1])\n", "net.connect('scared_direction', 'plan', index_post=[2,3])\n", "net.make('scared', neurons=50, dimensions=1)\n", "net.make_input('scared_input', [0])\n", "net.connect('scared_input', 'scared')\n", "net.connect('scared', 'plan', index_post=[4])\n", "\n", "def plan_function(x):\n", " c_x, c_y, s_x, s_y, s = x\n", " return s*(s_x)+(1-s)*c_x, s*(s_y)+(1-s)*c_y\n", " \n", "net.connect('plan', 'motor', func=plan_function) \n", "\n", "\n", "def rescale(x):\n", " return x[0]*0.1, x[1]*0.1\n", "\n", "net.connect('motor', 'position', func=rescale)\n", "\n", "\n", "net.connect('command_input', 'command')\n", "\n", "net.add_to_nengo()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }