示例#1
0
    def calculateInitialScore(self):
        with open('../../../sbml/b2.xml') as f:
            sbml = f.read()

        # show initial score
        from b2problem import B2Problem
        p = B2Problem(sbml)
        self.initial_score = p.evaluate(getDefaultParamValues())
        print('Initial score: {}'.format(self.initial_score))
示例#2
0
def run_island(i):
    class Problem:
        def __init__(self, evaluator, lb, ub):
            from .utils import expect, check_vector
            # type: (Evaluator, array, array) -> None
            '''
            Inits the problem with an objective evaluator
            (implementing the method evaluate), the parameter
            vector lower bound (a numpy array) and upper bound.
            Both bounds must have the same dimension.
            '''
            check_vector(lb)
            check_vector(ub)
            expect(len(lb) == len(ub), 'Bounds mismatch')
            self.evaluator = evaluator
            self.lb = lb
            self.ub = ub

        def fitness(self, x):
            return evaluator.evaluate(x)

        def get_bounds(self):
            return (lb,ub)

        def get_name(self):
            return 'Sabaody udp'

        def get_extra_info(self):
            return 'Sabaody extra info'

    import pygmo as pg
    from multiprocessing import cpu_count
    from b2problem import B2Problem
    from params import getDefaultParamValues, getLowerBound, getUpperBound
    from pymemcache.client.base import Client
    mc_client = Client((i.mc_host,i.mc_port))
    #udp = i.problem_factory()

    algorithm = pg.algorithm(pg.de())
    problem = pg.problem(Problem(B2Problem(i.problem_factory), getLowerBound(), getUpperBound()))
    # TODO: configure pop size
    #a = pg.archipelago(n=cpu_count,algo=algorithm, prob=problem, pop_size=100)

    mc_client.set(i.domain_qualifier('island', str(i.id), 'status'), 'Running', 10000)
    mc_client.set(i.domain_qualifier('island', str(i.id), 'n_cores'), str(cpu_count()), 10000)
    print('Starting island {} with {} cpus'.format(str(i.id), str(cpu_count())))

    #a.evolve(100)

    return 0
示例#3
0
 def __init__(self, lb, ub):
     # type: (Evaluator, array, array) -> None
     '''
     Inits the problem with an objective evaluator
     (implementing the method evaluate), the parameter
     vector lower bound (a numpy array) and upper bound.
     Both bounds must have the same dimension.
     '''
     from sabaody.utils import check_vector, expect
     check_vector(lb)
     check_vector(ub)
     expect(len(lb) == len(ub), 'Bounds mismatch')
     self.lb = lb
     self.ub = ub
     from b2problem import B2Problem
     self.evaluator = B2Problem('b2.xml')
示例#4
0
 def __setstate__(self, state):
     self.lb = state['lb']
     self.ub = state['ub']
     from b2problem import B2Problem
     self.evaluator = B2Problem('b2.xml')
示例#5
0
def get_fitness(x):
    from b2problem import B2Problem
    return (B2Problem('b2.xml').evaluate(x), )
示例#6
0
from __future__ import print_function, division, absolute_import

# run this in a notebook to plot

from b2problem import B2Problem
from params import getDefaultParamValues, getBestKnownValues

with open('../../../../../sbml/b2.xml') as f:
    sbml = f.read()
m = B2Problem(sbml)
print('obj value', m.evaluate(getBestKnownValues()))
for q in [
        'cpep', 'cg6p', 'cpyr', 'cf6p', 'cglcex', 'cg1p', 'cpg', 'cfdp', 'cgap'
]:
    m.plotQuantity(q, param_values=getBestKnownValues())
    print('MSE for {}: {:.3}'.format(q, m.RMSE_quantity(q)))
示例#7
0
 def fitness(self, x):
     if self.evaluator is None:
         from b2problem import B2Problem
         self.evaluator = B2Problem(self.sbml_file)
     return (self.evaluator.evaluate(x),)