-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.py
executable file
·34 lines (27 loc) · 949 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from IPython import parallel
import numpy
import gess
rc = parallel.Client(packer='pickle') # for running on starcluster on
# EC2. This line may have to be
# modified when running on other
# clusters
dview = rc[:]
print "using " + str(len(rc.ids)) + " engines"
with dview.sync_imports():
import numpy
import os
working_dir = os.getcwd()
dview.execute("os.chdir('" + working_dir + "')")
dview.execute("os.environ['MKL_NUM_THREADS']='1'") # prevent numpy from multithreading
dim = 10
num_cores = len(rc.ids)
iters = 1000
burnin = 1000
thinning = 1
repeats = 100
chains = num_cores
# a simple pdf
def logf(x):
return -.5 * numpy.dot(x, x)
starts = numpy.random.normal(loc=numpy.zeros(dim), scale=1, size=(2*chains,dim))
samples, calls = gess.parallel_gess(chains, iters, burnin, thinning, starts, logf, repeats, dview)