当前位置: 首页>>代码示例>>Python>>正文


Python SequentialDataSet.getSequenceIterator方法代码示例

本文整理汇总了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"
开发者ID:elishaROBINSON,项目名称:stock_Prediction_Neural_net,代码行数:26,代码来源:neural_net_train&store_data.py

示例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
开发者ID:maranemil,项目名称:Midi-AI-Melody-Generator,代码行数:33,代码来源:ai-melody-composer.py

示例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)
开发者ID:indiejoseph,项目名称:nn_trading,代码行数:32,代码来源:test_ohlc.py

示例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))
开发者ID:LoicBontempsINSA,项目名称:LSTM_RNN_Collective_Anomaly_Detection,代码行数:32,代码来源:CADTest.py

示例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) )

开发者ID:beekal,项目名称:UdacityMachieneLearningProjects,代码行数:31,代码来源:test+LSTM.py


注:本文中的pybrain.datasets.SequentialDataSet.getSequenceIterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。