17.1.1.6.1.1. cobra.sampling.achr
¶
Provide the ACHR sampler class.
17.1.1.6.1.1.1. Module Contents¶
17.1.1.6.1.1.1.1. Classes¶
Artificial Centering HitandRun sampler. 

class
cobra.sampling.achr.
ACHRSampler
(model: Model, thinning: int = 100, nproj: Optional[int] = None, seed: Optional[int] = None, **kwargs)[source]¶ Bases:
cobra.sampling.hr_sampler.HRSampler
Artificial Centering HitandRun sampler.
A sampler with low memory footprint and good convergence.
 Parameters
model (cobra.Model) – The cobra model from which to generate samples.
thinning (int, optional) – The thinning factor of the generated sampling chain. A thinning of 10 means samples are returned every 10 steps (default 100).
nproj (int > 0, optional) – How often to reproject the sampling point into the feasibility space. Avoids numerical issues at the cost of lower sampling. If you observe many equality constraint violations with sampler.validate you should lower this number (default None).
seed (int > 0, optional) – Sets the random number seed. Initialized to the current time stamp if None (default None).

problem
¶ A NamedTuple whose attributes define the entire sampling problem in matrix form.
 Type

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

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

fwd_idx
¶ A numpy array having one entry for each reaction in the model, containing the index of the respective forward variable.
 Type
numpy.array

rev_idx
¶ A numpy array having one entry for each reaction in the model, containing the index of the respective reverse variable.
 Type
numpy.array

prev
¶ The current/last flux sample generated.
 Type
numpy.array

center
¶ The center of the sampling space as estimated by the mean of all previously generated samples.
 Type
numpy.array
Notes
ACHR generates samples by choosing new directions from the sampling space’s center and the warmup points. The implementation used here is the same as in the MATLAB COBRA Toolbox 2 and uses only the initial warmup points to generate new directions and not any other previous iterations. 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 quasiMarkovian since the center converges rapidly.
Memory usage is roughly in the order of (2 * number of reactions) ^ 2 due to the required nullspace matrices and warmup points. So, large models easily take up a few GBs of RAM.
References
 1
Direction Choice for Accelerated Convergence in HitandRun Sampling David E. Kaufman, Robert L. Smith Operations Research 199846:1 , 8495 https://doi.org/10.1287/opre.46.1.84
 2

sample
(self, n: int, fluxes: bool = True) → pd.DataFrame[source]¶ Generate a set of samples.
This is the basic sampling function for all hitandrun samplers.
 Parameters
n (int) – The number of samples that are generated at once.
fluxes (bool, optional) – Whether to return fluxes or the internal solver variables. If set to False, will return a variable for each forward and backward flux as well as all additional variables you might have defined in the model (default True).
 Returns
Returns a pandas DataFrame with n rows, each containing a flux sample.
 Return type
pandas.DataFrame
Notes
Performance of this function linearly depends on the number of reactions in your model and the thinning factor.