本文整理汇总了Python中pybrain.supervised.RPropMinusTrainer.testOnData方法的典型用法代码示例。如果您正苦于以下问题:Python RPropMinusTrainer.testOnData方法的具体用法?Python RPropMinusTrainer.testOnData怎么用?Python RPropMinusTrainer.testOnData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybrain.supervised.RPropMinusTrainer
的用法示例。
在下文中一共展示了RPropMinusTrainer.testOnData方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
def main():
generated_data = [0 for i in range(10000)]
rate, data = get_data_from_wav("../../data/natabhairavi_violin.wav")
data = data[1000:190000]
print("Got wav")
ds = SequentialDataSet(1, 1)
for sample, next_sample in zip(data, cycle(data[1:])):
ds.addSample(sample, next_sample)
net = buildNetwork(1, 5, 1,
hiddenclass=LSTMLayer, outputbias=False, recurrent=True)
trainer = RPropMinusTrainer(net, dataset=ds)
train_errors = [] # save errors for plotting later
EPOCHS_PER_CYCLE = 5
CYCLES = 10
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
for i in xrange(CYCLES):
trainer.trainEpochs(EPOCHS_PER_CYCLE)
train_errors.append(trainer.testOnData())
epoch = (i+1) * EPOCHS_PER_CYCLE
print("\r epoch {}/{}".format(epoch, EPOCHS), end="")
stdout.flush()
# predict new values
old_sample = [100]
for i in xrange(500000):
new_sample = net.activate(old_sample)
old_sample = new_sample
generated_data[i] = new_sample[0]
print(new_sample)
wavfile.write("../../output/test.wav", rate, np.array(generated_data))
示例2: train
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
def train(d, cycles=100, epochs_per_cycle=7):
ds = SequentialDataSet(1, 1)
net = buildNetwork(1, 5, 1, hiddenclass=LSTMLayer, outputbias=False, recurrent=False)
for sample, next_sample in zip(d, cycle(d[1:])):
ds.addSample(sample, next_sample)
trainer = RPropMinusTrainer(net, dataset=ds)
train_errors = [] # save errors for plotting later
for i in xrange(cycles):
trainer.trainEpochs(epochs_per_cycle)
train_errors.append(trainer.testOnData())
stdout.flush()
return net, train_errors
示例3: train
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
def train (ds, net):
# Train the network
trainer = RPropMinusTrainer(net, dataset=ds)
train_errors = [] # save errors for plotting later
EPOCHS_PER_CYCLE = 5
CYCLES = 100
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
for i in xrange(CYCLES):
trainer.trainEpochs(EPOCHS_PER_CYCLE)
error = trainer.testOnData()
train_errors.append(error)
epoch = (i+1) * EPOCHS_PER_CYCLE
print("\r epoch {}/{}".format(epoch, EPOCHS))
stdout.flush()
# print("final error =", train_errors[-1])
return train_errors, EPOCHS, EPOCHS_PER_CYCLE
示例4: handle
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
def handle(self, *args, **options):
ticker = args[0]
print("****** STARTING PREDICTOR " + ticker + " ******* ")
prices = Price.objects.filter(symbol=ticker).order_by('-created_on').values_list('price',flat=True)
data = normalization(list(prices[0:NUM_MINUTES_BACK].reverse()))
data = [ int(x * MULT_FACTOR) for x in data]
print(data)
ds = SupervisedDataSet(5, 1)
try:
for i,val in enumerate(data):
DS.addSample((data[i], data[i+1], data[i+2], data[i+3], data[i+4]), (data[i+5],))
except Exception:
pass;
net = buildNetwork(5, 40, 1,
hiddenclass=LSTMLayer, outputbias=False, recurrent=True)
trainer = RPropMinusTrainer(net, dataset=ds)
train_errors = [] # save errors for plotting later
EPOCHS_PER_CYCLE = 5
CYCLES = 100
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
for i in xrange(CYCLES):
trainer.trainEpochs(EPOCHS_PER_CYCLE)
train_errors.append(trainer.testOnData())
epoch = (i+1) * EPOCHS_PER_CYCLE
print("\r epoch {}/{}".format(epoch, EPOCHS), end="")
stdout.flush()
print()
print("final error =", train_errors[-1])
for sample, target in ds.getSequenceIterator(0):
show_pred_sample = net.activate(sample) / MULT_FACTOR
show_sample = sample / MULT_FACTOR
show_target = target / MULT_FACTOR
show_diff = show_pred_sample - show_target
show_diff_pct = 100 * show_diff / show_pred_sample
print("{} => {}, act {}. ({}%)".format(show_sample[0],round(show_pred_sample[0],3),show_target[0],int(round(show_diff_pct[0],0))))
示例5: say_hello_text
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
def say_hello_text(username = "World",text="You are good"):
object_data_new = pd.read_csv('/Users/ruiyun_zhou/Documents/cmpe-274/data/data.csv')
data_area_new = object_data_new[object_data_new.Area==username]
data_area_new_1=data_area_new[data_area_new.Disease== text]
data_list_new = data_area_new_1['Count'].values.tolist()
print data_list_new.__len__()
data_list=data_list_new
ds = SequentialDataSet(1,1)
isZero=0;
for sample,next_sample in zip(data_list,cycle(data_list[1:])):
ds.addSample(sample, next_sample)
if sample:
isZero=1
if(isZero==0):
return '[0, 0]'
net = buildNetwork(1,5,1,hiddenclass=LSTMLayer,outputbias=False,recurrent=True)
trainer = RPropMinusTrainer(net, dataset=ds)
train_errors = [] # save errors for plotting later
EPOCHS_PER_CYCLE = 5
CYCLES = 10
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
for i in xrange(CYCLES):
print "Doing epoch %d" %i
trainer.trainEpochs(EPOCHS_PER_CYCLE)
train_errors.append(trainer.testOnData())
epoch = (i+1) * EPOCHS_PER_CYCLE
# return '<p>%d</p>\n' % (data_list_new.__len__())
# print("final error =", train_errors[-1])
# print "Value for last week is %4.1d" % abs(data_list[-1])
# print "Value for next week is %4.1d" % abs(net.activate(data_list[-1]))
# result = (abs(data_list[-1]))
result = (abs(net.activate(data_list[-1])))
result_1 = (abs(net.activate(result)))
return '[%d, %d]' % (result,result_1)
示例6: train
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
def train(data,name):
ds = SequentialDataSet(1, 1)
for sample, next_sample in zip(data, cycle(data[1:])):
ds.addSample(sample, next_sample)
net = buildNetwork(1, 200, 1, hiddenclass=LSTMLayer, outputbias=False, recurrent=True)
trainer = RPropMinusTrainer(net, dataset=ds)
train_errors = [] # save errors for plotting later
EPOCHS_PER_CYCLE = 5
CYCLES = 20
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
store=[]
for i in xrange(CYCLES):
trainer.trainEpochs(EPOCHS_PER_CYCLE)
train_errors.append(trainer.testOnData())
epoch = (i+1) * EPOCHS_PER_CYCLE
print("\r epoch {}/{}".format(epoch, EPOCHS))
print tm.time()-atm
stdout.flush()
for sample, target in ds.getSequenceIterator(0):
store.append(net.activate(sample))
abcd=pd.DataFrame(store)
abcd.to_csv(pwd+"lstmdata/"+name+".csv",encoding='utf-8')
print "result printed to file"
示例7: RPropMinusTrainer
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
from pybrain.supervised import RPropMinusTrainer
from sys import stdout
print 'Starting to train neural network. . .'
trainer = RPropMinusTrainer(net, dataset=ds)
train_errors = [] # save errors for plotting later
EPOCHS_PER_CYCLE = 2
#CYCLES = 200
CYCLES = 100
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
print 'Entering loop. . .'
for i in xrange(CYCLES):
# Does the training
trainer.trainEpochs(EPOCHS_PER_CYCLE)
train_errors.append(trainer.testOnData())
epoch = (i + 1) * EPOCHS_PER_CYCLE
print 'i: ', i
print ('\r epoch {}/{}'.format(epoch, EPOCHS))
stdout.flush()
print 'Exit loop'
print ''
print 'final error =', train_errors[-1]
# Plot the errors (note that in this simple toy example,
# we are testing and training on the same dataset, which
# is of course not what you'd do for a real project!):
import matplotlib.pyplot as plt
示例8: rnn
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
def rnn():
# load dataframe from csv file
df = pi.load_data_frame('../../data/NABIL.csv')
# column name to match with indicator calculating modules
# TODO: resolve issue with column name
df.columns = [
'Transactions',
'Traded_Shares',
'Traded_Amount',
'High',
'Low',
'Close']
data = df.Close.values
# TODO: write min_max normalization
# normalization
# cp = dataframe.pop(' Close Price')
# x = cp.values
temp = np.array(data).reshape(len(data),1)
min_max_scaler = preprocessing.MinMaxScaler()
data = min_max_scaler.fit_transform(temp)
# dataframe[' Close Price'] = x_scaled
# prepate sequential dataset for pyBrain rnn network
ds = SequentialDataSet(1, 1)
for sample, next_sample in zip(data, cycle(data[1:])):
ds.addSample(sample, next_sample)
# build rnn network with LSTM layer
# if saved network is available
if(os.path.isfile('random.xml')):
net = NetworkReader.readFrom('network.xml')
else:
net = buildNetwork(1, 20, 1,
hiddenclass=LSTMLayer, outputbias=False, recurrent=True)
# build trainer
trainer = RPropMinusTrainer(net, dataset=ds, verbose = True)
train_errors = [] # save errors for plotting later
EPOCHS_PER_CYCLE = 5
CYCLES = 5
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
for i in range(CYCLES):
trainer.trainEpochs(EPOCHS_PER_CYCLE)
train_errors.append(trainer.testOnData())
epoch = (i+1) * EPOCHS_PER_CYCLE
print("\r epoch {}/{}".format(epoch, EPOCHS), end="")
sys.stdout.flush()
# save the network
NetworkWriter.writeToFile(net,'network.xml')
print()
print("final error =", train_errors[-1])
predicted = []
for dat in data:
predicted.append(net.activate(dat)[0])
# data = min_max_scaler.inverse_transform(data)
# predicted = min_max_scaler.inverse_transform(predicted)
predicted_array = min_max_scaler.inverse_transform(np.array(predicted).reshape(-1,1))
print(predicted_array[-1])
plt.figure()
legend_actual, = plt.plot(range(0, len(data)),temp, label = 'actual', linestyle = '--', linewidth = 2, c = 'blue')
legend_predicted, = plt.plot(range(0, len(data)), predicted_array, label = 'predicted', linewidth = 1.5, c='red')
plt.legend(handles=[legend_actual, legend_predicted])
plt.savefig('error.png')
plt.show()
示例9: xrange
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
train_errors_2 = []
train_errors_3 = []
train_errors_4 = []
train_errors_5 = []
train_errors_6 = []
train_errors_8 = []
train_errors_9 = []
train_errors_10 = []
# Training
EPOCHS_per_CYCLE = 6
NUM_CYCLES = 15
EPOCHS = EPOCHS_per_CYCLE * NUM_CYCLES
for i in xrange(NUM_CYCLES):
trainer.trainEpochs(EPOCHS_per_CYCLE)
train_errors.append(trainer.testOnData())
trainer_2.trainEpochs(EPOCHS_per_CYCLE)
train_errors_2.append(trainer_2.testOnData())
trainer_3.trainEpochs(EPOCHS_per_CYCLE)
train_errors_3.append(trainer_3.testOnData())
trainer_4.trainEpochs(EPOCHS_per_CYCLE)
train_errors_4.append(trainer_4.testOnData())
trainer_5.trainEpochs(EPOCHS_per_CYCLE)
train_errors_5.append(trainer_5.testOnData())
trainer_6.trainEpochs(EPOCHS_per_CYCLE)
train_errors_6.append(trainer_6.testOnData())
trainer_8.trainEpochs(EPOCHS_per_CYCLE)
train_errors_8.append(trainer_8.testOnData())
trainer_9.trainEpochs(EPOCHS_per_CYCLE)
train_errors_9.append(trainer_9.testOnData())
trainer_10.trainEpochs(EPOCHS_per_CYCLE)
示例10: learn
# 需要导入模块: from pybrain.supervised import RPropMinusTrainer [as 别名]
# 或者: from pybrain.supervised.RPropMinusTrainer import testOnData [as 别名]
#.........这里部分代码省略.........
self.dictIn["WORD_"+word]=index
index+=1
self.TOTALSIZEOFSENTENCEFeature=index
f=open(self.FileNameofNumSentenceFeature,"wb")
pickle.dump(self.TOTALSIZEOFSENTENCEFeature,f)
f.close()
elif self.isUseSentenceRepresentationInsteadofBOW:
index=0
for i in range(0,LSTMWithBOWTracker.D2V_VECTORSIZE):
self.dictIn[str(index)+"thElemPV"]=index
index+=1
index=0
for i in range(0,LSTMWithBOWTracker.D2V_VECTORSIZE):
self.dictIn[str(index)+"thAvrWord"]=index
index+=1
assert self.D2V_VECTORSIZE == LSTMWithBOWTracker.D2V_VECTORSIZE, "D2V_VECTORSIZE is restrected to be same over the class"
else:
assert False, "Unexpected block"
#--(sub input vector 3) Features M1s defined
index=0
if self.isEnableToUseM1sFeature:
rejisteredFeatures=self.__rejisterM1sInputFeatureLabel(self.tagsets,dataset)
for rFeature in rejisteredFeatures:
assert rFeature not in self.dictIn, rFeature +" already registered in input vector. Use different label name. "
self.dictIn[rFeature]=index
index+=1
self.TOTALSIZEOFM1DEFINEDFeature=index
f=open(self.FileNameofNumM1Feature,"wb")
pickle.dump(self.TOTALSIZEOFM1DEFINEDFeature,f)
f.close()
print "inputSize:"+str(len(self.dictIn.keys()))
assert self.dictIn["CLASS_INFO"] == 0, "Unexpected index CLASS_INFO should has value 0"
assert self.dictIn["CLASS_Fort Siloso"] == 334, "Unexpected index CLASS_Fort Siloso should has value 334"
assert self.dictIn["CLASS_Yunnan"] == 1344, "Unexpected index CLASS_Yunnan should has value 1611"
#--write
fileObject = open('dictInput.pic', 'w')
pickle.dump(self.dictIn, fileObject)
fileObject.close()
fileObject = open('dictOutput.pic', 'w')
pickle.dump(self.dictOut, fileObject)
fileObject.close()
#Build RNN frame work
print "Start learning Network"
#Capability of network is: (30 hidden units can represents 1048576 relations) wherease (10 hidden units can represents 1024)
#Same to Henderson (http://www.aclweb.org/anthology/W13-4073)?
net = buildNetwork(len(self.dictIn.keys()), numberOfHiddenUnit, len(self.dictOut.keys()), hiddenclass=LSTMLayer, outclass=SigmoidLayer, outputbias=False, recurrent=True)
#Train network
#-convert training data into sequence of vector
convDataset=[]#[call][uttr][input,targetvec]
iuttr=0
convCall=[]
for elemDataset in dataset:
for call in elemDataset:
for (uttr,label) in call:
if self.isIgnoreUtterancesNotRelatedToMainTask:
if uttr['segment_info']['target_bio'] == "O":
continue
#-input
convInput=self._translateUtteranceIntoInputVector(uttr,call)
#-output
convOutput=[0.0]*len(self.dictOut.keys())#Occured:+1, Not occured:0
if "frame_label" in label:
for slot in label["frame_label"].keys():
for value in label["frame_label"][slot]:
convOutput[self.dictOut[uttr["segment_info"]["topic"]+"_"+slot+"_"+value]]=1
#-post proccess
if self.isSeparateDialogIntoSubDialog:
if uttr['segment_info']['target_bio'] == "B":
if len(convCall) > 0:
convDataset.append(convCall)
convCall=[]
convCall.append([convInput,convOutput])
#print "Converted utterance" + str(iuttr)
iuttr+=1
if not self.isSeparateDialogIntoSubDialog:
if len(convCall) > 0:
convDataset.append(convCall)
convCall=[]
#Online learning
trainer = RPropMinusTrainer(net,weightdecay=weightdecayw)
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
for i in xrange(CYCLES):
#Shuffle order
ds = SequentialDataSet(len(self.dictIn.keys()),len(self.dictOut.keys()))
datInd=range(0,len(convDataset))
random.shuffle(datInd)#Backpropergation already implemeted data shuffling, however though RpropMinus don't.
for ind in datInd:
ds.newSequence()
for convuttr in convDataset[ind]:
ds.addSample(convuttr[0],convuttr[1])
#Evaluation and Train
epoch = (i+1) * EPOCHS_PER_CYCLE
print "\r epoch {}/{} Error={}".format(epoch, EPOCHS,trainer.testOnData(dataset=ds))
stdout.flush()
trainer.trainOnDataset(dataset=ds,epochs=EPOCHS_PER_CYCLE)
NetworkWriter.writeToFile(trainer.module, "LSTM_"+"Epoche"+str(i+1)+".rnnw")
NetworkWriter.writeToFile(trainer.module, "LSTM.rnnw")