# -*- coding: cp936 -*-
#
# pyneurgen神经网络-遗传算法分析包,构建简单的神经网络并进行预测
#下载地址:http://sourceforge.net/projects/pyneurgen/files/
#内部doc帮助文档,简单易懂,但demo不完全。
import random
import math
from pyneurgen.neuralnet import NeuralNet
# struct random input number In range(0.8,1);targetnumber always=1.0
inputdata=[]
target=[]
for i in range(20):
a=[]
a.append(random.uniform(0.8,1))
inputdata.append(a)
target.append([1.0])
# 建立神经网络
net=NeuralNet()
net.init_layers(1,[10],1)#输入、隐含、输出层建立
net.randomize_network()
net.set_halt_on_extremes(True)
net.set_random_constraint(0.5)
net.set_learnrate(.1)
net.set_all_inputs(inputdata)
net.set_all_targets(target)
net.set_learn_range(0,19)
net.set_test_range(16,19)
net.layers[1].set_