Пример #1
0
# *> S_1
r3 = lambda *x : c_3
v3 = (1,0)

# * -> S_2
r4 = lambda *x : c_4
v4 = (0,1)

#S_1 + S_2 -> S_1 + S_1
r5 = lambda *x : c_5*x[0]*x[1]
v5 = (1,-1)

Zombie_model = Model( propensities = [r1,r2,r4,r5],
						transitions = [v1,v2,v4,v5],
						species = ("S_1 = Zombies","S_2 = People"),
						initial_state = (1,30)
	)

## We run a small OFSP to make the state space more regular.

from pyme.OFSP import OFSP_Solver

Zombie_OFSP = OFSP_Solver(Zombie_model,10,1e-6)

Zombie_OFSP.step(0.1)

Zombie_OFSP.plot()


Пример #2
0
                        transitions=[v_1, v_2, v_3],
                        initial_state=x_0,
                        species=species_names)

#print(catalytic_model.propensities)
print(catalytic_model.transitions)
print(catalytic_model.initial_state)
print(catalytic_model.species)

# inside a propensity
print(catalytic_model.propensities[0](*catalytic_model.initial_state))

from pyme.OFSP import OFSP_Solver
# OFSP
start_time = time.time()
OFSP_catalytic = OFSP_Solver(catalytic_model, 10, 1e-6)

T = np.arange(0.0, 0.5, 0.01)

output_data = []
for isp_position in T:
    OFSP_catalytic.step(isp_position)
    OFSP_catalytic.print_stats  # Prints some information of where the solver is.
    output_data.append(OFSP_catalytic.print_stats)
    """ Runtime plotting"""
    #OFSP_ABC.plot(inter=True)  # For interactive plotting
    """ Check Point"""
    OFSP_catalytic.check_point()
    """ Probing """
    #X = np.zeros((3,2))
    #X[:,0] = [8,2,0]
Пример #3
0
	return np.array([0.0,0.0,2.0*x[2],0.0])
def jac_6(x):
	return np.array([0.0,7.5e-6*x[1]*x[2],7.5e-6*x[1]*x[2],0.0])

def Jac_Mat(X,deter_vec,i):
    jac_list = [jac_0,jac_1,jac_0,jac_0,jac_5,jac_6]
    mat = np.array(map(jac_list[i],X.T)).T
    return mat[deter_vec,:]

delta_t = 0.1
T = np.arange(0.005,20.0,delta_t)

### Using the OFSP to generate a regular initial condition.
from pyme.OFSP import OFSP_Solver

OFSP_obj = OFSP_Solver(Viral_D_model,2,1e-6,expander_name="SE1")
for i in range(10):
	OFSP_obj.step(0.0005*(i+1))
	OFSP_obj.print_stats

OFSP_obj.plot()

####### Hybrid Solver Class ########

from pyme.Hybrid_FSP import Hybrid_FSP_solver

### Hybrid MRCE Computation
stoc_vector = np.array([True,False,False,True])
"""
Templetes and Virons are stochastic.
Genome and Structures are modelled by conditional / marginal expectations.
Пример #4
0
delta_t = 1.0
T = np.arange(1.0,80,delta_t)


### OFSP Approximation
from pyme.OFSP import OFSP_Solver

# This stops the system from growing into areas which have zero probability.
def validity_function(X):
	on_off = X[0,:] < 2
	neg_states = np.logical_and.reduce(X >= 0, axis=0)
	return np.multiply(on_off,neg_states)


OFSP_obj = OFSP_Solver(sRNA_model,5,1e-6,expander_name="SE1",validity_test=validity_function)


for t in T:
	OFSP_obj.step(t)
	OFSP_obj.plot(inter=True)			# Interactive mode graphs the marginal each time called.
	OFSP_obj.print_stats

### Hybrid FSP Approximation

"""
The Jacobian of the propensities needed for the higher moments
nabla(propensity func(state)) * state 
"""

def jac_0(x):
Пример #5
0
		OFSP solver for solving the CME for a given model over time.

		Parameters
		------------------------
		model 			: CMEPY Model Class
		compress_window : int , 
							number of steps before compressing the domain.
		step_error		: float, 
							global error allowed in the sink state per step.
		expander_name 	: str , 
							"SE1" Simple N-step expander.
		validity_test	: func , 
							Validity function is by default looking for non negative states
"""

OFSP_obj = OFSP_Solver(SIR_model, 50, 1e-6, expander_name="SE1")

for t in T:
    OFSP_obj.step(t)
    OFSP_obj.plot(
        inter=True)  # Interactive mode graphs the marginal each time called.
    OFSP_obj.print_stats
    OFSP_obj.check_point()
    X = np.array([[150, 180], [50, 20]
                  ])  # We can probe various states for their probabilities.
    OFSP_obj.probe_states(
        X)  # Probes and stores the states of the respective time step.

OFSP_obj.plot_checked()

from pyme.Hybrid_FSP import Hybrid_FSP_solver
Пример #6
0
# starting state  (S, E1, C1,  P, E2, C2)
x_0 = (50, 20, 0,  0, 10, 0) # initial populations of the six species.

species_names = ('S','E1','C1','P','E2','C2')

dual_enzy_model = Model(propensities = [reaction_1,reaction_2,reaction_3,reaction_4,reaction_5,reaction_6], transitions = [v_1,v_2,v_3,v_4,v_5,v_6], initial_state = x_0, species = species_names)
#print(dual_enzy_model.propensities)
print(dual_enzy_model.transitions)
print(dual_enzy_model.initial_state)
print(dual_enzy_model.species)


from pyme.OFSP import OFSP_Solver
# OFSP
start_time = time.time()
OFSP_dual_enzy_model = OFSP_Solver(dual_enzy_model,1,1e-6)

T = np.arange(0.0,2.0,0.01)

output_data = []
for isp_position in T:
    OFSP_dual_enzy_model.step(isp_position)
    OFSP_dual_enzy_model.print_stats
    output_data.append(OFSP_dual_enzy_model.print_stats)

    """ Check Point"""
    OFSP_dual_enzy_model.check_point()

    """ Probing """
    X = np.zeros((6,2))
    X[:,0] = [48,18,2,0,10,0]
Пример #7
0
		OFSP solver for solving the CME for a given model over time.

		Parameters
		------------------------
		model 			: CMEPY Model Class
		compress_window : int , 
							number of steps before compressing the domain.
		step_error		: float, 
							global error allowed in the sink state per step.
		expander_name 	: str , 
							"SE1" Simple N-step expander.
		validity_test	: func , 
							Validity function is by default looking for non negative states
"""

OFSP_obj = OFSP_Solver(SIR_model,50,1e-6,expander_name="SE1")

for t in T:
	OFSP_obj.step(t)
	OFSP_obj.plot(inter=True)			# Interactive mode graphs the marginal each time called.
	OFSP_obj.print_stats
	OFSP_obj.check_point()
	X = np.array([[150,180],[50,20]])	# We can probe various states for their probabilities.
	OFSP_obj.probe_states(X)			# Probes and stores the states of the respective time step.

OFSP_obj.plot_checked()


from pyme.Hybrid_FSP import Hybrid_FSP_solver
"""
Initialising a Hybrid solver class. Where we want to consider S to be stochastic and I to be deterministic
Пример #8
0
"""
First OFSP solver using the ABC model. 
Code for the tutorial http://github.com/vikramsunkara/PyME/wiki/OFSP-Solver-Tutorial
"""

import numpy as np

# Importing the model class
from ABC_model import ABC_model

# calling the class
from pyme.OFSP import OFSP_Solver

# OFSP solver for the ABC model
OFSP_ABC = OFSP_Solver(ABC_model,10,1e-6)

# Example with Validity function
"""
def validity_func(X):
  return np.sum(np.abs(X),axis=0) == 10 # since we started with 10 states.
# The solver initialisation would look like

OFSP_ABC = OFSP_Solver(ABC_model,10,1e-6,validity_test = validity_func)

"""


T = np.arange(0.01,1.0,0.01)
for t in T:
	OFSP_ABC.step(t)
	OFSP_ABC.print_stats 		# Prints some information of where the solver is.