Skip to content

Commit acf732b

Browse files
iJadduiJaddu
authored andcommitted
fixed raster plots
1 parent 0528768 commit acf732b

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

and_net.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def run_net(self, input, time = run_time):
8181
outIn = []
8282
for i in range(time):
8383
#Change to and, or, ^
84-
if(self.neurons[0].output[i] ^ self.neurons[1].output[i]):
84+
if(self.neurons[0].output[i] and self.neurons[1].output[i]):
8585
outIn.append(1)
8686
else:
8787
outIn.append(0)
8888
#Conversion factor scales # of spikes from output
8989
#AND: .7
9090
#OR: .06
9191
#XOR: .6
92-
self.neurons[3].sim(self.spikes_to_current(outIn, .6), time)
92+
self.neurons[3].sim(self.spikes_to_current(outIn, .7), time)

training.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from and_net import and_net
2-
#import matplotlib.pyplot as plt
2+
import matplotlib.pyplot as plt
33

44
net = and_net([], [])
55
net.create_simple_net()
@@ -16,42 +16,42 @@
1616
j = 0
1717
k = 0
1818

19-
"""
20-
def raster_plot(net):
21-
plt.figure()
22-
plt.title('Raster plot for network activity')
19+
20+
def raster_plot(net, length):
21+
# plt.title('Raster plot for network activity')
22+
plt.figure('Raster plot for network activity')
2323

2424
plt.subplot(3, 1, 1)
2525
plt.xlabel('Time')
2626
plt.ylabel('Input Neuron 1')
27-
for i in range(1000):
27+
# length = len(net.neurons[0].output)
28+
plt.xlim(0, 100)
29+
for i in range(length):
2830
if net.neurons[0].output[i] == 1:
29-
#fmt = '[|][-][k]'
30-
#plt.plot(fmt)
3131
plt.axvline(i)
3232

3333
plt.subplot(3, 1, 2)
3434
plt.xlabel('Time')
3535
plt.ylabel('Input Neuron 2')
36-
for j in range(1000):
36+
plt.xlim(0, 100)
37+
# length = len(net.neurons[1].output)
38+
for j in range(length):
3739
if net.neurons[1].output[j] == 1:
38-
#fmt = '[|][-][k]'
39-
#plt.plot(fmt)
4040
plt.axvline(j)
4141

4242
plt.subplot(3, 1, 3)
4343
plt.xlabel('Time')
4444
plt.ylabel('Output Neuron')
45-
for k in range(1000):
45+
plt.xlim(0, 100)
46+
# length = len(net.neurons[3].output)
47+
for k in range(length):
4648
if net.neurons[3].output[k] == 1:
47-
#fmt = '[|][-][k]'
48-
#plt.plot(fmt)
4949
plt.axvline(k)
5050

5151
plt.show()
52-
"""
5352

54-
#lines = open(input("Enter Filepath: "), "r").readlines()
53+
54+
# lines = open(input("Enter Filepath: "), "r").readlines()
5555
lines = open("data.txt", "r").readlines()
5656
runs = len(lines)
5757
for i in range(runs):
@@ -68,23 +68,23 @@ def raster_plot(net):
6868
net.run_net(data[r])
6969
time = len(net.neurons[0].output)
7070
w_max = 1
71-
for i in range(int(time/100)):
72-
#Finds rate for each neuron in a time step of 100
73-
v_x = sum(net.neurons[0].output[100*i:100*(i+1)])
74-
v_y = sum(net.neurons[1].output[100*i:100*(i+1)])
75-
v_o = sum(net.neurons[3].output[100*i:100*(i+1)])
76-
#Sets a_corr value
71+
for i in range(int(time / 100)):
72+
# Finds rate for each neuron in a time step of 100
73+
v_x = sum(net.neurons[0].output[100 * i:100 * (i + 1)])
74+
v_y = sum(net.neurons[1].output[100 * i:100 * (i + 1)])
75+
v_o = sum(net.neurons[3].output[100 * i:100 * (i + 1)])
76+
# Sets a_corr value
7777
a_corr_x = w_max - net.connections[0].weight
7878
a_corr_y = w_max - net.connections[1].weight
79-
#If the rate is below 5, set value to 0
79+
# If the rate is below 5, set value to 0
8080
if v_x <= 10:
8181
v_x = 0
8282
if v_y <= 10:
8383
v_y = 0
8484
if v_o <= 10:
8585
v_o = 0
86-
#Hebb with postsynaptic LTP/LTD threshold
87-
#TODO change .01 to something else?
86+
# Hebb with postsynaptic LTP/LTD threshold
87+
# TODO change .01 to something else?
8888
net.connections[0].weight += a_corr_x * v_x * (v_o - .01)
8989
net.connections[1].weight += a_corr_y * v_y * (v_o - .01)
9090
if net.connections[0].weight < 0:
@@ -98,9 +98,14 @@ def raster_plot(net):
9898
x_spikes = sum(net.neurons[0].output)
9999
y_spikes = sum(net.neurons[1].output)
100100
o_spikes = sum(net.neurons[3].output)
101-
#Change operator to and, or, ^
102-
print((data[r][0] ^ data[r][1]), "||", net.spikes_to_binary(net.neurons[3]), "\nX =",
103-
net.connections[0].weight, x_spikes, "\nY =", net.connections[1].weight, y_spikes, "\n", o_spikes, "\n")
101+
# Change operator to and, or, ^
102+
print((data[r][0] and data[r][1]), "||", net.spikes_to_binary(net.neurons[3]), "\nX =",
103+
net.connections[0].weight, x_spikes, "\nY =", net.connections[1].weight, y_spikes, "\n", o_spikes, "\n")
104+
105+
raster_plot(net, time)
104106
for i in range(4):
105107
net.neurons[i].clear()
106-
#raster_plot(net)
108+
109+
# net.run_net(data[r])
110+
# time = len(net.neurons[0].output)
111+
#raster_plot(net, time)

0 commit comments

Comments
 (0)