python 简单神经网络

来源:互联网 发布:最便宜的单片机 编辑:程序博客网 时间:2024/06/15 07:58
#!/usr/bin/python#coding: utf-8from pybrain.tools.shortcuts import buildNetworkfrom pybrain.datasets import SupervisedDataSetfrom pybrain.supervised.trainers import BackpropTrainerfrom pybrain.structure import *net = buildNetwork(2, 3, 1 , bias=True, hiddenclass=TanhLayer)ds = SupervisedDataSet(2, 1)ds.addSample((0, 0), (0,))ds.addSample((0, 1), (1,))ds.addSample((1, 0), (1,))ds.addSample((1, 1), (0,))for inpt, target in ds:    print inpt,targettrainer=BackpropTrainer(net, ds)d=1while d>1e-8:    d = trainer.train()print("结果:")print net.activate([0,0])print net.activate([0,1])print net.activate([1,0])print net.activate([1,1])


Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32Type "copyright", "credits" or "license()" for more information.>>> ================================ RESTART ================================>>> [ 0.  0.] [ 0.][ 0.  1.] [ 1.][ 1.  0.] [ 1.][ 1.  1.] [ 0.][ 0.00010477][ 0.99989226][ 0.99986574][ 0.00018769]>>> 



0 0
原创粉丝点击