-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
I'm running the script below with 2,000 samples. It's surprisingly slow, a bit under 9s / sample under Python 2.7.11 :: Anaconda custom (x86_64) on a Mid-2015 MacBook Pro with 2.5GHz CPUs (four of them, but the sampler seems to be single-threaded.) I'd be grateful for any suggestions about how to speed it up.
from pymc3 import Model, Normal, Gamma, Lognormal, Exponential, NUTS, sample, find_MAP, traceplot
from load_table import walltime, numsims, numconstraints, numtargets
def LogNormalInvGamma(mu, alpha, beta, n, name):
tau = Gamma('tau_' + name, alpha=alpha, beta=beta)
mu = Normal('mu_' + name, mu=mu, tau=(n * tau))
return Lognormal(name, mu=mu, tau=tau)
model = Model()
with model:
# Equation (3) in the doc string. But remember, comments go stale!
C_1 = LogNormalInvGamma(mu=0, alpha=1, beta=1,
n=Exponential('C_1_DOF', 1),
name='constraints')
# Equation (4)
C_2 = LogNormalInvGamma(mu=0, alpha=1, beta=1,
n=Exponential('C_2_DOF', 1),
name='targets')
# Now we model C_0 as the Lognormal which varies around the rest of
# Equation (1) / Equation (5)
C_0_mu = (C_1 * numconstraints) + (C_2 * numsims * numtargets)
walltime_model = Lognormal('walltime',
mu=C_0_mu,
tau=Gamma('tau_const', 1, 1), # 𝞽₀ in Equ (2)
observed=walltime)
# The section below is run in a separate module, which imports the model constructed above.
# Probably not relevant, but I don't really know why it's taking so long.
# Rough computation of MAP for the model.
map_estimate = find_MAP(model=model.model, fmin=optimize.fmin_powell)
# Draw 2,000 posterior samples
trace = sample(2000, start=map_estimate)