Exemplo n.º 1
0
def run(verbose=True, Y=1, D=2, dataset=2, in_path=None, out_path=None, steps=2):
  ripl = s.make_puma_church_prime_ripl()

  total_birds = 1000 if dataset == 2 else 1000000
  name = "%dx%dx%d-train" % (width, height, total_birds)

  params = {
    "name":name,
    "width":width,
    "height":height,
    "cells":cells,
    "dataset":dataset,
    "total_birds":total_birds,
    "years":range(Y),
    "days":[],
    "hypers":hypers,
    "in_path":in_path,
    "out_path":out_path,
  }

  model = Poisson(ripl, params)

  if verbose:
    print "Starting run"
  ripl.clear()
  model.loadAssumes()
  model.updateObserves(0)
  
  logs = []
  t = [time.time()] # python :(
  
  def log():
    dt = time.time() - t[0]
    #logs.append((ripl.get_global_logscore(), model.computeScoreDay(model.days[-2]), dt))
    logs.append((ripl.get_global_logscore(), dt))
    if verbose:
      print logs[-1]
    t[0] += dt
  
  for d in range(1, D):
    if verbose:
      print "Day %d" % d
    model.updateObserves(d)
    log()
    
    for i in range(steps):
      ripl.infer({"kernel":"mh", "scope":d-1, "block":"one", "transitions": Y*1000})
      log()
      continue
      bird_locs = model.getBirdLocations(days=[d])
      
      for y in range(Y):
        path = 'bird_moves%d/%d/%02d/' % (dataset, y, d)
        ensure(path)
        drawBirds(bird_locs[y][d], path + '%02d.png' % i, **params)
  
  #model.drawBirdLocations()
  model.writeBirdMoves()
  
  return logs
Exemplo n.º 2
0
def run(verbose=True, Y=1, D=2, dataset=2, in_path=None, out_path=None, steps=2):
    ripl = s.make_puma_church_prime_ripl()

    total_birds = 1000 if dataset == 2 else 1000000
    name = "%dx%dx%d-test" % (width, height, total_birds)

    params = {
        "name": name,
        "width": width,
        "height": height,
        "cells": cells,
        "dataset": dataset,
        "total_birds": total_birds,
        "years": range(Y),
        "days": [],
        "hypers": hypers,
        "in_path": in_path,
        "out_path": out_path,
    }

    model = Poisson(ripl, params)

    if verbose:
        print "Starting run"
    ripl.clear()
    model.loadAssumes()

    predictions = {}

    for d in range(D - 1):
        if verbose:
            print "Day %d" % d
        model.updateObserves(d)

        if d > 0:
            for i in range(5):
                ripl.infer({"kernel": "mh", "scope": d - 1, "block": "one", "transitions": Y * 1000})

        last_day = d == D - 2

        if last_day:
            bird_moves = ripl.predict("(get_birds_moving3 %d)" % d, label="predict%d" % d)
        else:
            bird_moves = [ripl.predict("(get_birds_moving3 %d)" % t, label="predict%d" % t) for t in [d, d + 1]]

        for y in range(Y):
            for i in range(cells):
                for j in range(cells):
                    if last_day:
                        predictions[(y, d - 1, i, j)] = [bird_moves[y][i][j], -1]
                    else:
                        predictions[(y, d - 1, i, j)] = [b[y][i][j] for b in bird_moves]

        for t in [d] if last_day else [d, d + 1]:
            ripl.forget("predict%d" % t)

    # model.drawBirdLocations()

    writePredictions(predictions, **params)