def passive_fit_2(info, up_data, down_data): h.v_init = 0 h.tstop = 100 h.cvode_active(1) fit_start = 4.0025 v_rec = h.Vector() t_rec = h.Vector() v_rec.record(h.soma[0](0.5)._ref_v) t_rec.record(h._ref_t) mrf = h.MulRunFitter[0] gen0 = mrf.p.pf.generatorlist.object(0) gen0.toggle() fit0 = gen0.gen.fitnesslist.object(0) up_t = h.Vector(up_data[:, 0]) up_v = h.Vector(up_data[:, 1]) fit0.set_data(up_t, up_v) fit0.boundary.x[0] = fit_start fit0.boundary.x[1] = info["limit"] fit0.set_w() gen1 = mrf.p.pf.generatorlist.object(1) gen1.toggle() fit1 = gen1.gen.fitnesslist.object(0) down_t = h.Vector(down_data[:, 0]) down_v = h.Vector(down_data[:, 1]) fit1.set_data(down_t, down_v) fit1.boundary.x[0] = fit_start fit1.boundary.x[1] = info["limit"] fit1.set_w() minerr = 1e12 for i in range(3): # Need to re-initialize the internal MRF variables, not top-level proxies # for randomize() to work mrf.p.pf.parmlist.object(0).val = 1 mrf.p.pf.parmlist.object(1).val = 10000 mrf.randomize() mrf.prun() if mrf.opt.minerr < minerr: fit_Ri = h.Ri fit_Cm = h.Cm fit_Rm = h.Rm minerr = mrf.opt.minerr results = { "ra": fit_Ri, "cm": fit_Cm, "rm": fit_Rm, "err": minerr, "a1": h.somaaxon_area(), "a2": h.alldend_area(), } return results
def passive_fit_elec(up_data, down_data, fit_window_start, fit_window_end, bridge, electrode_cap, n_init=10): """ Fit passive properties (Ri, Cm, and Rm) with simulated recording electrode Parameters ---------- up_data: array, shape (n_samples, 2) Positive-going times and voltage responses down_data: array, shape (n_samples, 2) Negative-going times and voltage responses fit_window_start: float Start of fit window (ms) fit_window_end: float End of fit window (ms) bridge: float Value of bridge balance (estimated series resistance), MOhm electrode_cap: float Value of electrode capacitance (pF) n_init: int (optional, default 10) Number of random starts for passive fitting Returns ------- :class:`PassiveFitResult` """ mrf = _common_config(fit_window_start, fit_window_end, up_data, down_data) circuit = h.LinearCircuit[0] circuit.R2 = bridge / 2.0 circuit.R3 = bridge / 2.0 circuit.C4 = electrode_cap * 1e-3 minerr = 1e12 for i in range(n_init): # Need to re-initialize the internal MRF variables, not top-level proxies # for randomize() to work mrf.p.pf.parmlist.object(0).val = 100 mrf.p.pf.parmlist.object(1).val = 1 mrf.p.pf.parmlist.object(2).val = 10000 mrf.p.pf.putall() mrf.randomize() mrf.prun() if mrf.opt.minerr < minerr: fit_Ri = h.Ri fit_Cm = h.Cm fit_Rm = h.Rm minerr = mrf.opt.minerr return PassiveFitResult(fit_Ri, fit_Cm, fit_Rm, minerr, h.somaaxon_area(), h.alldend_area())
def passive_fit_1(up_data, down_data, fit_window_start, fit_window_end, n_init=10): """ Fit passive properties (Ri, Cm, and Rm) Parameters ---------- up_data: array, shape (n_samples, 2) Positive-going times and voltage responses down_data: array, shape (n_samples, 2) Negative-going times and voltage responses fit_window_start: float Start of fit window (ms) fit_window_end: float End of fit window (ms) n_init: int (optional, default 10) Number of random starts for passive fitting Returns ------- Dictionary of passive fit and membrane area values """ mrf = _common_config(fit_window_start, fit_window_end, up_data, down_data) minerr = 1e12 for i in range(n_init): # Need to re-initialize the internal MRF variables, not top-level proxies # for randomize() to work mrf.p.pf.parmlist.object(0).val = 100 mrf.p.pf.parmlist.object(1).val = 1 mrf.p.pf.parmlist.object(2).val = 10000 mrf.p.pf.putall() mrf.randomize() mrf.prun() if mrf.opt.minerr < minerr: fit_Ri = h.Ri fit_Cm = h.Cm fit_Rm = h.Rm minerr = mrf.opt.minerr results = { "ra": fit_Ri, "cm": fit_Cm, "rm": fit_Rm, "err": minerr, "a1": h.somaaxon_area(), "a2": h.alldend_area(), } return results
def passive_fit_1(up_data, down_data, fit_window_start, fit_window_end, n_init=10): """ Fit passive properties (Ri, Cm, and Rm) Parameters ---------- up_data: (n_samples, 2) array Positive-going times and voltage responses down_data: (n_samples, 2) array Negative-going times and voltage responses fit_window_start: float Start of fit window (ms) fit_window_end: float End of fit window (ms) n_init: int, optional Number of random starts for passive fitting (default 10) Returns ------- :class:`PassiveFitResult` """ mrf = _common_config(fit_window_start, fit_window_end, up_data, down_data) minerr = 1e12 for i in range(n_init): # Need to re-initialize the internal MRF variables, not top-level proxies # for randomize() to work mrf.p.pf.parmlist.object(0).val = 100 mrf.p.pf.parmlist.object(1).val = 1 mrf.p.pf.parmlist.object(2).val = 10000 mrf.p.pf.putall() mrf.randomize() mrf.prun() if mrf.opt.minerr < minerr: fit_Ri = h.Ri fit_Cm = h.Cm fit_Rm = h.Rm minerr = mrf.opt.minerr return PassiveFitResult(fit_Ri, fit_Cm, fit_Rm, minerr, h.somaaxon_area(), h.alldend_area())