Ejemplo n.º 1
0
def runKsTest(mi):
  mi = str(mi)
  expDir = stocPy.getCurDir(__file__) + "/"
  paths = ["normal" + mi + "Met3600", "normal" + mi + "Dec5Met600", "normal" + mi + "Dec10Met600", "normal" + mi + "Dec15Met600"]
  titles = ["Metropolis 60m", "Metropolis Dec5 10m", "Metropolis Dec10 10m", "Metropolis Dec15 10m"]
  paths = [expDir + path for path in paths]

  #stocPy.calcKSTest(expDir + "normal" + mi + "Post", paths, names = titles)
  stocPy.calcKSTests(expDir + "normal" + mi + "Post", paths, aggFreq=np.logspace(1,math.log(50000,10),10), burnIn=1000, single=True, alpha=1, names=titles, ylim=[0.0225, 1.5], title="Single Run performance on NormalMean" + mi +"-prior = Unif(0,10000)")
Ejemplo n.º 2
0
def genRuns(model, noRuns, time, fn, alg="met", autoNames=True):
  runs = []
  for i in range(noRuns):
    print str(model), "Run", i
    samples = stocPy.getTimedSamples(model, time, alg=alg, autoNames=autoNames)
    assert(len(samples.keys()) == 1)
    samples = samples[samples.keys()[0]]
    runs.append(samples)
  cd = stocPy.getCurDir(__file__)
  with open(cd + "/" + fn, 'w') as f:
    cPickle.dump(runs, f)
Ejemplo n.º 3
0
def genRuns(model, noRuns, time, fn, alg="met", autoNames=True):
  global obsMean
  runs = []
  for i in range(noRuns):
    print str(model), "Run", i
    samples, traceAcc = stocPy.getTimedSamples(model, time, alg=alg, autoNames=autoNames, outTraceAcc=True)
    runs.append(stocPy.procUserSamples(obsMean, traceAcc))
    obsMean = []
  cd = stocPy.getCurDir(__file__)
  print map(lambda run: (min(run.values()), max(run.values())), runs)
  with open(cd + "/" + fn, 'w') as f:
    cPickle.dump(runs, f)
Ejemplo n.º 4
0
def runKsRuns(mi, term = "MetRuns", paths = None, titles = None):
  mi = str(mi)

  expDir = stocPy.getCurDir(__file__) + "/"

  if not paths:
    paths = ["normal" + mi + term, "normal" + mi + "Dec5" + term, "normal" + mi + "Dec10" + term, "normal" + mi + "Dec15" + term]
  if not titles:
    titles = ["Metropolis", "Metropolis Dec5", "Metropolis Dec10", "Metropolis Dec15"]
  paths = [expDir + path for path in paths]

  stocPy.calcKSSumms(expDir + "normal" + mi + "Post", paths, aggFreq=np.logspace(1,math.log(1000000,10),10), burnIn=0, names=titles, modelName = "NormalMean" + mi, postXlim=[float("-inf"), float("inf")])
Ejemplo n.º 5
0
def genPost(ps, data, fn=None, show=False, prior=ss.uniform(0,20).pdf, xlim=None, title=None):
  post = anlPost(data, ps, prior) 
  xs, ys = zip(*sorted(post.items()))
  if fn:
    cd = stocPy.getCurDir(__file__)
    with open(cd + "/" + fn, 'w') as f:
      cPickle.dump((xs,ys), f)
  if show:
    plt.plot(xs, ys)
    if xlim:
      plt.xlim(xlim)
    if title:
      plt.title(title)
    plt.show()
Ejemplo n.º 6
0
def genRuns(model, noRuns, runTime, fn, alg, autoNames=False, discAll=False):
  global startTime
  global stateHist
  global singleStateHist
  runs = []
  for i in range(noRuns):
    print str(model), "Run", i
    #startTime = time.time()
    samples = stocPy.getTimedSamples(model, runTime, alg=alg, autoNames=autoNames, discAll=discAll, orderNames=True)
    #print map(lambda x: dict([(k,v/float(len(stateHist))) for (k,v) in sorted(dict(Counter(x)).items())]), zip(*stateHist))
    runs.append(samples)#copy.deepcopy(stateHist))#singleStateHist))#map(lambda x: dict([(k,v/float(len(stateHist))) for (k,v) in sorted(dict(Counter(x)).items())]), zip(*stateHist)))
    #stateHist = []
    #singleStateHist = {}
  cd = stocPy.getCurDir(__file__)
  #print runs
  with open(cd + "/" + fn, 'w') as f:
    cPickle.dump(runs, f)
Ejemplo n.º 7
0
      plt.title(title)
    plt.show()

if __name__ == "__main__":
  #for i in [0,1,2,4,8,16,32,64,128,256]:
  #  genPost(np.arange(0,10,0.01), prior=ss.uniform(0,10).pdf, data=[4]*i, show=True, xlim=(-1,11), title="data = " + str(i) + " 4s")
  #assert(False)
  no = "1"
  iters = 5
  time = 3
  term = "_" + str(iters) + "_" + str(time)
  global noLetters
  noLetters = getattr(sys.modules[__name__], "noLetters" + no)

  #met = stocPy.extractDict(stocPy.getTimedSamples(lettersPerDay, 10, alg="met"))
  #metExp = stocPy.extractDict(stocPy.getTimedSamples(lettersPerDayExp, 10, alg="met", autoNames=False))
  #slic = stocPy.extractDict(stocPy.getTimedSamples(lettersPerDay, 10, alg="sliceTD"))
  #slicExp = stocPy.extractDict(stocPy.getTimedSamples(lettersPerDayExp, 10, alg="sliceTD", autoNames=False))
  #print len(met)/float(len(metExp)), len(slic)/float(len(slicExp))
  #assert(False)
  #genPost(np.arange(0,20,0.01), noLetters, show=True, fn = "post" + no)
  #genRuns(lettersPerDayExp, iters, time, "runs" + no + "Exp" + term, autoNames=False)
  #genRuns(lettersPerDay, iters, time, "runs" + no + term)
  #genRuns(lettersPerDayPart10, iters, time, "runs" + no + "Part10" + term, alg="met")
  #genRuns(lettersPerDayPart10, iters, time, "runs" + no + "SlicePart10" + term, alg="sliceTD")
  #genRuns(lettersPerDayPartU20, iters, time, "runs" + no + "PartU20" + term)
  cd = stocPy.getCurDir(__file__)
  #stocPy.calcKSTests(cd + "/post" + no , [cd + "/runs" + no + term, cd + "/runs" + no + "Part10" +term, cd + "/runs" +  no + "PartU20" + term], names = ["Depth0", "Depth10", "Depth_U20"], burnIn=100, aggFreq=np.logspace(1,math.log(1000000,10),10), modelName="simplePoisson" + no)
  stocPy.calcKSSumms(cd + "/post" + no , [cd + "/runs" + no + term, cd + "/runs" + no + "Part10" + term, cd + "/runs" +  no + "SlicePart10" + term], names = ["Depth0", "Depth10", "SliceDepth10"], burnIn=0, aggFreq=np.logspace(1,math.log(1000000,10),10), modelName="simplePoisson" + no)
  #stocPy.calcKSSumms(cd + "/post" + no , [cd + "/runs" + no + term, cd + "/runs" + no + "Exp" + term, cd + "/runs" +  no + "PartU20" + term], names = ["AutoNames", "ExpNames", "Auto-U20"], burnIn=100, aggFreq=np.logspace(1,math.log(1000000,10),10), modelName="simplePoisson" + no)
Ejemplo n.º 8
0
  ax4, = plt.plot(ds, dr2, 'gd')
  ax5, = plt.plot(ds, dr3, 'm*')
  ax6, = plt.plot(ds, dr4, 'co')
  plt.xscale("log")
  plt.yscale("log")
  plt.legend([ax1,ax2,ax3,ax4,ax5,ax6],["Optimal Depth", "Depth 0", "Depth 5", "Depth 10", "Depth 20", "Depth = 2^1..2^6"], loc=3)
  plt.xlabel("PriorStd / PostStd")
  plt.ylabel("Movement / PostStd")
  plt.title("Expected movement for optimal depth and several fixed depths")
  plt.show()
  
if __name__ == "__main__":
  approxOptimalDepth(np.logspace(0,9,100))
  assert(False)
  global normalData
  normalData = loadData(stocPy.getCurDir(__file__) + "/normalData_2_001_1000")
  #genRuns(normal8, alg="sliceTD", noRuns = 5, time=10, fn="normal8SliceTimedSmall") 
  #genRuns(normal4, alg="met", noRuns = 10, time=6, fn="normal4MetTimed1Small") 
  #genRuns(normal4, alg="slice", noRuns = 10, time=6, fn="normal4SliceTimed1Small") 
  #genRuns(normal4, alg="sliceTD", noRuns = 10, time=6, fn="normal4SliceTDTimed1Small") 
  runKsRuns(8, paths=["normal8SliceTimedSmall", "normal8MetRuns","normal8Dec5MetRuns", "normal8Dec15MetRuns"], titles=["Slice", "Met", "Met_Part5", "Met_Part15"])
  assert(False)
  #getPost(9, -15, 15, 0.001, fn="normal9Post")
  #samples = stocPy.aggDecomp(stocPy.getTimedSamples(normal9Dec5, 10, alg="met", thresh=0.1), func= lambda xs: 10000 * ss.norm.cdf(sum(xs)))

  #samples = stocPy.getTimedSamples(normal8Part, 5, alg="met", thresh=0.1)
  #print samples
  #samples = stocPy.aggDecomp(stocPy.getTimedSamples(normal9Dec15, 1, alg="met", thresh=0.1))
  #stocPy.plotSamples(samples)
  #print samples
  #stocPy.saveRun(samples, "normal8U20_600")