def plot_dt_scan(best_ind_dict, good_solutions, dt, sg, stderr): """Plot dt scan""" dt_vec = np.linspace(-90e-3, 50e-3, 100) sg_vec = [] for model_dt in dt_vec: protocol = stdputil.Protocol( ["pre", "post", "post", "post"], [model_dt, 20e-3, 20e-3], 0.1, 60.0, prot_id="%.2fms" % model_dt ) model_sg = stdputil.protocol_outcome(protocol, best_ind_dict) sg_vec.append(model_sg) try: sg_good_sol_vec = pickle.load(open("sg_good_sol_vec.pkl", "rb")) except IOError: sg_good_sol_vec = [] for _, good_sol in enumerate(good_solutions): sg_ind = [] for model_dt in dt_vec: protocol = stdputil.Protocol( ["pre", "post", "post", "post"], [model_dt, 20e-3, 20e-3], 0.1, 60.0, prot_id="%.2fms" % model_dt ) model_sg = stdputil.protocol_outcome(protocol, good_sol) sg_ind.append(model_sg) sg_good_sol_vec.append(sg_ind) pickle.dump(sg_good_sol_vec, open("sg_good_sol_vec.pkl", "wb")) fig3, ax3 = plt.subplots(figsize=(10, 10), facecolor="white") ax3.set_rasterization_zorder(1) for sg_ind in sg_good_sol_vec: ax3.plot(dt_vec * 1000.0, sg_ind, lw=1, color="lightblue", zorder=0) ax3.plot(dt_vec * 1000.0, sg_vec, marker="o", lw=1, color="darkblue", label="Best model") ax3.errorbar( dt, sg, yerr=stderr, fmt="o", color="red", ms=10, ecolor="red", elinewidth=3, capsize=5, capthick=3, zorder=10000, label="In vitro", ) ax3.axhline(y=1, color="k", linestyle="--") ax3.axvline(color="k", linestyle="--") ax3.set_xlabel(r"$\Delta t$ (ms)") ax3.set_ylabel("EPSP amplitude change") ax3.legend() fig3.tight_layout() fig3.savefig("figures/graupner_dtscan.eps", rasterized=True, dpi=72)
def plot_dt_scan(best_ind_dict, good_solutions, dt, sg, stderr): """Plot dt scan""" dt_vec = np.linspace(-90e-3, 50e-3, 100) sg_vec = [] for model_dt in dt_vec: protocol = stdputil.Protocol( ['pre', 'post', 'post', 'post'], [model_dt, 20e-3, 20e-3], 0.1, 60.0, prot_id='%.2fms' % model_dt) model_sg = stdputil.protocol_outcome(protocol, best_ind_dict) sg_vec.append(model_sg) try: sg_good_sol_vec = pickle.load(open( "sg_good_sol_vec.pkl", "rb" )) except IOError: sg_good_sol_vec = [] for i, good_sol in enumerate(good_solutions): #print(len(good_solutions), i) sg_ind = [] for model_dt in dt_vec: protocol = stdputil.Protocol( ['pre', 'post', 'post', 'post'], [model_dt, 20e-3, 20e-3], 0.1, 60.0, prot_id='%.2fms' % model_dt) model_sg = stdputil.protocol_outcome(protocol, good_sol) sg_ind.append(model_sg) sg_good_sol_vec.append(sg_ind) pickle.dump(sg_good_sol_vec, open( "sg_good_sol_vec.pkl", "wb" )) fig3, ax3 = plt.subplots(figsize=(10, 10), facecolor='white') ax3.set_rasterization_zorder(1) for sg_ind in sg_good_sol_vec: ax3.plot(dt_vec * 1000.0, sg_ind, lw=1, color='lightblue', zorder=0) ax3.plot(dt_vec * 1000.0, sg_vec, marker='o', lw=1, color='darkblue', label='Best model') ax3.errorbar(dt, sg, yerr=stderr, fmt='o', color='red', ms=10, ecolor='red', elinewidth=3, capsize=5, capthick=3, zorder=10000, label='In vitro') ax3.axhline(y=1, color='k', linestyle='--') ax3.axvline(color='k', linestyle='--') ax3.set_xlabel(r'$\Delta t$ (ms)') ax3.set_ylabel('EPSP amplitude change') ax3.legend() fig3.tight_layout() fig3.savefig('figures/graupner_dtscan.eps', rasterized=True, dpi=72)
def test_protocol_outcome(): """ Test against Fig. 3 of Graupner and Brunel (2012). TODO, Ask permission to Michael to add testing files. Notes ----- Data used for the test were kindly provprot_ided by Dr. M. Graupner. Fig. 3F cannot be reproduced because generated using an approximate solution. """ # Case 1: Fig. 3B mgspike = np.loadtxt( '/gpfs/bbp.cscs.ch/home/chindemi/proj32/graupner/data/post_spike.dat') dt = mgspike[:, 0] outcome = np.zeros(len(dt)) for i in xrange(len(dt)): p = stdputil.Protocol(['pre', 'post'], [dt[i] * 1e-3], 5.0, 200.0) outcome[i] = stdputil.protocol_outcome(p, stdputil.param_hippocampal) npt.assert_allclose(outcome, mgspike[:, 1], rtol=1e-05) # Case 2: Fig. 3D mgspike = np.loadtxt( '/gpfs/bbp.cscs.ch/home/chindemi/proj32/graupner/data/' 'post_burst_100.dat') dt = mgspike[:, 0] outcome = np.zeros(len(dt)) for i in xrange(len(dt)): p = stdputil.Protocol(['post', 'post', 'pre'], [11.5e-3, -dt[i] * 1e-3], 5.0, 100.0) outcome[i] = stdputil.protocol_outcome(p, stdputil.param_hippocampal) npt.assert_allclose(outcome, mgspike[:, 1], rtol=1e-05) # Case 3: Fig. 3E mgspike = np.loadtxt( '/gpfs/bbp.cscs.ch/home/chindemi/proj32/graupner/data/' 'post_burst_30.dat') dt = mgspike[:, 0] outcome = np.zeros(len(dt)) for i in xrange(len(dt)): p = stdputil.Protocol(['post', 'post', 'pre'], [11.5e-3, -dt[i] * 1e-3], 5.0, 30.0) outcome[i] = stdputil.protocol_outcome(p, stdputil.param_hippocampal) npt.assert_allclose(outcome, mgspike[:, 1], rtol=1e-05)
def compute_synaptic_gain_with_lists(self, param_values): """Compute synaptic gain for all protocols. :param param_values: iterable Parameters list """ param_dict = self.get_param_dict(param_values) syn_gain = [stdputil.protocol_outcome(protocol, param_dict) for protocol in self.protocols] return syn_gain
def compute_synaptic_gain_with_lists(self, param_values): """Compute synaptic gain for all protocols. :param param_values: iterable Parameters list """ param_dict = self.get_param_dict(param_values) syn_gain = [ stdputil.protocol_outcome(protocol, param_dict) for protocol in self.protocols ] return syn_gain
def test_protocol_outcome(): """ Test against Fig. 3 of Graupner and Brunel (2012). TODO, Ask permission to Michael to add testing files. Notes ----- Data used for the test were kindly provprot_ided by Dr. M. Graupner. Fig. 3F cannot be reproduced because generated using an approximate solution. """ # Case 1: Fig. 3B mgspike = np.loadtxt('/gpfs/bbp.cscs.ch/home/chindemi/proj32/graupner/data/post_spike.dat') dt = mgspike[:, 0] outcome = np.zeros(len(dt)) for i in xrange(len(dt)): p = stdputil.Protocol(['pre', 'post'], [dt[i] * 1e-3], 5.0, 200.0) outcome[i] = stdputil.protocol_outcome(p, stdputil.param_hippocampal) npt.assert_allclose(outcome, mgspike[:, 1], rtol=1e-05) # Case 2: Fig. 3D mgspike = np.loadtxt('/gpfs/bbp.cscs.ch/home/chindemi/proj32/graupner/data/post_burst_100.dat') dt = mgspike[:, 0] outcome = np.zeros(len(dt)) for i in xrange(len(dt)): p = stdputil.Protocol(['post', 'post', 'pre'], [11.5e-3, -dt[i] * 1e-3], 5.0, 100.0) outcome[i] = stdputil.protocol_outcome(p, stdputil.param_hippocampal) npt.assert_allclose(outcome, mgspike[:, 1], rtol=1e-05) # Case 3: Fig. 3E mgspike = np.loadtxt('/gpfs/bbp.cscs.ch/home/chindemi/proj32/graupner/data/post_burst_30.dat') dt = mgspike[:, 0] outcome = np.zeros(len(dt)) for i in xrange(len(dt)): p = stdputil.Protocol(['post', 'post', 'pre'], [11.5e-3, -dt[i] * 1e-3], 5.0, 30.0) outcome[i] = stdputil.protocol_outcome(p, stdputil.param_hippocampal) npt.assert_allclose(outcome, mgspike[:, 1], rtol=1e-05)
def evaluate_with_lists(self, param_values): """Evaluate individual :param param_values: iterable Parameters list """ param_dict = self.get_param_dict(param_values) err = [] for protocol, sg, stderr in zip(self.protocols, self.sg, self.stderr): res = stdputil.protocol_outcome(protocol, param_dict) err.append(numpy.abs(sg - res) / stderr) return err
def evaluate_with_lists(self, param_values): """Evaluate individual :param param_values: iterable Parameters list """ param_dict = self.get_param_dict(param_values) err = [] for protocol, sg, stderr in \ zip(self.protocols, self.sg, self.stderr): res = stdputil.protocol_outcome(protocol, param_dict) err.append(numpy.abs(sg - res) / stderr) return err
def plot_dt_scan(best_ind_dict, good_solutions, dt, sg, stderr): """Plot dt scan""" dt_vec = np.linspace(-90e-3, 50e-3, 100) sg_vec = [] for model_dt in dt_vec: protocol = stdputil.Protocol( ["pre", "post", "post", "post"], [model_dt, 20e-3, 20e-3], 0.1, 60.0, prot_id="%.2fms" % model_dt, ) model_sg = stdputil.protocol_outcome(protocol, best_ind_dict) sg_vec.append(model_sg) try: sg_good_sol_vec = pickle.load(open("sg_good_sol_vec.pkl", "rb")) except IOError: sg_good_sol_vec = [] for _, good_sol in enumerate(good_solutions): sg_ind = [] for model_dt in dt_vec: protocol = stdputil.Protocol( ["pre", "post", "post", "post"], [model_dt, 20e-3, 20e-3], 0.1, 60.0, prot_id="%.2fms" % model_dt, ) model_sg = stdputil.protocol_outcome(protocol, good_sol) sg_ind.append(model_sg) sg_good_sol_vec.append(sg_ind) pickle.dump(sg_good_sol_vec, open("sg_good_sol_vec.pkl", "wb")) fig3, ax3 = plt.subplots(figsize=(10, 10), facecolor="white") ax3.set_rasterization_zorder(1) for sg_ind in sg_good_sol_vec: ax3.plot(dt_vec * 1000.0, sg_ind, lw=1, color="lightblue", zorder=0) ax3.plot( dt_vec * 1000.0, sg_vec, marker="o", lw=1, color="darkblue", label="Best model", ) ax3.errorbar( dt, sg, yerr=stderr, fmt="o", color="red", ms=10, ecolor="red", elinewidth=3, capsize=5, capthick=3, zorder=10000, label="In vitro", ) ax3.axhline(y=1, color="k", linestyle="--") ax3.axvline(color="k", linestyle="--") ax3.set_xlabel(r"$\Delta t$ (ms)") ax3.set_ylabel("EPSP amplitude change") ax3.legend() fig3.tight_layout() fig3.savefig("figures/graupner_dtscan.eps", rasterized=True, dpi=72)