示例#1
0
def main():
    initial_copies = 20

    m = model.create(propensities=[lambda x: initial_copies - x],
                     transitions=[(1, )],
                     shape=(initial_copies + 1, ),
                     initial_state=(0, ))

    s = solver.create(model=m, sink=False)

    r = recorder.create((('A->B', ), ))

    time_steps = numpy.linspace(0.0, 3.0, 6)
    for t in time_steps:
        s.step(t)
        r.write(t, s.y)

    pylab.figure()
    for t, d in zip(r['A->B'].times, r['A->B'].distributions):
        marginal = d.to_dense(m.shape)
        pylab.plot(marginal, label='t = %.1f' % t)
    pylab.xlabel('Reaction count')
    pylab.ylabel('Probability')
    pylab.legend()
    pylab.savefig('simple_plot.png')
示例#2
0
文件: simple.py 项目: fcostin/cmepy
def main():
    initial_copies = 20
    
    m = model.create(
        propensities = [lambda x: initial_copies - x],
        transitions = [(1, )],
        shape = (initial_copies + 1, ),
        initial_state = (0, )
    )
    
    s = solver.create(
        model = m,
        sink = False
    )
    
    r = recorder.create(
        (('A->B', ), )
    )
    
    time_steps = numpy.linspace(0.0, 3.0, 6)
    for t in time_steps:
        s.step(t)
        r.write(t, s.y)
    
    pylab.figure()
    for t, d in zip(r['A->B'].times, r['A->B'].distributions):
        marginal = d.to_dense(m.shape)
        pylab.plot(marginal, label = 't = %.1f' % t)
    pylab.xlabel('Reaction count')
    pylab.ylabel('Probability')
    pylab.legend()
    pylab.savefig('simple_plot.png')
示例#3
0
def main():
    """
    the complete example from the slides
    """
    
    import numpy
    from cmepy import solver, recorder, model
    from cmepy.util import non_neg

    s_0 = 50
    e_0 = 10

    s = lambda *x : x[0]
    e = lambda *x : non_neg(e_0 - x[1])
    c = lambda *x : x[1]
    p = lambda *x : non_neg(s_0 - x[0] - x[1])

    m = model.create(
        species_counts = (s, e, c, p, ),
        propensities = (
            lambda *x : 0.01*s(*x)*e(*x),
            lambda *x : 35.0*c(*x),
            lambda *x : 30.0*c(*x),
        ),
        transitions = (
            (-1, 1),
            (1, -1),
            (0, -1)
        ),
        shape = (s_0 + 1, min(s_0, e_0) + 1),
        initial_state = (s_0, 0)
    )

    enzyme_solver = solver.create(
        model = m,
        sink = False
    )

    time_steps = numpy.linspace(0.0, 10.0, 101)

    r = recorder.create(
        (['S', 'E', 'C', 'P'], m.species_counts)
    )

    for t in time_steps:
        enzyme_solver.step(t)
        r.write(t, enzyme_solver.y)   

    recorder.display_plots(r)
示例#4
0
def main():
    """
    Solves the competing clonotypes model and plots results
    """
    
    import pylab
    
    from cmepy import solver, recorder
    
    m = create_model()
    
    s = solver.create(
        model = m,
        sink = True,
        time_dependencies = create_time_dependencies()
    )
    
    r = recorder.create(
        (m.species, m.species_counts)
    )
    
    t_final = 15.0
    steps_per_time = 1
    time_steps = numpy.linspace(0.0, t_final, int(steps_per_time*t_final) + 1)
    
    for t in time_steps:
        s.step(t)
        p, p_sink = s.y
        print 't : %.2f, truncation error : %.2g' % (t, p_sink)
        r.write(t, p)
    
    # display a series of contour plots of P(A, B; t) for varying t
    
    measurement = r[('A', 'B')]
    epsilon = 1.0e-5
    for t, marginal in zip(measurement.times, measurement.distributions):
        pylab.figure()
        pylab.contourf(
            marginal.compress(epsilon).to_dense(m.shape)
        )
        pylab.title('P(A, B; t = %.f)' % t)
        pylab.ylabel('species A count')
        pylab.xlabel('species B count')
    pylab.show()
def main():
    
    import numpy
    from cmepy import solver, recorder, model
    from cmepy.util import non_neg

    s_0 = 50
    e_0 = 10

    s = lambda *x : x[0]
    e = lambda *x : non_neg(e_0 - x[1])
    c = lambda *x : x[1]
    p = lambda *x : non_neg(s_0 - x[0] - x[1])

    m = model.create(
        species_counts = (s, e, c, p, ),
        propensities = (
            lambda *x : 0.01*s(*x)*e(*x),
            lambda *x : 35.0*c(*x),
            lambda *x : 30.0*c(*x),
        ),
        transitions = (
            (-1, 1),
            (1, -1),
            (0, -1)
        ),
        shape = (s_0 + 1, min(s_0, e_0) + 1),
        initial_state = (s_0, 0)
    )

    enzyme_solver = solver.create(
        model = m,
        sink = False
    )

    time_steps = numpy.linspace(0.0, 30.0, 101)
    
    species = ['S', 'E', 'C', 'P']
    
    r = recorder.create(
        (species, m.species_counts)
    )

    for t in time_steps:
        enzyme_solver.step(t)
        r.write(t, enzyme_solver.y)

    import pylab
    
    species_colours = {
        'S' : 'r',
        'E' : 'k',
        'C' : 'g',
        'P' : 'b',
    }
    
    pylab.figure()
    for var in species:
        colour = species_colours[var]
        measurement = r[var]
        mu = numpy.reshape(numpy.array(measurement.expected_value), (-1, ))
        sigma = numpy.array(measurement.standard_deviation)
        
        mu_style = '-'+colour
        mu_pm_sigma_style = '--'+colour
        pylab.plot(measurement.times, mu, mu_style, label = var)
        pylab.plot(measurement.times, mu + sigma, mu_pm_sigma_style)
        pylab.plot(measurement.times, mu - sigma, mu_pm_sigma_style)
    
    title_lines = (
        'Enzymatic Reaction Species Counts:',
        'expected values $\pm$ 1 standard deviation',
    )
    pylab.title('\n'.join(title_lines))
    pylab.xlabel('time')
    pylab.ylabel('species count')
    pylab.legend()
    pylab.show()