コード例 #1
0
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()
コード例 #2
0
#time()
#s1.sample(iters, temperature)
#time()

#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()
#######################################