def optgp(model): """Return OptGPSampler instance for tests.""" sampler = OptGPSampler(model, processes=1, thinning=1) assert ((sampler.n_warmup > 0) and (sampler.n_warmup <= 2 * len(model.variables))) assert all(sampler.validate(sampler.warmup) == "v") return sampler
def test_complicated_model(self): """Difficult model since the online mean calculation is numerically unstable so many samples weakly violate the equality constraints.""" model = Model('flux_split') reaction1 = Reaction('V1') reaction2 = Reaction('V2') reaction3 = Reaction('V3') reaction1.lower_bound = 0 reaction2.lower_bound = 0 reaction3.lower_bound = 0 reaction1.upper_bound = 6 reaction2.upper_bound = 8 reaction3.upper_bound = 10 A = Metabolite('A') reaction1.add_metabolites({A: -1}) reaction2.add_metabolites({A: -1}) reaction3.add_metabolites({A: 1}) model.add_reactions([reaction1]) model.add_reactions([reaction2]) model.add_reactions([reaction3]) optgp = OptGPSampler(model, 1, seed=42) achr = ACHRSampler(model, seed=42) optgp_samples = optgp.sample(100) achr_samples = achr.sample(100) assert any(optgp_samples.corr().abs() < 1.0) assert any(achr_samples.corr().abs() < 1.0) # > 95% are valid assert(sum(optgp.validate(optgp_samples) == "v") > 95) assert(sum(achr.validate(achr_samples) == "v") > 95)
def test_complicated_model(): """Test a complicated model. Difficult model since the online mean calculation is numerically unstable so many samples weakly violate the equality constraints. """ model = Model('flux_split') reaction1 = Reaction('V1') reaction2 = Reaction('V2') reaction3 = Reaction('V3') reaction1.bounds = (0, 6) reaction2.bounds = (0, 8) reaction3.bounds = (0, 10) A = Metabolite('A') reaction1.add_metabolites({A: -1}) reaction2.add_metabolites({A: -1}) reaction3.add_metabolites({A: 1}) model.add_reactions([reaction1, reaction2, reaction3]) optgp = OptGPSampler(model, 1, seed=42) achr = ACHRSampler(model, seed=42) optgp_samples = optgp.sample(100) achr_samples = achr.sample(100) assert any(optgp_samples.corr().abs() < 1.0) assert any(achr_samples.corr().abs() < 1.0) # > 95% are valid assert sum(optgp.validate(optgp_samples) == "v") > 95 assert sum(achr.validate(achr_samples) == "v") > 95
def test_complicated_model(self): """Difficult model since the online mean calculation is numerically unstable so many samples weakly violate the equality constraints.""" model = Model('flux_split') reaction1 = Reaction('V1') reaction2 = Reaction('V2') reaction3 = Reaction('V3') reaction1.lower_bound = 0 reaction2.lower_bound = 0 reaction3.lower_bound = 0 reaction1.upper_bound = 6 reaction2.upper_bound = 8 reaction3.upper_bound = 10 A = Metabolite('A') reaction1.add_metabolites({A: -1}) reaction2.add_metabolites({A: -1}) reaction3.add_metabolites({A: 1}) model.add_reactions([reaction1]) model.add_reactions([reaction2]) model.add_reactions([reaction3]) optgp = OptGPSampler(model, 1, seed=42) achr = ACHRSampler(model, seed=42) optgp_samples = optgp.sample(100) achr_samples = achr.sample(100) assert any(optgp_samples.corr().abs() < 1.0) assert any(achr_samples.corr().abs() < 1.0) # > 95% are valid assert (sum(optgp.validate(optgp_samples) == "v") > 95) assert (sum(achr.validate(achr_samples) == "v") > 95)
def getFluxSample(self, nsamples=5000): """ Generates a sample of the flux cone. It uses the default sampler in cobrapy """ optGPS = OptGPSampler(self.GEM, thinning=100, processes=3) samplerSample = optGPS.sample(nsamples) sample = samplerSample[optGPS.validate(samplerSample) == "v"] return sample
def setup_class(self): from . import create_test_model model = create_test_model("textbook") achr = ACHRSampler(model, thinning=1) assert ((achr.n_warmup > 0) and (achr.n_warmup <= 2 * len(model.variables))) assert all(achr.validate(achr.warmup) == "v") self.achr = achr optgp = OptGPSampler(model, processes=1, thinning=1) assert ((optgp.n_warmup > 0) and (optgp.n_warmup <= 2 * len(model.variables))) assert all(optgp.validate(optgp.warmup) == "v") self.optgp = optgp
def setup_class(self): from . import create_test_model model = create_test_model("textbook") arch = ARCHSampler(model, thinning=1) assert ((arch.n_warmup > 0) and (arch.n_warmup <= 2 * len(model.reactions))) assert all(arch.validate(arch.warmup) == "v") self.arch = arch optgp = OptGPSampler(model, processes=1, thinning=1) assert ((optgp.n_warmup > 0) and (optgp.n_warmup <= 2 * len(model.reactions))) assert all(optgp.validate(optgp.warmup) == "v") self.optgp = optgp