def solve_model(self, log10_theta, modelid): def fsp_constr(X, out): out[:, 0] = X[:, 0] out[:, 1] = X[:, 1] out[:, 2] = X[:, 2] out[:, 3] = X[:, 3] out[:, 4] = X[:, 3] theta = np.power(10.0, log10_theta) copymax = self.copymaxs[modelid] constr_init = np.array([2, 2, 2, 5, copymax]) propensity_t, propensity_x = self.propensity_factory(theta, modelid) fsp_solver = FspSolverMultiSinks(mpi.COMM_SELF) fsp_solver.SetModel(self.STOICH_MATRIX, propensity_t, propensity_x, [1]) fsp_solver.SetFspShape( constr_fun=fsp_constr, constr_bound=constr_init, exp_factors=np.array([0.0, 0.0, 0.0, 0.2, 0.0]), ) fsp_solver.SetInitialDist(self.X0, self.P0) fsp_solver.SetOdeSolver(self.ODE_METHOD) fsp_solver.SetOdeTolerances(1.0e-4, 1.0e-10) solutions = fsp_solver.SolveTspan(self.t_meas + theta[-1], 1.0e-8) return solutions
def loglike(self, log10_thetas, dataz, surrogate_id): thetas = np.power(10.0, log10_thetas) nsamp = thetas.shape[0] loglike_values = np.zeros((nsamp, 1)) data = dataz[surrogate_id] for jnc in range(0, nsamp): prop = self.prop_factory(thetas[jnc, :], surrogate_id) solver = FspSolverMultiSinks(mpi.COMM_SELF) solver.SetModel(self.stoich_mat, None, prop) solver.SetFspShape(None, self.constr_init) solver.SetInitialDist(self.x0, self.p0) solver.SetOdeSolver("KRYLOV") solver.SetKrylovOrthLength(2) solver.SetKrylovDimRange(30, 30) solutions = solver.SolveTspan(self.t_meas, 1.0e-8) ll = 0.0 for i in range(0, len(self.t_meas)): ll = ll + data[i].LogLikelihood( solutions[i], np.array([self.num_gene_states, self.num_gene_states + 1]), ) loglike_values[jnc, 0] = ll return loglike_values
out[:] = x[:,1] if reaction is 2: out[:] = x[:,1] if reaction is 3: out[:] = x[:,2] def t_fun(t, out): out[0] = 0.01 out[1] = 0.001 out[2] = 1 out[3] = 0.1 n_t = 100 tspan = np.linspace(0, 1000, n_t) solver = FspSolverMultiSinks(mpi.COMM_WORLD) solver.SetModel(stoich_mat, t_fun, propensity) solver.SetFspShape(None, constr_init) solver.SetInitialDist(x0, p0) solver.SetVerbosity(2) solver.SetUp() solutions = solver.SolveTspan(tspan, 1.0e-4) marginals = [] for i in range(0, 3): for j in range(0, n_t): marginals.append(solutions[j].Marginal(i)) def weightfun(x, fout):
out[:, 5] = np.multiply(X[:, 0], X[:, 2]) init_bounds = np.array([22, 2, 2, 44, 4, 44]) exp_factors = np.array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) rank = MPI.COMM_WORLD.rank x0 = np.array([[21, 0, 0]]) p0 = np.array([1.0]) sm = np.array([[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]]) tspan = np.linspace(0, 1, 2) # Create FSP solver object solver = FspSolverMultiSinks(MPI.COMM_WORLD) solver.SetModel(sm, None, propensity) solver.SetFspShape(constr_fun=rep_constr, constr_bound=init_bounds) solver.SetInitialDist(x0, p0) solver.SetOdeSolver("CVODE") solver.SetVerbosity(2) t1 = MPI.Wtime() solution_cvode = solver.SolveTspan(tspan, 1.0e-4) t_cvode = MPI.Wtime() - t1 solver.ClearState() solver.SetFspShape(constr_fun=rep_constr, constr_bound=init_bounds) solver.SetOdeSolver("KRYLOV") solver.SetKrylovOrthLength(-1) solver.SetVerbosity(2)