1 Star 0 Fork 1

huigeysu/AnnWebots

forked from mirrors_mikaelbr/AnnWebots 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example_xor_learning.py 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
Mikael Brevik 提交于 2012-03-20 17:15 . Example changes
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])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huigeysu/AnnWebots.git
[email protected]:huigeysu/AnnWebots.git
huigeysu
AnnWebots
AnnWebots
master

搜索帮助