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


Python MLP.update_weights方法代码示例

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


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

示例1: main

# 需要导入模块: from mlp import MLP [as 别名]
# 或者: from mlp.MLP import update_weights [as 别名]
def main():
  training, count_c0, count_c1 = get_data(122)
  dev, _, _ = get_data(122,True)
  series_c0, series_c1 = get_time_series()
  # A window of 240 corresponds to two hours of heart rate
  window_size = 240
  print "#class0: ", count_c0/float(window_size), "#class1:", count_c1/float(window_size)
  c1 = 0
  c0 = 0
  print "len training = " + str(len(training))
  count0 = 0
  count1 = 0
  random.shuffle(training)
  n_input = window_size
  n_hidden = 100
  n_output = 1
  num_hidden_layers = 1
  eta_c = .005
  A = .0008
  eta = eta_c
  mlp = MLP(n_input, num_hidden_layers, n_hidden, n_output, eta)
  n_epochs = 400
  step = True

  l = loss(mlp, training, window_size, window_size/2)
  print "initial loss: " + str(l)
  for j in range(0, n_epochs):
    print "epoch " + str(j)
    random.shuffle(training)
    c = 0
    grad = None
    for xs, y in training:
      if c == 10:
        break
      c += 1
      part_grad = None
      if step:
        part_grad = train(mlp, xs, y, window_size, window_size/2)
      else:
        part_grad = train(mlp, xs, y, window_size, 1)

      grad = sum_grad(grad, part_grad)
    mlp.update_weights(grad)
    if step:
      error(mlp, training, window_size, window_size/2)
    else:
      error(mlp, training, window_size, 1) 
    if step:
      l = loss(mlp, training, window_size, window_size/2)
    else:
      l = loss(mlp, training, window_size, 1)
    print "loss: " + str(l)
    eta = A / float(j/float(n_epochs) + 1)
    mlp.eta = eta
    print "lr:", mlp.eta
    if n_epochs % 10 == 0:
      if step:
        error(mlp, dev, window_size, window_size/2, True)
      else:
        error(mlp, dev, window_size, 1, True) 

  print "Getting training accuracy..." 
  if step:
    error(mlp, training, window_size, window_size/2)
  else:
    error(mlp, training, window_size, 1)
  print "Getting dev accuracy..." 
  if step:
    error(mlp, dev, window_size, window_size/2, True)
    probs(mlp, series_c0, series_c1, window_size, window_size/2)
  else:
    error(mlp, dev, window_size, 1, True)
    probs(mlp, series_c0, series_c1, window_size, 1)
开发者ID:d-unknown-processor,项目名称:mlcd_proj,代码行数:75,代码来源:sepsis_heartrate_test.py


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