problem_py
problem_py
import numpy as np
# random seed
np.random.seed(42)
# input neuron x
Vx = 66
time = t # ms
cur_t = 0
cur_out = Vr
return Vx
# input neuron y
Vy = 66
time = t # ms
cur_t = 0
cur_out = Vr
return Vy
# output neuron z
Vz = 66
time = t # ms
cur_t = 0
cur_out = Vr
return Vz
# learning rules
a1 = 0.0000005
a2 = 0.0000001
a3 = 0.0000001
def d_w1(x,z):
return (a1*x*z) - (a2*x) - (a3*z)
b1 = 0.0000005
b2 = 0.0000001
b3 = 0.0000001
def d_w2(y,z):
return (b1*y*z) - (b2*y) - (b3*z)
x_ins = np.array([-1,-1,-1,-1])
y_ins = np.array([-1,-1,-1,-1])
for n in range(4):
x_ins[n] = in_x(featset[n,0], 10)
y_ins[n] = in_y(featset[n,1], 10)
# x_ins = x_ins.reshape(4,1)
# y_ins = y_ins.reshape(4,1)
return inputs
# train network
def train_network(inputs, labels):
weights = np.random.rand(2,1)
weights /= 2.55
print(inputs)
# output value
Vz_hat = []
Iz_hat = np.dot(inputs, weights)
print(Iz_hat)
for I in Iz_hat:
Vz_hat.append(out_z(I, 10))
print(Vz_hat)
return weights
test_inputs = readSpikeTrain(feature_set)
fin_weights = train_network(test_inputs, labels1)
print("Final Weights:")
print(fin_weights)