Package: torchsnn
torchsnnpytorch implementation of the Stigmergic Neural Networks as presented in the paperUsing stigmergy to incorporate the time into artificial neural networks.This package was wrote with the intent to make aseasyas possible to integrate the Stigmergic Neural Networks into the existing models.You can safelymixnative pytorch Modules with ours.The onlycatchis that you should useStigmergicModule(which extends pytorch'sModule) as base class for your models in order to be able totick()andreset()them.Implementing ourproposed architecture to solve MNISTbecomes as easy as:importtorchimporttorchsnnnet=torchsnn.Sequential(torchsnn.SimpleLayer(28,10),torchsnn.FullLayer(10,10),torchsnn.TemporalAdapter(10,28),torch.nn.Linear(10*28,10),torch.nn.Sigmoid())You can train aStigmergicModuleas you would do with a pytorch'sModule, but don't forget toreset()andtick()it!optimizer=torch.optim.Adam(net.parameters(),lr=0.001)foriinrange(0,N):forX,Yinzip(dataset_X,dataset_Y):net.reset()out=NoneforxiinX:out=net(torch.tensor(xi,dtype=torch.float32))net.tick()loss=(Y-out)**2loss.backward()optimizer.step()Does it support batch inputs?Yes! if you forward into a StigmergicModule a batch of inputs it will return a batch of outputsfortinrange(0,num_ticks):batch_out[0],batch_out[1],...=net(torch.tensor([batch_in[0][t],batch_in[1][t],...]))net.tick()Can it run on CUDA?Yes and as you will expect from a pytorch Module!You just need to call theto(device)method on a model to move it in the GPU memorydevice=torch.device("cuda")net=net.to(device)net.forward(torch.tensor(...,device=device))Documentationtorchsnn.StigmergicModuleBase class for a stigmergic network or layer.If you are writing your ownStigmergicModuleyou have to implement the functionstick()reset()If you are using othersStigmergicModuleit will propagate these calls in its subtree.For example if you want to build a network with aLinearand aSimpleLayeryou can do something like:importtorchimporttorchsnnclassTestNetwork(torchsnn.StigmergicModule):def__init__(self):torchsnn.StigmergicModule.__init__(self)self.linear=torch.nn.Linear(2,5)self.stigmergic=torchsnn.SimpleLayer(5,2)defforward(self,input):l1=torch.sigmoid(self.linear(input))l2=self.stigmergic(l1)returnl2net=TestNetwork()torchsnn.SequentialFunction with the same interface oftorch.nn.Sequentialfor building sequential networks.The same network of the previous example can be built with:importtorchimporttorchsnnnet=torchsnn.Sequential(torch.nn.Linear(2,5),torch.nn.Sigmoid(),torchsnn.SimpleLayer(5,2))torchsnn.SimpleLayerIt this layer only the thresholds are stigmergic variables and theirstimuliare the output values.torchsnn.FullLayerIn this layer both thresholds and weights are stigmergic variables and theirstimuliare respectively the output values and the input ones.CitingWe can't wait to see what you will build with the Stigmergic Neural Networks!When you will publish your work you can use this BibTex to cite us :)@article{galatolo_snn
,	author	= {Galatolo, Federico A and Cimino, Mario GCA and Vaglini, Gigliola}
,	title	= {Using stigmergy to incorporate the time into artificial neural networks}
,	journal	= {MIKE 2018}
,	year	= {2018}
}ContributingThis code is released under GNU/GPLv3 so feel free to fork it and submit your changes, every PR helps.If you need help using it or for any question please reach me atgalatolo.federico@gmail.comor on Telegram@galatolo