Skip to content

Commit 4e5f830

Browse files
committed
AND, OR, XOR Working
Check commented values to change operator
1 parent 0f0aee3 commit 4e5f830

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

and_net.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,20 @@ def run_net(self, input, time = run_time):
7373
# Initializes a current for the three input neurons
7474
xIn = self.spikes_to_current(self.binary_to_spikes(input[0]), self.connections[0].weight)
7575
yIn = self.spikes_to_current(self.binary_to_spikes(input[1]), self.connections[1].weight)
76-
# Change and to xor/or
7776
#teachIn = self.spikes_to_current(self.binary_to_spikes(input[1] and input[0]), self.connections[2].weight)
7877
self.neurons[0].sim(xIn, time)
7978
self.neurons[1].sim(yIn, time)
8079
#self.neurons[2].sim(teachIn, time)
8180
# Calculates the input current for the output by using an or function on all 3 spike outputs
8281
outIn = []
8382
for i in range(time):
84-
if(self.neurons[0].output[i] == 1 and self.neurons[1].output[i] == 1):
83+
#Change to and, or, ^
84+
if(self.neurons[0].output[i] ^ self.neurons[1].output[i]):
8585
outIn.append(1)
8686
else:
8787
outIn.append(0)
8888
#Conversion factor scales # of spikes from output
89-
self.neurons[3].sim(self.spikes_to_current(outIn, .7), time)
89+
#AND: .7
90+
#OR: .06
91+
#XOR: .6
92+
self.neurons[3].sim(self.spikes_to_current(outIn, .6), time)

data.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
01
9595
10
9696
11
97-
10
97+
00
9898
10
9999
11
100-
10
100+
00

training.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
net = and_net([], [])
55
net.create_simple_net()
66
# X at [0], Y at [1], Teacher at [2]
7+
# AND: .6, .4
8+
# OR: .5, .5
9+
# XOR: .6, .4
710
net.connections[0].weight = .6
811
net.connections[1].weight = .4
912
net.connections[2].weight = 1
@@ -95,7 +98,8 @@ def raster_plot(net):
9598
x_spikes = sum(net.neurons[0].output)
9699
y_spikes = sum(net.neurons[1].output)
97100
o_spikes = sum(net.neurons[3].output)
98-
print((data[r][0] and data[r][1]), "||", net.spikes_to_binary(net.neurons[3]), "\nX =",
101+
#Change operator to and, or, ^
102+
print((data[r][0] ^ data[r][1]), "||", net.spikes_to_binary(net.neurons[3]), "\nX =",
99103
net.connections[0].weight, x_spikes, "\nY =", net.connections[1].weight, y_spikes, "\n", o_spikes, "\n")
100104
for i in range(4):
101105
net.neurons[i].clear()

0 commit comments

Comments
 (0)