From bd0ccaeb0e3b93c02ad7b164f8c3014ca1367d5d Mon Sep 17 00:00:00 2001 From: Peter Schubert <Peter.Schubert@hhu.de> Date: Wed, 14 Sep 2022 12:00:54 +0200 Subject: [PATCH] in GBA_problem - density constraint with scaled density --- xbanalysis/problems/gba_problem.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xbanalysis/problems/gba_problem.py b/xbanalysis/problems/gba_problem.py index acafcc8..dee8097 100644 --- a/xbanalysis/problems/gba_problem.py +++ b/xbanalysis/problems/gba_problem.py @@ -26,6 +26,7 @@ def cache_last(func): # TODO: call get_reaction_rates from solver ? # TODO: split get_reaction_rates, get_reaction_jacs, get_reaction_hesses +# TODO: variable transformation x = exp(y) and solve for unbounded y. start with vector y = log(x) class GbaProblem: @@ -40,7 +41,9 @@ class GbaProblem: :type xba_model: XbaModel """ self.xba_model = xba_model - # self.cache = True + + # check to scale density constraint to improve convergence + self.scale_density = 1e-4 # metabolites and enzymes in the model metab_sids = [s.id for s in xba_model.species.values() if s.sboterm.is_in_branch('SBO:0000247')] @@ -713,7 +716,7 @@ class GbaProblem: density = self.model_params['mws'][self.var_mask_enz].dot(ce) else: density = self.model_params['mws'].dot(x) - return np.array([self.model_params['rho'] - density]) + return np.array([self.model_params['rho'] - density]) * self.scale_density @cache_last def heq_density_jac(self, x): @@ -733,7 +736,7 @@ class GbaProblem: density_grad[self.var_mask_enz] = -self.model_params['mws'][self.var_mask_enz] else: density_grad = -self.model_params['mws'] - return density_grad + return density_grad * self.scale_density # noinspection PyUnusedLocal @cache_last @@ -746,4 +749,4 @@ class GbaProblem: :rtype: numpy.ndarray (3D), shape [1,x,x] """ hess = np.zeros((1, self.n_vars, self.n_vars)) - return np.tril(hess) + return np.tril(hess) * self.scale_density -- GitLab