本文整理汇总了Python中pybrain.datasets.SequentialDataSet.getSequenceIterator方法的典型用法代码示例。如果您正苦于以下问题:Python SequentialDataSet.getSequenceIterator方法的具体用法?Python SequentialDataSet.getSequenceIterator怎么用?Python SequentialDataSet.getSequenceIterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybrain.datasets.SequentialDataSet
的用法示例。
在下文中一共展示了SequentialDataSet.getSequenceIterator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train
# 需要导入模块: from pybrain.datasets import SequentialDataSet [as 别名]
# 或者: from pybrain.datasets.SequentialDataSet import getSequenceIterator [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"
示例2: MIDIFile
# 需要导入模块: from pybrain.datasets import SequentialDataSet [as 别名]
# 或者: from pybrain.datasets.SequentialDataSet import getSequenceIterator [as 别名]
MyMIDI = MIDIFile(1)
track = 0
time = 0
MyMIDI.addTrackName(track,time,"Sample Track")
#tempo = 120
tempo = 120
MyMIDI.addTempo(track,time,tempo)
i = 0
time = 0
prev_pitch_ar = np.array([])
# Preform seeding (although seeding is not random, it seeds the original midi song)
for (sample, target) in ds.getSequenceIterator(0):
#print track_fi
# Part of code used to have generator predict based on its own prev notes
'''
if i != 0:
sample = prev_ac_ar
'''
pred_ar = net.activate(sample)
tick_n = int(pred_ar[2])
pitch_n = int(pred_ar[0])
velocity_n = int(pred_ar[1])
# To remove negative numbers and turn them into zero
示例3: xrange
# 需要导入模块: from pybrain.datasets import SequentialDataSet [as 别名]
# 或者: from pybrain.datasets.SequentialDataSet import getSequenceIterator [as 别名]
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()
# test output
predict_list = []
actual_list = []
err = []
for sample, target in test_ds.getSequenceIterator(0):
p = net.activate(sample)
a = np.argmax(p)
d1 = p[a]
if a == 1:
d1 = -p[a]
t = np.argmax(target)
d2 = target[t]
if t == 1:
d2 = -target[t]
predict = (d1 * sample[3]) + sample[3]
actual = (d2 * sample[3]) + sample[3]
err.append(abs((d2 - d1) / d1)) # compute error rate
predict_list.append(predict)
actual_list.append(actual)
示例4: abs
# 需要导入模块: from pybrain.datasets import SequentialDataSet [as 别名]
# 或者: from pybrain.datasets.SequentialDataSet import getSequenceIterator [as 别名]
DC = 0
tab_avg_error = []
the_errors = []
MAT = 20
circular_array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
detector = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# Thresholds for collective anomaly detection, up to the user and their systems to set them
AVERAGE_THRESH = 0.8
DC_Thresh = 8
RET = 0.9
# Testing and detecting collective errors
for current_sample, target in dataset_bis.getSequenceIterator(0):
# Test the data -- comp is the output of the network
comp = network.activate(current_sample)
# Error calculation
erreur = comp - target
the_errors.insert(my_error_position, abs(erreur))
position += 1
position = position % MAT
# Integrating the newly calculated error value to the circular array
circular_array.pop(position)
circular_array.insert(position, abs(erreur))
示例5: print
# 需要导入模块: from pybrain.datasets import SequentialDataSet [as 别名]
# 或者: from pybrain.datasets.SequentialDataSet import getSequenceIterator [as 别名]
trainer.trainEpochs(EPOCHS_PER_CYCLE) # train on the given data set for given number of epochs
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])
## Plot the data and the training
import matplotlib.pyplot as plt
plt.plot(range(0, EPOCHS, EPOCHS_PER_CYCLE), train_errors)
plt.xlabel('epoch')
plt.ylabel('error')
plt.show()
mape_error = 0
count = 0
## Predict new examples
for sample, actual in ds.getSequenceIterator(0):
PredictedValue = net.activate(sample)
count = count + 1
# MAPE Error
CurrentError = abs ((actual - PredictedValue) * 100.00 / actual )
mape_error = mape_error + CurrentError
print(" sample = %4.3f. Prediction = %4.3f. Actual = %4.3f. Error = %4.3f. Normalised Error = %4.3f " % (sample, PredictedValue, actual, (actual - PredictedValue ), CurrentError ) )
print ("Total Mean Absolute Percentage Error = %4.3f Percentage" % (mape_error/count) )