Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with pm.Model() as model_context:
- print "Setting hyper priors..."
- H1_mu = pm.Normal('h1_mu', numpy.array([100, 1]), numpy.array([1.0/1000, 1.0/1000]), shape=2)
- H1_precision = pm.Gamma('h1_precision', numpy.array([0.1, 0.1]), numpy.array([0.1, 0.1]), shape=2)
- H1_alpha = pm.Gamma('h1_a', numpy.array([0.1, 0.1]), numpy.array([0.1, 0.1]), shape=2)
- H1_beta = pm.Gamma('h1_b', numpy.array([0.1, 0.1]), numpy.array([0.1, 0.1]), shape=2)
- w1 = pm.Beta('w1', 15, 85)
- print "Setting priors and likelihood..."
- Z = numpy.empty(nGenes, dtype=object)
- MU = numpy.empty(nGenes, dtype=object)
- ALPHA = numpy.empty(nGenes, dtype=object)
- for i,gene in enumerate(fullG):
- Z[i] = pm.Categorical('Z_%d' % i, tt.stack([1.0-w1,w1]))
- MU[i] = pm.Normal('mu_%d' % i, H1_mu[Z[i]], H1_precision[Z[i]])
- ALPHA[i] = pm.Gamma('alpha_%d' % i, alpha=H1_alpha[Z[i]], beta=H1_beta[Z[i]])
- COUNTS[i] = pm.NegativeBinomial('counts_%d' % i, mu=MU[i], alpha=ALPHA[i], observed=gene.reads.flatten())
- ### ABOVE IS SLOW
- ### BELOW IS EVEN SLOWER ###
- print "Performing sampling..."
- with model_context:
- #start = pm.find_MAP()
- #step1 = pm.Metropolis(vars=[COUNTS, MU, ALPHA, H1_mu, H1_precision, H1_alpha, H1_beta, w1])
- #step2 = pm.ElemwiseCategoricalStep(Z, np.arange(2))
- db = Text('%s_negbinom_pymc3.trace' % label)
- trace = pm.sample(SAMPLES, njobs=2, random_seed=123, trace=db)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement