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


Python SequentialDataSet.getSample方法代码示例

本文整理汇总了Python中pybrain.datasets.SequentialDataSet.getSample方法的典型用法代码示例。如果您正苦于以下问题:Python SequentialDataSet.getSample方法的具体用法?Python SequentialDataSet.getSample怎么用?Python SequentialDataSet.getSample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pybrain.datasets.SequentialDataSet的用法示例。


在下文中一共展示了SequentialDataSet.getSample方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: train

# 需要导入模块: from pybrain.datasets import SequentialDataSet [as 别名]
# 或者: from pybrain.datasets.SequentialDataSet import getSample [as 别名]
  def train(self, params):

    self.net.reset()

    ds = SequentialDataSet(self.nDimInput, self.nDimOutput)
    trainer = RPropMinusTrainer(self.net, dataset=ds, verbose=False)

    history = self.window(self.history, params)
    resets = self.window(self.resets, params)

    for i in xrange(params['prediction_nstep'], len(history)):
      if not resets[i-1]:
        ds.addSample(self.inputEncoder.encode(history[i-params['prediction_nstep']]),
                     self.outputEncoder.encode(history[i][0]))
      if resets[i]:
        ds.newSequence()

    # print ds.getSample(0)
    # print ds.getSample(1)
    # print ds.getSample(1000)
    # print " training data size", ds.getLength(), " len(history) ", len(history), " self.history ", len(self.history)
    # print ds

    if len(history) > 1:
      trainer.trainEpochs(params['num_epochs'])

    self.net.reset()
    for i in xrange(len(history) - params['prediction_nstep']):
      symbol = history[i]
      output = self.net.activate(ds.getSample(i)[0])

      if resets[i]:
        self.net.reset()
开发者ID:chanceraine,项目名称:nupic.research,代码行数:35,代码来源:suite.py

示例2: train

# 需要导入模块: from pybrain.datasets import SequentialDataSet [as 别名]
# 或者: from pybrain.datasets.SequentialDataSet import getSample [as 别名]
  def train(self, params, verbose=False):

    if params['reset_every_training']:
      if verbose:
        print 'create lstm network'

      random.seed(6)
      if params['output_encoding'] == None:
        self.net = buildNetwork(self.nDimInput, params['num_cells'], self.nDimOutput,
                           hiddenclass=LSTMLayer, bias=True, outputbias=True, recurrent=True)
      elif params['output_encoding'] == 'likelihood':
        self.net = buildNetwork(self.nDimInput, params['num_cells'], self.nDimOutput,
                           hiddenclass=LSTMLayer, bias=True, outclass=SigmoidLayer, recurrent=True)

    self.net.reset()

    ds = SequentialDataSet(self.nDimInput, self.nDimOutput)
    networkInput = self.window(self.networkInput, params)
    targetPrediction = self.window(self.targetPrediction, params)

    # prepare a training data-set using the history
    for i in xrange(len(networkInput)):
      ds.addSample(self.inputEncoder.encode(networkInput[i]),
                   self.outputEncoder.encode(targetPrediction[i]))

    if params['num_epochs'] > 1:
      trainer = RPropMinusTrainer(self.net, dataset=ds, verbose=verbose)

      if verbose:
        print " train LSTM on ", len(ds), " records for ", params['num_epochs'], " epochs "

      if len(networkInput) > 1:
        trainer.trainEpochs(params['num_epochs'])

    else:
      self.trainer.setData(ds)
      self.trainer.train()

    # run through the training dataset to get the lstm network state right
    self.net.reset()
    for i in xrange(len(networkInput)):
      self.net.activate(ds.getSample(i)[0])
开发者ID:andrewmalta13,项目名称:nupic.research,代码行数:44,代码来源:run_lstm_suite.py


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