Exemplo n.º 1
0
# generate random models
for i in range(n_models):

    # create a model randomly from all channels
    weights_model = problem.generator(prng, None)

    for j, dt in enumerate(dts):
        print 'run '+'model: ' + str(i) + ' dt: ' +str(dt)
        
        # change dt
        data_newdt = change_dt(dt, problem.data)
        problem.simulation_params = extract_simulation_params(data_newdt)

        # run simulation
        problem.update_cell(weights_model)
        currents = [problem.cell.soma.record_from(channel_list[k], 'i'+ion_list[k], pos=.5) for k in range(len(channel_list))]
        v_newdt, t_newdt = run_simulation(problem.cell, **problem.simulation_params)

        #pl.figure()
        #pl.plot(t_newdt, v_newdt)
        #pl.show()

        # compute parameter
        dvdt_newdt = np.concatenate((np.array([(v_newdt[1]-v_newdt[0])/dt]), np.diff(v_newdt)/dt))
        i_newdt = data_newdt.i.values
        celsius = problem.simulation_params['celsius']

        # get currents
        candidate = np.ones(len(problem.path_variables))  # gbars should be 1
        problem.update_cell(candidate)
Exemplo n.º 2
0
    os.makedirs(save_dir)
with open(save_dir+'/problem.json', 'w') as f:
    json.dump(params, f, indent=4)
with open(save_dir+'/cell.json', 'w') as f:
    json.dump(Cell.from_modeldir(params['model_dir']).get_dict(), f, indent=4)

for trial in range(0, n_trials):

    # get current traces
    v_exp = problem.data.v.values
    t_exp = problem.data.t.values
    i_exp = problem.data.i.values
    dt = t_exp[1] - t_exp[0]
    dvdt = np.concatenate((np.array([(v_exp[1]-v_exp[0])/dt]), np.diff(v_exp) / dt))
    candidate = np.ones(len(problem.path_variables))
    problem.update_cell(candidate)
    channel_list = get_channel_list(problem.cell, 'soma')
    ion_list = get_ionlist(channel_list)
    celsius = problem.simulation_params['celsius']

    currents = currents_given_v(v_exp, t_exp, problem.cell.soma, channel_list, ion_list, celsius)

    # convert units
    dvdt_sc, i_inj_sc, currents_sc, Cm, cell_area = convert_units(problem.cell.soma.L, problem.cell.soma.diam,
                                                          problem.cell.soma.cm, dvdt, i_exp,
                                                          currents)

    # linear regression
    weights, residual, y, X = linear_regression(dvdt_sc, i_inj_sc, currents_sc, i_pas=0, Cm=Cm)
    #weights, residual, y, X = linear_regression(dvdt_sc, i_inj_sc, currents_sc, i_pas=0, Cm=None, cell_area=cell_area)