{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Discrete Principle 3\n", "\n", "This notebook demonstrates the superior accuracy obtained by using the discretized version of Principle 3 that takes into account the simulation timestep." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%pylab inline\n", "import pylab\n", "try:\n", " import seaborn as sns # optional; prettier graphs\n", "except ImportError:\n", " pass\n", "\n", "import numpy as np\n", "import nengo\n", "import nengolib" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def go(sys=nengolib.synapses.Bandpass(20, 5), T=1.0, dt=0.001, n_neurons=200,\n", " synapse=0.02, seed=0, discretized=True, neuron_type=nengo.LIF()):\n", "\n", " with nengolib.Network(seed=seed) as model:\n", " stim = nengo.Node(output=nengo.processes.WhiteSignal(T, high=50, rms=0.1, y0=0))\n", " subnet = nengolib.networks.LinearNetwork(\n", " sys, n_neurons_per_ensemble=n_neurons, synapse=synapse,\n", " radii=1.0, dt=dt if discretized else None, output_synapse=synapse,\n", " neuron_type=neuron_type)\n", " nengo.Connection(stim, subnet.input, synapse=None)\n", "\n", " p = nengo.Probe(subnet.output)\n", " p_stim = nengo.Probe(stim)\n", "\n", " with nengo.Simulator(model, dt=dt, seed=seed) as sim:\n", " sim.run(T)\n", "\n", " return sim.trange(), sim.data[p], sim.data[p_stim]\n", "\n", "t, disc_actual, expected = go(neuron_type=nengo.LIFRate())\n", "t, cont_actual, expected = go(discretized=False, neuron_type=nengo.LIFRate())\n", "t, ideal, expected = go(neuron_type=nengo.Direct())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pylab.figure(figsize=(16, 6))\n", "pylab.title(\"Comparison of Synapse Mapping Methods on a Bandpass Filter\")\n", "pylab.plot(t, disc_actual, linewidth=2, label=\"Discretized\")\n", "pylab.plot(t, cont_actual, linewidth=2, label=\"Principle 3\")\n", "pylab.plot(t, ideal, linestyle='--', linewidth=2, label=\"Target\")\n", "pylab.legend()\n", "pylab.xlabel(\"Time (s)\")\n", "pylab.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }