# generate data format for SNPE / OBSERVABLE x_o = {'data': U.reshape(-1), 'time': t, 'dt': dt, 'I': I} # Setup Priors prior_min, prior_max, labels = load_prior_ranges(n_params) prior_unif = Uniform(lower=prior_min, upper=prior_max) # Summary Statistics S = syn_obs_stats(x_o['I'], params=params, dt=x_o['dt'], t_on=t_on, t_off=t_off, n_summary=n_summary, summary_stats=1, data=x_o) M = DAPSimulator(x_o['I'], x_o['dt'], -75) s = DAPSummaryStatsStepMoments(t_on, t_off, n_summary=n_summary) G = Default(model=M, prior=prior_unif, summary=s) # Generator # Runing the simulation inf_snpe = SNPE(generator=G, n_components=n_components, n_hiddens=n_hiddens, obs=S, # reg_lambda=reg_lambda, pilot_samples=0, prior_norm=True) reg_lambda=reg_lambda, pilot_samples=0) logs, tds, posteriors = inf_snpe.run(n_train=[n_samples], n_rounds=n_rounds, proposal=prior_unif) # Analyse results samples_prior = prior_unif.gen(n_samples=int(5e5)) samples_posterior = posteriors[-1].gen(n_samples=int(5e5))
from dap import DAPcython from dap.dap_simulator import DAPSimulator # General Settings Pick n_samples = 100 n_summary = 13 dt = 0.01 percent_accept = 1 # Get current I, t, t_on, t_off = syn_current(duration=70, dt=dt, t_on=15, t_off=20, amp=3.1) params, labels = obs_params_gbar(reduced_model=True) dap = DAPcython(-75, params * 10) # Set up the model sim = DAPSimulator(I, dt, -75, dim_param=2) stats = DAPSummaryStatsMoments(t_on, t_off, n_summary=n_summary) # Setup Priors prior_min = np.array([0, 0]) prior_max = np.array([2, 2]) prior_unif = Uniform(lower=prior_min, upper=prior_max) # generate desired data U = dap.simulate(dt, t, I) y_o = {'data': U.reshape(-1), 'time': t, 'dt': dt, 'I': I} y = stats.calc([y_o]) # Sample Parameters params = prior_unif.gen(n_samples=n_samples)
import matplotlib.pyplot as plt from dap.dap_simulator import DAPSimulator from dap.utils import obs_params_gbar, syn_current params, labels = obs_params_gbar() I, t, t_on, t_off = syn_current(duration=150, dt=0.01) # define model dap1 = DAPSimulator(I, 0.01, -75) # run model stats = dap1.gen_single(params) # plot voltage trace fig, ax = plt.subplots(ncols=1, nrows=2, figsize=(20, 10)) ax[0].grid() ax[0].set_ylabel('V (mV)') ax[0].set_xlabel('t (ms)') ax[0].plot(stats['time'], stats['data'], label='DAP') ax[0].legend() ax[1].plot(t, I) plt.show()