-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model in Wu et al unit test is inconsistent with model in Wu et al notebook #10
Comments
Thanks for the detailed breakdown and analysis.
This is where the work needs to happen. Bayesian MCA uses different conventions than regular FBA, and this pain point has affected the ability of @janisshin to operationalize Bayesian MCA, too. Recall that there are two different models: A cobra model, and a pymc model. The goal should be to take a cobra model as input and generate a pymc model that exactly reproduces the notebook results. If we can't do this for Wu, then we can't guarantee that it will work for more complex models. I am happy to help you revise the transformation of the cobra model into a pymc model so that it does reproduce the Wu et al results. |
If this is the input cobra model Then this should be the output pymc model: with pm.Model() as pymc_model:
# Initialize elasticities
Ex_t = pm.Deterministic('Ex', initialize_elasticity(N, 'ex', b=0.05, sigma=1, alpha=5))
Ey_t = pm.Deterministic('Ey', initialize_elasticity(-Ey.T, 'ey', b=0.05, sigma=1, alpha=5))
# sample prior
trace_prior = pm.sample_prior_predictive()
# Error priors.
v_err = pm.HalfNormal('v_error', sigma=0.05, initval=.1)
x_err = pm.HalfNormal('x_error', sigma=0.05, initval=.1)
# Calculate steady-state concentrations and fluxes from elasticities
chi_ss, v_hat_ss = ll.steady_state_pytensor(Ex_t, Ey_t, en, yn)
# Error distributions for observed steady-state concentrations and fluxes
chi_obs = pm.Normal('chi_obs', mu=chi_ss, sigma=x_err, observed=xn)
v_hat_obs = pm.Normal('v_hat_obs', mu=v_hat_ss[:, 0].squeeze(),
sigma=v_err, observed=vn.squeeze())
# perform HMC to compute posterior
trace = pm.sample(500, random_seed=123, tune=1000,step=pm.NUTS(), n_init=1000, nuts_sampler_kwargs=dict(njobs=4))
# sample posterior
ppc = pm.sample_posterior_predictive(trace) Where
are identical to the Wu et al notebook. |
So the major problem we need to address here is that our design goal is to try and generalize the workflow of building the import emll
Ex = emll.create_elasticity_matrix(model)
Ey = np.zeros((3, 2))
Ey[0, 0] = 1 # bpg (+) PGM
Ey[2, 1] = 1 # adp (+) PK
ll = emll.LinLogSymbolic2x2(N, Ex, Ey, v_star) This is a specific behavior only for the Also this implementation uses a manually defined external elasticity matrix So we diverge in a few areas:
Thoughts after writing all this:I think we'd just need to step back and look at it again. We could pre-define |
Hey @mcnaughtonadm I agree that the Wu model contains lots of corner cases, so perhaps from a strategic perspective, it would make sense to punt on Wu for the time being, and focus on more typical workflows such as Contador or Hackett or A. niger so that at least you have one or two examples working end-to-end. We can always return to Wu later once the pipeline has been hardened so that there are fewer moving parts to deal with and we can just focus on what is different between Wu and the typical use case. |
In fact, maybe A. niger would be the best one to work on, since it works in our hands, it has been experimentally validated, and is an example of a "typical" workflow that we would expect to get. |
@djinnome and @mcnaughtonadm: please see the latest notebook file that I just pushed to the I left in the original code snippets as commented lines where they were relevant. Some of the notebook cell ordering has change slightly as we were exploring things. (Cells 3 and 4 for the cobra model; cell 8 for the elasticity matrices; cell 10 for the Giersch data loading, though the new code here is commented) Short version of findings: Longer version, including recapitulation of the discussion so far:
|
Hi @djinnome ,
@mcnaughtonadm and @ShantMahserejian met today to work on the BMCA code. Here’s an update of the current status/issue, possible ways forward, and what we will try as an immediate next step:
The model in the Wu notebook updated to be operation in the test code:
model.optimize()
, which is needed to calculate fluxes* Different
* Different
* Different LinLog model/method needed (vs. original Wu notebook)
* Specifically, stuck on calculating steady state terms:
Possible alternative approaches:
*
Suggest next step – Option 2: Make up numbers
* We’ve already got a working model for this, so easier step to check if final results agree with original Wu notebook
* Would be more appropriate rather than changing lines of code impacting the approach
* Challenge: Unsure of best values to use to augment Gierch data (what values do we use for exchange/sink reactions?)
We’d be happy to chat about this before the weekly PPI meeting if available. We’ll try to keep making progress with the suggest next step to get functional code, and we can revisit how we change the Giersch data after the fact.
The text was updated successfully, but these errors were encountered: