def calculate_weight(prev_population, prev_weights, sim_theta): wsum = 0.0 sigma = np.cov(np.vstack(prev_population).T) mean = utils.colMeans(np.vstack(prev_population)) for particle, weight in izip(prev_population, prev_weights): wsum += weight * utils.dmvnorm(sim_theta, mean, sigma) return 0.1 / wsum
def main(): X0 = [1, 0.5] t = np.arange(0, 15, 0.1) ds = generate_data() populations = abc.smc(dx_dt, ds, [700.0]) last_population = populations[:-1] theta = utils.colMeans(np.vstack(last_population)) X = integrate.odeint(dx_dt, X0, t, args=(theta,)) plt.plot(t,X) plt.show()
def main(): X0 = [1, 0.5] t = np.arange(0, 15, 0.1) ds = generate_data() populations = abc.smc(dx_dt, ds, [700.0]) last_population = populations[:-1] theta = utils.colMeans(np.vstack(last_population)) X = integrate.odeint(dx_dt, X0, t, args=(theta, )) plt.plot(t, X) plt.show()
def gene_regulation(): theta = [1., 10.] t = np.arange(0, 15, 0.1) X0 = 1. ds = abc.generate_dataset_full(gene_reg, theta) noisy_ds = abc.add_gaussian_noise_full(np.copy(ds)) populations = abc.smc(gene_reg, noisy_ds, [300.0]) theta1 = utils.colMeans(np.vstack(populations[:-1])) X = integrate.odeint(gene_reg, X0, t, args=(theta, )) plt.plot(t, X, 'r-') X1 = integrate.odeint(gene_reg, X0, t, args=(theta1, )) plt.plot(t, X1, 'b-') plt.plot(t, noisy_ds, 'go') plt.show()
def plot_solution(population, ds): ti = [t / 10 for t in times] theta1 = np.array([1, 1]) plt.figure(1) theta = utils.colMeans(np.vstack(population)) X0 = np.array([1, 0.5]) t = np.arange(0, 15, 0.1) X = integrate.odeint(dx_dt, X0, t, args=(theta, )) Y = integrate.odeint(dx_dt, X0, t, args=(theta1, )) x, y = X.T x1, y1 = Y.T plt.figure(3) plt.subplot(211) plt.plot(t, x, 'r-', label='x(t)') plt.plot(t, x1, 'g-', label='x(t))') plt.plot(ti, ds[:, 0], marker='s', linestyle='', color='g') plt.subplot(212) plt.plot(t, y, 'b-', label='y(t)') plt.plot(t, y1, 'g-', label='y(t)') plt.plot(ti, ds[:, 1], marker='^', linestyle='', color='g') plt.xlabel('time') plt.show()
def plot_solution(population, ds): ti = [t/10 for t in times] theta1 = np.array([1,1]) plt.figure(1) theta = utils.colMeans(np.vstack(population)) X0 = np.array([1, 0.5]) t = np.arange(0, 15, 0.1) X= integrate.odeint(dx_dt, X0, t, args=(theta,)) Y= integrate.odeint(dx_dt, X0, t, args=(theta1,)) x,y = X.T x1,y1 = Y.T plt.figure(3) plt.subplot(211) plt.plot(t, x, 'r-', label='x(t)') plt.plot(t, x1,'g-',label='x(t))') plt.plot(ti, ds[:, 0], marker='s', linestyle='', color='g') plt.subplot(212) plt.plot(t, y, 'b-', label='y(t)') plt.plot(t, y1, 'g-', label='y(t)') plt.plot(ti, ds[:, 1], marker='^', linestyle='', color='g') plt.xlabel('time') plt.show()