anna-pa-m / Metabolic-EP

Code and data for analysis of metabolic networks
Other
9 stars 3 forks source link

Sampling feasible flux vectors from metabolic-EP results #19

Closed Bastien-N closed 1 year ago

Bastien-N commented 2 years ago

Hello, I am wondering if there may be a way to sample flux vectors (such as would result from FBA) from the results of metabolic-EP sampling. Indeed your method is much faster than other sampling algorithms but having actual flux vector samples would be useful in some applications.

In the context of my project I am trying to correct sampling results for thermodynamically infeasible fluxes. Flux vectors can be fixed using the CycleFreeFlux method, while we so far could not find a way to prevent metabolic-EP sampling results from being affected by infeasible fluxes.

I would appreciate any insights on whether you believe this may be possible or if you would advise to use alternative sampling algorithms instead. Thank you in advance, Bastien

abraunst commented 2 years ago

Indeed it is in principle possible with ancestral sampling: you can sample $\nu^\star_1$ for the (truncated Gaussian) marginal distribution $p(\nu_1)$, then fix $\nu_1 = \nu_1^*$ (e.g. by shrinking the bounds or reducing the system), then recompute marginals, effectively computing $p(\nu_i | \nu_1=\nu^\star_1)$, sample $\nu_2^\star$ etc

Bastien-N commented 2 years ago

Thank you very much! I was not aware of this method but it seems to be exactly what we would need.

abraunst commented 2 years ago

No problem! Of course this adds a factor N (number of fluxes) to the whole process to produce each sample, I don't know if the resulting process will be too slow for your application.

Bastien-N commented 2 years ago

Indeed it may be fairly slow, I will have to do a benchmark against different sampling methods. It would still be useful where we already have EP sampling results. I also have a feeling that I may not need that many samples to, at least roughly, correct for fluxes in EP results.

Bastien-N commented 2 years ago

Sorry to bother you again, but I am having difficulties applying ancestral sampling in this case. Specifically I am unsure whether I can recompute the marginals in one go or if I need to essentially perform another round of EP.

What I have been doing was: -Start with mu,s,a,d,etc from a previous EP round -fix the flux through a reaction v1 by setting its lower and upper bounds to a value -calculate the means and variances of the tilted distribution based on mu,s, and the new bounds -recalculate the priors -update the mu and s of the posterior distributions

However, I found that I am getting somewhat different results from this than from running a fresh EP sampling with already fixed v1 bounds.

Is there a flaw in my approach? My understanding of bayesian statistics is somewhat limited and I have only seen examples of ancestral sampling in the case of simple bayesian networks of a handful of nodes.

abraunst commented 1 year ago

You do need an EP convergence at each step.

Bastien-N commented 1 year ago

Thank you for your help, as it turned out this approach turned out too complex and computationally intensive for our purpose.

Best wishes

abraunst commented 1 year ago

Yes I can see that, it's not really devised for sampling. Thanks for following up!