コード例 #1
0
    def gen_single(self, params):
        """Forward model for simulator for single parameter set

        Parameters
        ----------
        params : list or np.array, 1d of length dim_param
            Parameter vector
        integration : string deciding on the type of integration used

        Returns
        -------
        dict : dictionary with data
            The dictionary must contain a key data that contains the results of
            the forward run. Additional entries can be present.
        """
        params = param_invtransform(self.prior_log,np.asarray(params))
        assert params.ndim == 1, 'params.ndim must be 1'

        dap_seed = self.gen_newseed()

        dap = DAPcython(self.init, params, seed=dap_seed)
        states = dap.simulate(self.dt, self.t, self.I)

        return {'data': states.reshape(-1),
                'time': self.t,
                'dt': self.dt,
                'I': self.I.reshape(-1)}
コード例 #2
0
# 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)

# calculate the distance for each parameters
norms = []

for p in tqdm(params):
    x_o = sim.gen_single(p)
    y_obs = stats.calc([x_o])
    obs_zt = zscore(y_obs, axis=1)
    dist_sum_stats = np.linalg.norm((sum_stats - obs_zt), axis=1)
コード例 #3
0
tstep = t_step[0:16200]
Istep = I_step[2500:18700]
vstep = v_step[2500:18700]

I_all = [I, Istep]
dt_all = [dt, dt_step]

params, labels = obs_params(reduced_model=True)
params = params[:n_params]
print(params)
print(labels)

# Set up themodel
dap = DAPcython(-75, params)
U = dap.simulate(dt, t, I)
U_step = dap.simulate(dt_step, tstep, Istep)

# generate data format for SNPE / OBSERVABLE
x_o = {'data': v.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,
コード例 #4
0
dt = 1e-2
params, labels = obs_params(reduced_model=True)
params, labels = obs_params_gbar(reduced_model=False)
I, t, t_on, t_off = syn_current(duration=120, dt=dt)

print(params)

# define models / check setters
dap = DAP(-75, params)
dap_back = DAPBe(-75, params)
dap_cython = DAPcython(-75, params, solver=1)
dap_cython_back = DAPcython(-75, params, solver=2)

# run models
U = dap.simulate(dt, t, I)
U_cython = dap_cython.simulate(dt, t, I)
U_back = dap_back.simulate(dt, t, I)
U_cython_back = dap_cython_back.simulate(dt, t, I)


# plot
fig, ax = plt.subplots(5, 1, figsize=(20, 10));
ax[0].plot(t, U, label='forward')
ax[1].plot(t, U_cython)
ax[2].plot(t, U_back, label='backward')
ax[3].plot(t, U_cython_back, label='backward_cython')

ax[4].plot(t, U, label='forward')
ax[4].plot(t, U_cython)
ax[4].plot(t, U_back, label='backward')
ax[4].plot(t, U_cython_back, label='backward_cython')
コード例 #5
0
ファイル: calc_features.py プロジェクト: alTeska/DAP_analysis
Is, vs, ts, t_ons, t_offs, dts = load_current(data_dir,
                                              protocol='IV',
                                              ramp_amp=1)

# get traces for both currents
U_steps, U_ramps = [], []

for i, j in tqdm(df_param.iterrows()):
    # get parameters
    par_temp = j.values

    # define a model
    dap = DAPcython(-75, j)

    # run model
    U_step_x = dap.simulate(dts, ts, Is)
    U_ramp_x = dap.simulate(dtr, tr, Ir)

    # run model
    U_steps.append(U_step_x.transpose()[0])
    U_ramps.append(U_ramp_x.transpose()[0])

    # calculate distance for both currents
    dis_step = distance.euclidean(vs, U_step_x)
    dis_ramp = distance.euclidean(vr, U_ramp_x)

    # save into new columns
    df_param.loc[i, 'distance_ramp'] = dis_ramp
    df_param.loc[i, 'distance_step'] = dis_step
    df_param.loc[i, 'distance_sum'] = dis_ramp + dis_step
コード例 #6
0
}

# Load the current
data_dir = '/home/alteska/Desktop/LFI_DAP/data/rawData/2015_08_26b.dat'  # best cell
protocol = 'IV'  # 'IV' # 'rampIV' # 'Zap20'
ramp_amp = 1
I, v, t, t_on, t_off, dt = load_current(data_dir,
                                        protocol=protocol,
                                        ramp_amp=ramp_amp)
I_ramp, v_ramp, t_ramp, t_on_ramp, t_off_ramp, dt_ramp = load_current(
    data_dir, protocol='rampIV', ramp_amp=3.1)

# Set up themodel
params, labels = obs_params(reduced_model=True)
dap = DAPcython(-75, params)
U_ramp = dap.simulate(dt_ramp, t_ramp, I_ramp)
U = dap.simulate(dt, t, I)

# generate data format for SNPE / OBSERVABLE
x_o = {'data': v.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)
print(prior_min, prior_max, labels)

# Summary Statistics
S = syn_obs_stats(x_o['I'],
                  params=params,
                  dt=x_o['dt'],
                  t_on=t_on,
コード例 #7
0
data_dir = '/home/ateska/Desktop/LFI_DAP/data/rawData/2015_08_26b.dat'  # best cell
# data_dir = '/home/ateska/Desktop/LFI_DAP/data/rawData/2015_08_11d.dat'  # second best cell

# load the data TODO: load actual Zap20 with CORRECT ramp_amp
I, v, t, t_on, t_off, dt = load_current(data_dir,
                                        protocol='IV',
                                        ramp_amp=-0.15)

time_start = time.clock()

# define models
dap = DAPcython(-75, params)

# run model
DAPdict = dap.simulate(dt, t, I, channels=True)

time_end = time.clock()
print('time elapsed:', time_end - time_start)

# plot voltage trace
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(20, 10))
ax.plot(t, DAPdict['U'], label='model')
ax.plot(t, v, label='data')
ax.grid()
ax.plot(t, I)
ax.legend()
plt.show()

# plot activation functions
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(20, 10))
コード例 #8
0
ファイル: test_cython.py プロジェクト: alTeska/DAPmodel
dt = 1e-2
# params, labels = obs_params_gbar(reduced_model=True)
params, labels = obs_params(reduced_model=False)

I, t, t_on, t_off = syn_current(duration=120, dt=dt)

# define models
dap = DAP(-75, params)
dap_back = DAPBe(-75, params)
dap_cython = DAPcython(-75, params, solver=1)
dap_cython_back = DAPcython(-75, params, solver=2)

# run models
U = dap.simulate(dt, t, I)
U_cython = dap_cython.simulate(dt, t, I)
U_back = dap_back.simulate(dt, t, I)
U_cython_back = dap_cython_back.simulate(dt, t, I)

print('\n', 'forward:')
print("cython:",
      timeit.timeit(lambda: dap_cython.simulate(dt, t, I), number=int(4)))
print("python:", timeit.timeit(lambda: dap.simulate(dt, t, I), number=int(4)))

print('\n', 'backward:')
print("cython:",
      timeit.timeit(lambda: dap_cython_back.simulate(dt, t, I), number=int(4)))
print("python:",
      timeit.timeit(lambda: dap_back.simulate(dt, t, I), number=int(4)))

fig, ax = plt.subplots(2, 1, figsize=(20, 10))
コード例 #9
0
from dap import DAPcython
from dap.utils import load_current, obs_params_gbar

params, labels = obs_params_gbar()
data_dir = '/home/ateska/Desktop/LFI_DAP/data/rawData/2015_08_26b.dat'    # best cell
# data_dir = '/home/ateska/Desktop/LFI_DAP/data/rawData/2015_08_11d.dat'  # second best cell

# load the data
I, v, t, t_on, t_off, dt = load_current(data_dir, protocol='rampIV', ramp_amp=3.1)
I_iv, v_iv, t_iv, t_on_iv, t_off_iv, dt_iv = load_current(data_dir, protocol='IV', ramp_amp=1)



# define and run the model
dap = DAPcython(-75, params)
U = dap.simulate(dt, t, I)
U_iv = dap.simulate(dt_iv, t_iv, I_iv)

print("cython:", timeit.timeit(lambda: dap.simulate(dt, t, I), number=int(1)))
print("cython:", timeit.timeit(lambda: dap.simulate(dt_iv, t_iv, I_iv), number=int(1)))

print(dt, dt_iv)

fig, ax = plt.subplots(2, 1, figsize=(10,20))
ax[0].plot(t, I)
ax[0].plot(t, v)
ax[0].plot(t, U)
ax[1].plot(t_iv, I_iv)
ax[1].plot(t_iv, v_iv)
ax[1].plot(t_iv, U_iv)