1
1
from and_net import and_net
2
- # import matplotlib.pyplot as plt
2
+ import matplotlib .pyplot as plt
3
3
4
4
net = and_net ([], [])
5
5
net .create_simple_net ()
16
16
j = 0
17
17
k = 0
18
18
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' )
23
23
24
24
plt .subplot (3 , 1 , 1 )
25
25
plt .xlabel ('Time' )
26
26
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 ):
28
30
if net .neurons [0 ].output [i ] == 1 :
29
- #fmt = '[|][-][k]'
30
- #plt.plot(fmt)
31
31
plt .axvline (i )
32
32
33
33
plt .subplot (3 , 1 , 2 )
34
34
plt .xlabel ('Time' )
35
35
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 ):
37
39
if net .neurons [1 ].output [j ] == 1 :
38
- #fmt = '[|][-][k]'
39
- #plt.plot(fmt)
40
40
plt .axvline (j )
41
41
42
42
plt .subplot (3 , 1 , 3 )
43
43
plt .xlabel ('Time' )
44
44
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 ):
46
48
if net .neurons [3 ].output [k ] == 1 :
47
- #fmt = '[|][-][k]'
48
- #plt.plot(fmt)
49
49
plt .axvline (k )
50
50
51
51
plt .show ()
52
- """
53
52
54
- #lines = open(input("Enter Filepath: "), "r").readlines()
53
+
54
+ # lines = open(input("Enter Filepath: "), "r").readlines()
55
55
lines = open ("data.txt" , "r" ).readlines ()
56
56
runs = len (lines )
57
57
for i in range (runs ):
@@ -68,23 +68,23 @@ def raster_plot(net):
68
68
net .run_net (data [r ])
69
69
time = len (net .neurons [0 ].output )
70
70
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
77
77
a_corr_x = w_max - net .connections [0 ].weight
78
78
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
80
80
if v_x <= 10 :
81
81
v_x = 0
82
82
if v_y <= 10 :
83
83
v_y = 0
84
84
if v_o <= 10 :
85
85
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?
88
88
net .connections [0 ].weight += a_corr_x * v_x * (v_o - .01 )
89
89
net .connections [1 ].weight += a_corr_y * v_y * (v_o - .01 )
90
90
if net .connections [0 ].weight < 0 :
@@ -98,9 +98,14 @@ def raster_plot(net):
98
98
x_spikes = sum (net .neurons [0 ].output )
99
99
y_spikes = sum (net .neurons [1 ].output )
100
100
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 ]), "\n X =" ,
103
- net .connections [0 ].weight , x_spikes , "\n Y =" , 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 ]), "\n X =" ,
103
+ net .connections [0 ].weight , x_spikes , "\n Y =" , net .connections [1 ].weight , y_spikes , "\n " , o_spikes , "\n " )
104
+
105
+ raster_plot (net , time )
104
106
for i in range (4 ):
105
107
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