本文整理匯總了Python中mlp.MLP.eta方法的典型用法代碼示例。如果您正苦於以下問題:Python MLP.eta方法的具體用法?Python MLP.eta怎麽用?Python MLP.eta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mlp.MLP
的用法示例。
在下文中一共展示了MLP.eta方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from mlp import MLP [as 別名]
# 或者: from mlp.MLP import eta [as 別名]
def main():
training, dev = get_data()
window_size = 5
n_input = window_size
n_hidden = 100
n_output = 1
A = 1
num_hidden_layers = 1
mlp = MLP(n_input, num_hidden_layers, n_hidden, n_output)
n_epochs = 50
step = False
l = loss(mlp, training, window_size, window_size/2)
print "initial loss: " + str(l)
for j in range(0, n_epochs):
print "epoch " + str(j)
random.shuffle(training)
c = 0
for xs, y in training:
if c == 10:
break
c += 1
if step:
train(mlp, xs, y, window_size, window_size/2)
else:
train(mlp, xs, y, window_size, 1)
if step:
error(mlp, training, window_size, window_size/2)
else:
error(mlp, training, window_size, 1)
if step:
l = loss(mlp, training, window_size, window_size/2)
else:
l = loss(mlp, training, window_size, 1)
print "loss: " + str(l)
eta = A / float(j/float(n_epochs) + 1)
mlp.eta = eta
print "lr:", mlp.eta
print "Getting Dev Accuracy..."
if step:
error(mlp, dev, window_size, window_size/2)
else:
error(mlp, dev, window_size, 1)
示例2: main
# 需要導入模塊: from mlp import MLP [as 別名]
# 或者: from mlp.MLP import eta [as 別名]
def main():
training, count_c0, count_c1 = get_data(122)
dev, _, _ = get_data(122,True)
series_c0, series_c1 = get_time_series()
# A window of 240 corresponds to two hours of heart rate
window_size = 240
print "#class0: ", count_c0/float(window_size), "#class1:", count_c1/float(window_size)
c1 = 0
c0 = 0
print "len training = " + str(len(training))
count0 = 0
count1 = 0
random.shuffle(training)
n_input = window_size
n_hidden = 100
n_output = 1
num_hidden_layers = 1
eta_c = .005
A = .0008
eta = eta_c
mlp = MLP(n_input, num_hidden_layers, n_hidden, n_output, eta)
n_epochs = 400
step = True
l = loss(mlp, training, window_size, window_size/2)
print "initial loss: " + str(l)
for j in range(0, n_epochs):
print "epoch " + str(j)
random.shuffle(training)
c = 0
grad = None
for xs, y in training:
if c == 10:
break
c += 1
part_grad = None
if step:
part_grad = train(mlp, xs, y, window_size, window_size/2)
else:
part_grad = train(mlp, xs, y, window_size, 1)
grad = sum_grad(grad, part_grad)
mlp.update_weights(grad)
if step:
error(mlp, training, window_size, window_size/2)
else:
error(mlp, training, window_size, 1)
if step:
l = loss(mlp, training, window_size, window_size/2)
else:
l = loss(mlp, training, window_size, 1)
print "loss: " + str(l)
eta = A / float(j/float(n_epochs) + 1)
mlp.eta = eta
print "lr:", mlp.eta
if n_epochs % 10 == 0:
if step:
error(mlp, dev, window_size, window_size/2, True)
else:
error(mlp, dev, window_size, 1, True)
print "Getting training accuracy..."
if step:
error(mlp, training, window_size, window_size/2)
else:
error(mlp, training, window_size, 1)
print "Getting dev accuracy..."
if step:
error(mlp, dev, window_size, window_size/2, True)
probs(mlp, series_c0, series_c1, window_size, window_size/2)
else:
error(mlp, dev, window_size, 1, True)
probs(mlp, series_c0, series_c1, window_size, 1)