Skip to main content

PymoNNtorch is a Pytorch version of PymoNNto

Project description

PymoNNtorch

pymonntorch logo

https://img.shields.io/pypi/v/pymonntorch.svg 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.

History

0.1.1 (2023-05-26)

  • Every NetworkObject can have a recorder behavior.

  • Netowrk settings accept “index” entry.

  • Bug fixes and general improvement.

0.1.0 (2023-03-17)

  • Repository made public.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymonntorch-0.1.2.tar.gz (509.0 kB view details)

Uploaded Source

Built Distribution

pymonntorch-0.1.2-py2.py3-none-any.whl (37.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pymonntorch-0.1.2.tar.gz.

File metadata

  • Download URL: pymonntorch-0.1.2.tar.gz
  • Upload date:
  • Size: 509.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pymonntorch-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6a89e3af37c2a9ba8f3059d0bd73261b413f4c10598a60e0be98ab44d93e94bf
MD5 fed703d33b00d78d122c5ff7207fbaa8
BLAKE2b-256 c67471c9138eb1ec876bed7257f819af016151a2b10af735398a19348ba379dc

See more details on using hashes here.

File details

Details for the file pymonntorch-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pymonntorch-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0746934a9a25c604b266adb33a0a7abadf59dd5067d33c042cbf757b8ce4ffd9
MD5 1a8fdabcb4a5b7ddd922870a3717de78
BLAKE2b-256 83993e0092ce670f2c62116cf20b858e8c758f96d3068e1ab6b60a4c8bc0d8d9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page