Esempio n. 1
0
    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.
"""


MRCE_obj = Hybrid_FSP_solver(Viral_D_model,stoc_vector,"MRCE",1e-7,jac=Jac_Mat)
MRCE_obj.set_initial_values(OFSP_obj.domain_states,OFSP_obj.p,t=0.005)
Esempio n. 2
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()


Esempio n. 3
0
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]
    #X[:,1] = [7,2,1]

    X = np.zeros((5, 2))
    X[:, 0] = [48, 2, 0, 80, 0]
    X[:, 1] = [47, 2, 1, 80, 0]
    #X[:,2] = [48,1,0,79,1]

    OFSP_catalytic.probe_states(X)
elapsed_time = time.time() - start_time
print "Time elapsed:" + ' ' + str(elapsed_time) + ' ' + "seconds"
OFSP_catalytic.plot()
#OFSP_catalytic.plot_contour()
OFSP_catalytic.plot_checked()
np.savetxt('ISPData_CatalyticOFSP.csv',
           np.column_stack(output_data),
           delimiter=',')
Esempio n. 4
0
### 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):
	return np.array([0.0,0.0,0.0,0.0])
def jac_2(x):
	return np.multiply(np.array([0.0,0.0,0.0,0.001*x[0]]),x)
def jac_3(x):
	return np.multiply(np.array([0.0,0.0,0.05,0.0]),x)
Esempio n. 5
0
File: SIR.py Progetto: oaarscorp/CME
		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

	def __init__(self,model,stoc_vector,model_name,sink_error,jac=None): 
Esempio n. 6
0

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]
    X[:,1] = [48,19,1,1,10,0]

    OFSP_dual_enzy_model.probe_states(X)
elapsed_time = time.time() - start_time
print "Time elapsed:" +' '+ str( elapsed_time) +' '+ "seconds"
OFSP_dual_enzy_model.plot()
#OFSP_dual_enzy_model.plot_contour()
OFSP_dual_enzy_model.plot_checked()
np.savetxt('OFSPData_dual_enzyOFSP.csv', np.column_stack(output_data), delimiter=',')
Esempio n. 7
0
# 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.

	""" Runtime plotting"""
	#OFSP_ABC.plot(inter=True)  # For interactive plotting

	""" Check Point"""
	OFSP_ABC.check_point()

	""" Probing """
	X = np.zeros((3,2))
	X[:,0] = [8,2,0]
	X[:,1] = [7,2,1]
	OFSP_ABC.probe_states(X)


OFSP_ABC.plot()
OFSP_ABC.plot_checked()