I am trying to write a simulator in python for spiking neural networks. Network has been planned to be built from neurons and connections, as below:
Connection class:
class Connection(object):
connectionType = 0
weight = [[0 for x in range(1)] for x in range(9)]
def __init__():
self.threshold = 0
self.connectionType = 0
And Neuron class:
import Connection
class Neuron(object):
ID = 1
OveralPotential = 0
def __init__(self):
global ID
self.input = [[0 for x in range(1)] for x in range(9)]
self.output = [[0 for x in range(1)] for x in range(9)]
self.id = Neuron.ID
Neuron.ID += 1
def connect(srcNeuron, dstNeuron, connectionType):
srcNeuron.output[dstNeuron.id] = 1
dstNeuron.input[srcNeuron.id] = 1
Connection.Connection.connectionType = connectionType
if __name__ == "__main__":
n1 = Neuron()
n2 = Neuron()
n3 = Neuron()
print("ID of the 3rd neuron is {0}".format(n3.id))
n4 = Neuron()
n5 = Neuron()
Neuron.connect(1,3,1)
Neuron.connect(1,4,1)
Neuron.connect(1,5,1)
Neuron.connect(2,3,1)
Neuron.connect(2,4,1)
Neuron.connect(2,5,1)
But here is the stacktrace:
ID of the 3rd neuron is 3
Traceback (most recent call last):
File "C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Mic
rosoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 106, in
exec_file
exec_code(code, file, global_variables)
File "C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Mic
rosoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 82, in
exec_code
exec(code_obj, global_variables)
File "C:\Users\Matinking\Documents\Visual Studio 2013\Projects\NeuroSimulation
\NeuroSimulation\Neuron.py", line 31, in <module>
Neuron.connect(1,3,1)
File "C:\Users\Matinking\Documents\Visual Studio 2013\Projects\NeuroSimulation
\NeuroSimulation\Neuron.py", line 16, in connect
srcNeuron.output[dstNeuron.id] = 1
AttributeError: 'int' object has no attribute 'output'
I checked the possible duplicates in this case, like:
AttributeError: 'int' object has no attribute 'split'
and
AttributeError: 'int' object has no attribute 'write'
But none of them gave me enough insight to handle above stuff. How should I resolve it?!
Thanks in advance
The connect
function expects two objects of type Neuron
, not a neuron id. You are passing an id, that is an int
and python tries to access the output field.
You are passing integer values to the method
def connect(srcNeuron, dstNeuron, connectionType):
srcNeuron.output[dstNeuron.id] = 1
dstNeuron.input[srcNeuron.id] = 1
Connection.Connection.connectionType = connectionType
when you are invoking it
Neuron.connect(1,3,1)
Neuron.connect(1,4,1)
Neuron.connect(1,5,1)
Neuron.connect(2,3,1)
Neuron.connect(2,4,1)
Neuron.connect(2,5,1)
I think you actually meant to specify the neurons instead of integers
Neuron.connect(n1,n3,n1)
Neuron.connect(n1,n4,n1)
Neuron.connect(n1,n5,n1)
Neuron.connect(n2,n3,n1)
Neuron.connect(n2,n4,n1)
Neuron.connect(n2,n5,n1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.