Open djinnome opened 5 years ago
It's got to be in here somewhere :)
My guess is that sample_prior_predictive expects 1d variables somewhere, but the e
matrix is built up out of 0d Uniform distributions? It's tough to say.
You could try the quick hack (note the shape=(1,)
kwargs)
e_measured = theano.shared( np.ones( enzyme_measurements.shape ) )
for i, strain in enumerate(enzyme_measurements.index):
for j, enzyme in enumerate(enzyme_measurements.columns):
if enzyme_measurements.loc[reference_state, enzyme] == 1 and enzyme_measurements.loc[strain,enzyme] != 1:
e_measured = T.set_subtensor( e_measured[i,j],
pm.Uniform( 'e_{}_{}'.format( strain, enzyme ),
lower = 0, upper=1, shape=(1,)) )
elif enzyme_measurements.loc[reference_state,enzyme] != 1 and enzyme_measurements.loc[strain, enzyme] == 1:
e_measured = T.set_subtensor( e_measured[i,j],
pm.Uniform( 'e_{}_{}'.format( strain, enzyme ),
lower = 1, upper=10, shape=(1,)) )
e_unmeasured = T.ones((n_exp, len(e_unmeasured_inds)))
e_uncatalyzed = T.ones((n_exp, len(e_uncatalyzed_inds)))
en_t = T.concatenate(
[e_measured, e_unmeasured,
e_uncatalyzed], axis=1)[:, e_indexer]
pm.Deterministic('en_t', en_t)
the e
matrix is supposed to be (n_exp, nr)
in shape. (number of experiments by number of reactions). Did you try a closer version to my contador example?
I would do something like this:
e_hat = T.ones((n_exp, nr))
e_hat_overexpressed = pm.Uniform('e_hat_entries', lower=0, upper=1, shape=(num_overexpressed_enzymes,))
e_hat_underexpressed = pm.Uniform('e_hat_entries', lower=1, upper=10, shape=(num_underexpressed_enzymes,))
for i, strain in enumerate(enzyme_measurements.index):
for j, enzyme in enumerate(enzyme_measurements.columns):
if enzyme_measurements.loc[reference_state, enzyme] == 1 and enzyme_measurements.loc[strain,enzyme] != 1:
T.set_subtensor( e_hat[i,j], e_hat_underexpressed[j] )
elif enzyme_measurements.loc[reference_state,enzyme] != 1 and enzyme_measurements.loc[strain, enzyme] == 1:
T.set_subtensor( e_hat[i,j], e_hat_overexpressed[j] )
# Store the fitted e_hat in the trace object
e_hat = pm.Deterministic('e_hat', e_hat)
(this code probably isn't correct, but hopefully is close enough to convey the idea) this would then assume that enzymes overexpressed relative to WT are overexpressed by a constant amount in all the strains, which is fewer degrees of freedom. You could certainly add those back in if you needed too, but I'd start with the more constrained example.
The main difference would be specifying all the Uniforms
in a single vector, rather than initializing them separately.
Actually, the problem appeared to be that I had not set the Ey matrix correctly. I still have some semantic confusion about which reactions/metabolites belong in Ex and which belong in Ey, which don't belong in either. Is there an intuitive explanation you can provide to guide my modeling decisions?
So all reactions have to "be" in both: Ex is (nxm) (where n is number of reactions, m is number of internal metabolites) and Ey is (nxp) (where p is number of external metabolites).
But then it comes down to whether a metabolite is "internal" or "external". These distinctions are similar to the ones from MCA, but it comes down to whether metabolite concentrations are something that can be independently controlled (i.e., media concentrations) or something that's the result of steady-state fluxes and rate rules. They're essentially the boundary conditions for the overall pathway.
The Ey matrix (and external metabolites) gives you a way to change flux through the model without changes in enzyme expression. But if the media is consistent across all the experiments, you don't really need to include external metabolites, since they'll just be zero (log y/y*) for all conditions.
Hey Peter,
So I got the small model working with your help, thank you so much! Now I am working on glycolysis-TCA-itaconate model, and everything runs just fine: with ADVI, I get a nice ELBO,
the parity between predicted and measured fluxes and enzymes is tight, sample_posterior_predictive generates reasonable-looking FCC's, but I can't get
pm.sample_prior_predictive()
to run.The error message is:
This is my model:
And this is the full stacktrace:
Any suggestions as to what I might be doing wrong?