mass.thermo.conc_sampling.conc_achr

Provides concentration sampling through an ACHR sampler.

Based on sampling implementations in cobra.sampling.achr

Module Contents

Classes

ConcACHRSampler

Artificial Centering Hit-and-Run sampler for concentration sampling.

class mass.thermo.conc_sampling.conc_achr.ConcACHRSampler(concentration_solver, thinning=100, nproj=None, seed=None)[source]

Bases: mass.thermo.conc_sampling.conc_hr_sampler.ConcHRSampler

Artificial Centering Hit-and-Run sampler for concentration sampling.

A sampler with low memory footprint and good convergence [KS98].

Notes

ACHR generates samples by choosing new directions from the sampling space’s center and the warmup points. The implementation used here is the similar as in the Python cobra package.

This implementation uses only the initial warmup points to generate new directions and not any other previous iterates. This usually gives better mixing since the startup points are chosen to span the space in a wide manner. This also makes the generated sampling chain quasi-markovian since the center converges rapidly.

Memory usage is roughly in the order of:

(number included reactions + number included metabolites)^2

due to the required nullspace matrices and warmup points. So large models easily take up a few GB of RAM.

Parameters
  • concentration_solver (ConcSolver) – The ConcSolver to use in generating samples.

  • thinning (int) – The thinning factor for the generated sampling chain as a positive int > 0. A thinning factor of 10 means samples are returned every 10 steps.

  • nproj (int or None) –

    A positive int > 0 indicating how often to reporject the sampling point into the feasibility space. Avoids numerical issues at the cost of lower sampling. If None then the value is determined via the following:

    nproj = int(min(len(self.concentration_solver.variables)**3, 1e6))
    

    Default is None

  • seed (int or None) –

    A positive int > 0 indiciating random number seed that should be used. If None provided, the current time stamp is used.

    Default is None.

concentration_solver

The ConcSolver used to generate samples.

Type

ConcSolver

feasibility_tol

The tolerance used for checking equalities feasibility.

Type

float

bounds_tol

The tolerance used for checking bounds feasibility.

Type

float

thinning

The currently used thinning factor.

Type

int

n_samples

The total number of samples that have been generated by this sampler instance.

Type

int

retries

The overall of sampling retries the sampler has observed. Larger values indicate numerical instabilities.

Type

int

problem

A namedtuple whose attributes define the entire sampling problem in matrix form. See docstring of Problem for more information.

Type

collections.namedtuple

warmup

A matrix of with as many columns as variables in the model of the ConcSolver and more than 3 rows containing a warmup sample in each row. None if no warmup points have been generated yet.

Type

numpy.matrix

nproj[source]

How often to reproject the sampling point into the feasibility space.

Type

int

sample(n, concs=True)[source]

Generate a set of samples.

This is the basic sampling function for all hit-and-run samplers.

Notes

Performance of this function linearly depends on the number of variables in the model of the ConcSolver and the thinning factor.

Parameters
  • n (int) – The number of samples that are generated at once.

  • concs (bool) – Whether to return concentrations or the internal solver variables. If False will return a variable for each metabolite and reaction equilibrium constant as well as all additional variables that may have been defined in the model of the ConcSolver.

Returns

A matrix with n rows, each containing a concentration sample.

Return type

numpy.matrix

__single_iteration()[source]

Perform a single iteration of sampling.

Warning

This method is intended for internal use only.