本文整理汇总了Python中pybrain.supervised.trainers.RPropMinusTrainer.setData方法的典型用法代码示例。如果您正苦于以下问题:Python RPropMinusTrainer.setData方法的具体用法?Python RPropMinusTrainer.setData怎么用?Python RPropMinusTrainer.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybrain.supervised.trainers.RPropMinusTrainer
的用法示例。
在下文中一共展示了RPropMinusTrainer.setData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trainNetwork
# 需要导入模块: from pybrain.supervised.trainers import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.trainers.RPropMinusTrainer import setData [as 别名]
def trainNetwork(net, sample_list, validate_list, net_filename, max_epochs=5500, min_epochs=300):
count_input_samples = len(sample_list)
count_outputs = len(validate_list)
ds = SupervisedDataSet(count_input_samples, count_outputs)
ds.addSample(sample_list, validate_list)
trainer = RPropMinusTrainer(net, verbose=True)
trainer.setData(ds)
trainer.trainUntilConvergence(maxEpochs=max_epochs, continueEpochs=min_epochs)
NetworkWriter.writeToFile(net, net_filename)
return net
示例2: createAndTrainNetworkFromList
# 需要导入模块: from pybrain.supervised.trainers import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.trainers.RPropMinusTrainer import setData [as 别名]
def createAndTrainNetworkFromList(train_list, count_input_samples, net_filename, count_layers=33,
count_outputs=1, max_epochs=15000, min_epochs=300):
net = buildNetwork(count_input_samples, count_layers, count_outputs)
ds = SupervisedDataSet(count_input_samples, count_outputs)
count_samples = len(train_list)
for i in range(0, count_samples):
ds.addSample(train_list[i][:-count_outputs], train_list[i][-count_outputs])
trainer = RPropMinusTrainer(net, verbose=True)
trainer.setData(ds)
a = trainer.trainUntilConvergence(maxEpochs=max_epochs, continueEpochs=min_epochs, validationProportion=0.15)
net_filename = net_filename[:-4]+str(a[0][-1])+'.xml'
NetworkWriter.writeToFile(net, net_filename)
result_list = [a, net_filename]
return result_list
示例3: createAndTrainNetworkFromFile
# 需要导入模块: from pybrain.supervised.trainers import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.trainers.RPropMinusTrainer import setData [as 别名]
def createAndTrainNetworkFromFile(curs_filename, count_input_samples, count_samples, net_filename, count_layers=33,
count_outputs=1, max_epochs=15000, min_epochs=300):
net = buildNetwork(count_input_samples, count_layers, count_outputs)
ds = SupervisedDataSet(count_input_samples, count_outputs)
wb = load_workbook(filename=curs_filename)
ws = wb.active
for i in range(0, count_samples):
loaded_data = []
for j in range(0, count_input_samples + 1):
loaded_data.append(round(float(ws.cell(row=i+1, column=j+1).value), 4))
#ds.addSample(loaded_data[:-1], loaded_data[-1])
#print loaded_data[:-1], loaded_data[-1]
ds.addSample(loaded_data[:-1], loaded_data[-1])
trainer = RPropMinusTrainer(net, verbose=True)
trainer.setData(ds)
a = trainer.trainUntilConvergence(maxEpochs=max_epochs, continueEpochs=min_epochs, validationProportion=0.15)
net_filename = net_filename[:-4]+str(a[0][-1])+'.xml'
NetworkWriter.writeToFile(net, net_filename)
result_list = [a, net_filename]
return result_list
示例4: Brain
# 需要导入模块: from pybrain.supervised.trainers import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.trainers.RPropMinusTrainer import setData [as 别名]
class Brain():
def __init__(self):
self.inputs = 3
self.outputs = 1
self.n = buildNetwork(self.inputs, 200,200,200,200,self.outputs, bias=True,hiddenclass=TanhLayer)
self.n.sortModules()
self.ds = SupervisedDataSet(self.inputs, self.outputs)
self.trainer = RPropMinusTrainer(self.n)
self.trainer.setData(self.ds)
def wipedataset(self):
self.ds = SupervisedDataSet(self.inputs, self.outputs)
pass
def cycle(self,action,state):
return self.n.activate([action,state[0],state[1]])
def AddToTrainingSet(self,action,state,output):
out= "New Set","Action: ",action,"State: ", state,"Output: ", output
f.write(str(out)+"\n")
self.ds.addSample((action,state[0],state[1]),output)
def train(self):
return "ERROR",self.trainer.train()
def traintoconverg(self):
x = 10000
y=0
z=100
print len(self.ds),"DS SIZE"
while x > 0.0001 and y < z:
print len(self.ds)
x = self.trainer.train()
print x,"ERROR",y
y+=1
f = open('brains/brain2000.ann','w')
pickle.dump(self.n,f)
def trainfinal(self):
x = 10000
y=0
z=25
while x > 0.00001 and y < z:
x = self.trainer.train()
print x,"ERROR",y
y+=1
示例5: range
# 需要导入模块: from pybrain.supervised.trainers import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.trainers.RPropMinusTrainer import setData [as 别名]
n.addConnection(FullConnection(inLayer, hiddenLayers[0]))
for i in range(1, len(hiddenLayers)):
n.addConnection(FullConnection(hiddenLayers[i - 1], hiddenLayers[i]))
n.addConnection(FullConnection(hiddenLayers[len(hiddenLayers) - 1], outLayer))
n.sortModules()
# training set
DS = SupervisedDataSet(10, 5)
trainer = RPropMinusTrainer(n, verbose=True, batchlearning=True, learningrate=0.01, lrdecay=0.0, momentum=0.0,
weightdecay=0.0)
trainer.setData(DS)
data = days('btceUSD.days.csv')
def normalize(v, _max, _min):
return 2.0 / (_max - _min) * (v - _min) - 1.0
def denormalize(v, _max, _min):
return (v + 1.0) / 2.0 * (_max - _min) + _min
def ticks_to_inputs_outputs(ticks, ticks_forecast):
window_prices = map(lambda (x): x[0], ticks)
window_volumes = map(lambda (x): x[1], ticks)
示例6: SupervisedDataSet
# 需要导入模块: from pybrain.supervised.trainers import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.trainers.RPropMinusTrainer import setData [as 别名]
nr.append(ratio)
print ratio, column
else:
print column, "not an int or long"
return np.array(nr[:-1]), nr[-1]
data = cursor.execute("select %s from adult_data" % columns).fetchall()
dataset = SupervisedDataSet(8, 1)
for row in data:
xd, yd = createNPRow(row)
dataset.addSample(xd, yd)
nn = buildNetwork(8, 3, 1)
trainer = RPropMinusTrainer(nn)
trainer.setData(dataset)
for x in range(5):
error = trainer.train()
print error
errors, success = 0,0
for row in cursor.execute("select %s from adult_test" % columns).fetchall():
xd, yd = createNPRow(row)
check = int(round(nn.activate(xd[:8])[0]))
if check > 1: check = 1
prediction = possibilities['relation_to_50k_plus'][check]
actual = possibilities['relation_to_50k_plus'][yd]
if prediction == actual:
match = "match"
success += 1
示例7: buildNetwork
# 需要导入模块: from pybrain.supervised.trainers import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.trainers.RPropMinusTrainer import setData [as 别名]
testset.append((a,random.uniform(-math.pi,-math.pi/2),-1))
testset.append((a,random.uniform(math.pi/2,math.pi),-1))
elif a == 1:
testset.append((a,random.uniform(-math.pi,0),1))
testset.append((a,random.uniform(0,math.pi),-1))
else:
testset.append((a,random.uniform(0,math.pi),1))
testset.append((a,random.uniform(-math.pi,0),-1))
ann = buildNetwork(2,20,1,bias=True,hiddenclass=TanhLayer)
ds = SupervisedDataSet(2,1)
ann.sortModules()
trainer = RPropMinusTrainer(ann)
trainer.setData(ds)
for i in dataset:
ds.addSample((i[0],i[1]),i[2])
i=10000
x=0
z=100
while i > 0.0001 and x<z:
i = trainer.train()
print i
x+=1
for a in testset:
result = ann.activate([a[0],a[1]])
print str(a[2]) +" actual vs. output " +str(result)