Giter Club home page Giter Club logo

pymonntorch's Introduction

PymoNNtorch

pymonntorch logo


Documentation Status

PymoNNtorch is a Pytorch-adapted version of PymoNNto.

Features

  • Use torch tensors and Pytorch-like syntax to create a spiking neural network (SNN).
  • Simulate an SNN on CPU or GPU.
  • Define dynamics of SNN components as Behavior modules.
  • Control over the order of applying different behaviors in each simulation time step.

Usage

You can use the same syntax as PymoNNto to create you network:

from pymonntorch import *

net = Network()
ng = NeuronGroup(net=net, tag="my_neuron", size=100, behavior=None)
SynapseGroup(src=ng, dst=ng, net=net, tag="recurrent_synapse")
net.initialize()
net.simulate_iterations(1000)

Similarly, you can write your own Behavior Modules with the same logic as PymoNNto; except using torch tensors instead of numpy ndarrays.

from pymonntorch import *

class BasicBehavior(Behavior):
    def initialize(self, neurons):
        super().initialize(neurons)
        neurons.voltage = neurons.vector(mode="zeros")
        self.threshold = 1.0

    def forward(self, neurons):
        firing = neurons.voltage >= self.threshold
        neurons.spike = firing.byte()
        neurons.voltage[firing] = 0.0 # reset

        neurons.voltage *= 0.9 # voltage decay
        neurons.voltage += neurons.vector(mode="uniform", density=0.1)

class InputBehavior(Behavior):
    def initialize(self, neurons):
        super().initialize(neurons)
        for synapse in neurons.afferent_synapses['GLUTAMATE']:
            synapse.W = synapse.matrix('uniform', density=0.1)
            synapse.enabled = synapse.W > 0

    def forward(self, neurons):
        for synapse in neurons.afferent_synapses['GLUTAMATE']:
            neurons.voltage += synapse.W@synapse.src.spike.float() / synapse.src.size * 10

net = Network()
ng = NeuronGroup(net=net,
                size=100,
                behavior={
                    1: BasicBehavior(),
                    2: InputBehavior(),
                    9: Recorder(['voltage']),
                    10: EventRecorder(['spike'])
                })
SynapseGroup(ng, ng, net, tag='GLUTAMATE')
net.initialize()
net.simulate_iterations(1000)

import matplotlib.pyplot as plt

plt.plot(net['voltage',0][:, :10])
plt.show()

plt.plot(net['spike.t',0], net['spike.i',0], '.k')
plt.show()

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template. It changes the codebase of PymoNNto to use torch rather than numpy and tensorflow numpy.

pymonntorch's People

Contributors

keyvantajfar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.