代码拉取完成,页面将自动刷新
同步操作将从 mirrors_mikaelbr/AnnWebots 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import random
from functools import partial
from controllers.webann.ann.layer import *
from controllers.webann.ann.link import *
from controllers.webann.ann.ann import Ann
from controllers.webann.ann.parser import AnnParser
from controllers.webann.ann.ann_modules import Inhibitory
import time
data = [
[[1, 1], [0]],
[[0, 0], [0]],
[[0, 1], [1]],
[[1, 0], [1]]
]
# Layers
i_l = Layer("Input", 2, io_type='encoder')
hidden = Layer("Hidden", 2, partial(Activation.step, T=2))
out = Layer("Out", 1, partial(Activation.step, T=2), io_type='decoder')
layers = [i_l, hidden, out]
# weights=[2, -1, -1, 2],
l1 = Link(i_l, hidden,
arc_range=[-1, 2],
arcs=[(0,0), (0,1), (1,0), (1,1)],
learning_rule=LearningRule.general_hebb
)
l2 = Link(hidden, out,
arc_range=[0, 2],
topology="full",
learning_rule=LearningRule.oja
)
# Execution order
ann = Ann(layers, [l1, l2])
ann.execution_order = layers
# Do training
ann.set_learning_mode()
epochs = 1000
# Learn
# Run back-propagation learning
t = time.time()
print "Training"
for i in range(epochs):
inputs, target = data[i % len(data)]
ann.learn(inputs)
# ann.backprop(inputs, target)
# print ann.test(inputs, target)
# print l1.export_weights()
# print l2.export_weights()
print l1.export_weights()
print l2.export_weights()
# Do testing
ann.set_testing_mode()
# AnnParser.export(ann, "scripts/xor.ini")
print ann.recall([0, 0])
print ann.recall([1, 0])
print ann.recall([1, 1])
print ann.recall([0, 1])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。