#s1.compute_means() #if 'WORKHASH' in os.environ: #r.lpush('jobs:done:' + jobhash, s1.read_db()) #s1.db.close() ############# bayesnetcpd ############ #import pstats, cProfile joint = utils.graph_to_joint(groundgraph) states = np.ones(len(joint.dists),dtype=np.int32)*2 groundbnet = BayesNetCPD(states, data) groundbnet.set_cpds(joint) obj = BayesNetCPD(states, data) b2 = BayesNetSampler(obj, template, groundbnet, priorweight) s2 = SAMCRun(b2,burn,stepscale,refden,thin) time() #cProfile.runctx("s2.sample(iters, temperature)", globals(), locals(), "prof.prof") s2.sample(iters, temperature) time() s2.compute_means() #s2.compute_means(cummeans=False) if 'WORKHASH' in os.environ: r.lpush('jobs:done:' + jobhash, s2.read_db()) s2.db.close() ####################################### ###
template = sampleTemplate(groundgraph, numtemplate) if 'WORKHASH' in os.environ: jobhash = os.environ['WORKHASH'] if not r.hexists('jobs:grounds', jobhash): r.hset('jobs:grounds', jobhash, zlib.compress(cPickle.dumps(groundgraph))) random.seed() np.random.seed() datasizes = [4, 16, 32, 64, 128, 256] temps = [1.0, 1.0, 2.0, 2.0, 5.0, 5.0] for temperature, numdata in zip(temps, datasizes): data = generateData(groundgraph, joint, numdata) groundbnet = BayesNetCPD(states, data, limparent=3) groundbnet.set_cpds(joint) obj = BayesNetCPD(states, data, limparent=3) b = BayesNetSampler(obj, template, groundbnet, priorweight) s = SAMCRun(b, burn, stepscale, refden, thin) s.sample(iters, temperature) s.compute_means() if 'WORKHASH' in os.environ: r.lpush('jobs:done:' + jobhash, s.read_db()) r.lpush('custom:%s:samplesize=%d' % (jobhash, numdata), s.db.root.computed.means._v_attrs['kld']) s.db.close()
burn = 1 stepscale=10 temperature = 1.0 thin = 1 refden = 0.0 random.seed(123456) np.random.seed(123456) groundgraph = generateTree(N, comps) data = generateData(groundgraph,numdata) #template = sampleTemplate(groundgraph, numtemplate) random.seed() np.random.seed() ground = TreeNet(N, graph=groundgraph) b = TreeNet(N, data=data, ground=ground) s = SAMCRun(b,burn,stepscale,refden,thin,verbose=True) s.sample(iters, temperature) s.compute_means() # All to exercise cde deps tmp = s.read_db() import cPickle txt = zlib.compress(cPickle.dumps([1,2,3])) if 'WORKHASH' in os.environ: r.lpush('jobs:done:'+os.environ['WORKHASH'], s.read_db())