Ejemplo n.º 1
0
def plot_voltage_after(ax):
    data = core.get_data('fig3/2019-02-02_membrane_potential_psth_end.npy')[10]
    data_teach=core.get_data("fig3/2019-02-02_membrane_potential_psth_teacher.npy")[10]
    time_params=core.get_data("fig3/time_parameters.npy").item()
    #ax.set_xlim([0.,.5])

    time=np.arange(0,500)*time_params["dt"]
    
    #subtract resting potential
    data=data-70.
    data_teach=data_teach-70.

    ax.plot(time,data,color=core.label_to_color["natural"],linewidth=core.linewidth["voltage"])
    ax.plot(time,data_teach,color=core.label_to_color["teacher"],linewidth=core.linewidth["voltage"])

    core.show_axis(ax)
    core.make_spines(ax)

    #plotf.trace_plot(data)
    ax.set_xlabel(core.x_labels["voltage_trace"])
    ax.set_ylabel(core.y_labels["voltage_trace"])
   #ax.legend(("student","teacher"),loc=0,fontsize=8.,labelspacing=0.1,borderaxespad=0.1,borderpad=0.,handlelength=0.5,frameon=False)
    


    pass
Ejemplo n.º 2
0
def plot_var_result_example(ax):
    ax.set_xlim([-0.0,5.5])
    data_hr_ht = core.get_data('fig6/variance_hr_ht.npy')
    data_lr_ht = core.get_data('fig6/variance_lr_ht.npy')
    data_hr_lt = core.get_data('fig6/variance_hr_lt.npy')
    time_params=core.get_data('fig6/time_parameters.npy').item()


    weighttrace=np.concatenate(((data_hr_ht,),(data_lr_ht,),(data_hr_lt,)))
    
    core.show_axis(ax)
    core.make_spines(ax)
    ax.set_prop_cycle(cycler('color',[core.label_to_color["hr_ht"],core.label_to_color["lr_ht"],core.label_to_color["hr_lt"]] ))

    plotf.trace_plot(ax,weighttrace,time_params,linewidth=core.linewidth["normal"])
    ax.axvline(x=5,color=core.label_to_color["aux_lines"],linewidth=core.linewidth["aux_lines"],ls="dashed")
    ax.text(5.,75.,r"$t_0$")
    ax.set_xlabel(core.x_labels["trace_plot"])
    ax.set_ylabel(core.y_labels["trace_plot"])
    ax.legend((r"$w_1$",r"$w_2$",r"$w_3$"),loc=2,fontsize=8.,handlelength=0.5,frameon=False)
    




    pass
Ejemplo n.º 3
0
def plot_heatplot_heterosyn(ax):
    data = core.get_data('fig5/Delta_w_het_grid.npy')
    data_aux = core.get_data('fig5/Delta_w_hom_grid.npy')

    vmin = min(np.amin(data), np.amin(data_aux))
    vmax = max(np.amax(data), np.amax(data_aux))

    w_range = core.get_data('fig5/w_range.npy')

    core.show_axis(ax)
    core.make_spines(ax)

    label = r"$\Delta w_{\mathrm{ust}}$ [%]"
    labelpad = -8.

    plotf.hplot(ax, data, vmin, vmax, w_range, label, labelpad)
    ax.axhline(y=1.85,
               color=core.label_to_color["aux_line_heat"],
               linewidth=core.linewidth["aux_lines"],
               ls="dashed")
    ax.set_xlabel(core.x_labels["heat_plot"],
                  labelpad=core.linewidth["lp_heat"])
    ax.set_ylabel(core.y_labels["heat_plot"],
                  labelpad=core.linewidth["lp_heat"])

    pass
Ejemplo n.º 4
0
def plot_var_hist_hr_ht(ax):
    data_usp = core.get_data('fig6/histogram_hr_ht.npy')   


    ax.set_ylim([0.,20.])
    ax.set_xlim([0.,5.])
    
    
    
    counts,bins,patches=ax.hist(data_usp,bins=np.arange(0.,25.,.5),log=1,orientation="horizontal",density=1,rwidth=1.,color=core.label_to_color["hr_ht"])
    ax.set_xlim(ax.get_xlim()[::-1])
   
    ax.spines['left'].set_position(('axes', 1.))
    ax.tick_params(axis="y",direction="in", pad=-15.)
    ax.tick_params(axis="x",direction="out", pad=-0.3)
   
    core.show_axis(ax)
    core.make_spines(ax)
    tick_formatter =ticker.LogFormatterExponent()
    ax.xaxis.set_major_formatter(tick_formatter)

    
    ax.set_xlabel(core.x_labels["hist"],labelpad=-2.)
    
    
    
    pass
Ejemplo n.º 5
0
def plot_var_lowr_hightau(ax):
    data = core.get_data('fig6/usp_trace_lr_ht.npy')[0]
    ax.set_ylim([0.,20.])
    ax.set_xlim([0.,0.5])
    time_params=core.get_data('fig6/time_parameters.npy').item()
    time=np.arange(0,time_params["learning_time"],time_params["dt"])
    ax.text(0.3,22,r"$r_2=5\rm{ Hz }$")
    ax.text(0.3,17,r"$\tau_2=15\rm{ ms}$")
    core.show_axis(ax)
    core.make_spines(ax)

    ax.plot(time,data,color=core.label_to_color["lr_ht"],linewidth=core.linewidth["normal"])
    
    ax.set_xlabel(core.x_labels["usp_trace"])
    ax.set_ylabel(core.y_labels["usp_trace"])
    pass
Ejemplo n.º 6
0
def plot_attenuation_example_abs(ax):
    data_prox = core.get_data('fig6/attenuation_proximal_synapse.npy')
    data_dist = core.get_data('fig6/attenuation_distal_synapse.npy')
    time_params=core.get_data('fig6/time_parameters.npy').item()
    ax.set_prop_cycle(cycler('color',[core.label_to_color["attenuation_ldist"],core.label_to_color["attenuation_hdist"]] ))
    weighttrace=np.concatenate(((data_prox,),(data_dist,)))
    
    core.show_axis(ax)
    core.make_spines(ax)

    plotf.trace_plot(ax,weighttrace,time_params,perc=False,linewidth=core.linewidth["normal"])
    ax.set_xlabel(core.x_labels["trace_plot"])
    ax.set_ylabel(core.y_labels["trace_plot_dend_abs"])
   # ax.legend((r"$d=3\mu m$",r"$d=7\mu m$"),loc=2,fontsize=8.,handlelength=0.5,frameon=False)

    
    pass
Ejemplo n.º 7
0
def plot_spikes_post(ax):
    data = core.get_data('fig5/teacher_spikes_illu.npy')
    ax.plot(data[10, 0:500],
            color=core.label_to_color["aux_lines"],
            linewidth=core.linewidth["spikes"])

    core.hide_axis(ax)

    pass
Ejemplo n.º 8
0
def plot_attenuation_summary_abs(ax):
    
    ax.set_xlim([0.,11.])
    
    data_wchange = core.get_data('fig6/att_weight_change_abs.npy')
    data_dist = core.get_data('fig6/distances.npy')
    color=[core.label_to_color["attenuation_im"]]*np.shape(data_dist)[0]
    color[2]=core.label_to_color["attenuation_ldist"]
    color[-3]=core.label_to_color["attenuation_hdist"]
    core.show_axis(ax)
    core.make_spines(ax)

    ax.scatter(data_dist,data_wchange,color=color,s=core.linewidth["scatter"])
    ax.set_xlabel(r"$d[\mu m]$")
    ax.set_ylabel(core.y_labels["weightchange_dend_abs"])
    

    pass
Ejemplo n.º 9
0
def plot_phase3(ax):

    data_hom = core.get_data('fig5/w_hom_phase3.npy')
    data_het = core.get_data('fig5/w_het_phase3.npy')
    time_params = core.get_data('fig5/time_parameters.npy').item()
    ax.set_xlim([-.5, 5.5])
    x_ticks = np.array((0., 2.5, 5.))
    ax.xaxis.set_ticks(x_ticks)

    weighttrace = np.concatenate(((data_hom, ), (data_het, )))
    ax.set_prop_cycle(
        cycler('color',
               [core.label_to_color["stim"], core.label_to_color["unstim"]]))

    core.show_axis(ax)
    core.make_spines(ax)

    plotf.trace_plot(ax,
                     weighttrace,
                     time_params,
                     linewidth=core.linewidth["normal"])
    ax.axvline(x=0,
               color=core.label_to_color["aux_lines"],
               linewidth=core.linewidth["aux_lines"],
               ls="dashed")
    ax.text(0., 99.05, r"$t_0$")
    ax.axvline(x=5,
               color=core.label_to_color["aux_lines"],
               linewidth=core.linewidth["aux_lines"],
               ls="dashed")
    ax.text(5., 99.05, r"$t_1$")

    ax.set_xlabel(core.x_labels["trace_plot"])
    ax.set_ylabel(core.y_labels["trace_plot"])
    ax.legend((r"$w_{\rm st}$", r"$w_{\rm ust}$"),
              loc=0,
              fontsize=8.,
              labelspacing=0.1,
              borderaxespad=0.1,
              borderpad=0.,
              handlelength=0.5,
              frameon=False)

    pass
Ejemplo n.º 10
0
def plot_spikes_stim2(ax):
    data = core.get_data('fig5/inputspikes_stim_illu.npy')

    ax.plot(data[20, 0:500],
            color=core.label_to_color["aux_lines"],
            linewidth=core.linewidth["spikes"])

    core.hide_axis(ax)

    pass
Ejemplo n.º 11
0
def plot_heatplot_hom_het_comparison(ax):
    data = core.get_data('fig5/Sign_delta_w_comparison.npy')
    
    w_range = core.get_data('fig5/w_range.npy')

    core.show_axis(ax)
    core.make_spines(ax)
    labelpad=0.
    
    label=r"$\rm{Sign}(\Delta w_{\mathrm{st}}\times\Delta w_{\mathrm{unst}})$"

    plotf.hplot(ax,data,-1.,1.,w_range,label=label,labelpad=labelpad)
    ax.axhline(y=1.85,color=core.label_to_color["aux_line_heat"],linewidth=core.linewidth["aux_lines"],ls="dashed")
    
    ax.set_xlabel(core.x_labels["heat_plot"],labelpad=core.linewidth["lp_heat"])
    ax.set_ylabel(core.y_labels["heat_plot"],labelpad=core.linewidth["lp_heat"])


    pass
Ejemplo n.º 12
0
def plot_var_result_summary(ax):
    
    ax.set_xlim([0.,31.])
    
    data_wchange = core.get_data('fig6/wfinal_com.npy')
    data_dist = core.get_data('fig6/usp_var_com.npy')


    core.show_axis(ax)
    core.make_spines(ax)
    color=[core.label_to_color["attenuation_im"]]*np.shape(data_dist)[0]
    color[4]=core.label_to_color["lr_ht"]
    color[20]=core.label_to_color["hr_lt"]
    color[24]=core.label_to_color["hr_ht"]
    
    
    ax.scatter(data_dist,data_wchange,color=color,s=core.linewidth["scatter"])
    ax.set_xlabel(r'$\sigma^2(\mathrm{USP})$')
    ax.set_ylabel(core.y_labels["weightchange"])
    
    pass
Ejemplo n.º 13
0
def plot_spikes_before(ax):
    
    data = core.get_data('fig3/2019-02-02_output_spikes_psth_start.npy')
    
    ax.scatter(np.nonzero(data)[1],np.nonzero(data)[0],color=core.label_to_color["natural"],s=0.01)
    
    core.show_axis(ax)
    core.make_spines(ax)
    
    ax.set_xlabel(core.x_labels["spikes"])
    ax.set_ylabel(core.y_labels["spikes"])

    pass
Ejemplo n.º 14
0
def plot_histo_after(ax):
    
    data = core.get_data('fig3/2019-02-02_output_spikes_psth_end.npy')
    data_teach=core.get_data("fig3/2019-02-02_output_spikes_psth_teacher.npy")
    print("data",np.shape(data))
    spiketimes=np.nonzero(data)[1]*0.0005
    spiketimes_teach=np.nonzero(data_teach)[1]*0.0005
    
    
    ax.set_prop_cycle(cycler('color',[core.label_to_color["natural"],core.label_to_color["teacher"]] ))
    
    bins=np.linspace(0.,0.25,20,endpoint=False)
    ax.hist([spiketimes,spiketimes_teach], bins, label=['x', 'y'],normed=1.)

    
    core.show_axis(ax)
    core.make_spines(ax)
    
    ax.set_xlabel(core.x_labels["histo"])
    ax.set_ylabel(core.y_labels["histo"])
    
    pass
Ejemplo n.º 15
0
def plot_weightpath_nat(ax):
       
    import parameter_vectorplot as parameter
    N=2
    
    para=parameter.parameter
    para["color"]=core.label_to_color["natural"]
    
    
    
    data_quiver = core.get_data('fig3/2019-01-07_vectorplot_nat.npy')
    data_cost=core.get_data('fig3/2019-01-07_contour_cost.npy')
    data_wpath=core.get_data("fig3/2018-08-24_nwpath.npy")
    data_wpath=N*data_wpath
    
    #normalize
    norm_data=np.sqrt(np.square(data_quiver[:,:,0])+np.square(data_quiver[:,:,1]))
    data_quiver[:,:,0]=data_quiver[:,:,0]/norm_data
    data_quiver[:,:,1]=data_quiver[:,:,1]/norm_data
    
    plotf.wpathplot(ax,data_quiver,data_wpath,**para)
    
    
    levels=[0.001,0.003,0.005,0.009,0.015,0.02,0.03,0.04]
    plotf.contourplot(ax,data_cost, levels=levels,**para)
    
   
    core.show_axis(ax)
    core.make_spines(ax)
    ax.spines['top'].set_visible(True)
    ax.spines['right'].set_visible(True)
    

    ax.set_xlabel(core.x_labels["weight_path"])
    ax.set_ylabel(core.y_labels["weight_path"])


    pass
Ejemplo n.º 16
0
def plot_phase1(ax):
    data_hom = core.get_data('fig5/w_hom_phase1.npy')
    data_het = core.get_data('fig5/w_het_phase1.npy')
    time_params = core.get_data('fig5/time_parameters.npy').item()

    ax.set_xlim([-.5, 5.5])
    x_ticks = np.array((0., 2.5, 5.))
    ax.xaxis.set_ticks(x_ticks)

    weighttrace = np.concatenate(((data_hom, ), (data_het, )))

    ax.set_prop_cycle(
        cycler('color',
               [core.label_to_color["stim"], core.label_to_color["unstim"]]))

    core.show_axis(ax)
    core.make_spines(ax)

    plotf.trace_plot(ax,
                     weighttrace,
                     time_params,
                     linewidth=core.linewidth["normal"])
    ax.axvline(x=0,
               color=core.label_to_color["aux_lines"],
               linewidth=core.linewidth["aux_lines"],
               ls="dashed")
    ax.text(0., 10., r"$t_0$")

    ax.axvline(x=5,
               color=core.label_to_color["aux_lines"],
               linewidth=core.linewidth["aux_lines"],
               ls="dashed")
    ax.text(5., 10., r"$t_1$")

    ax.set_xlabel(core.x_labels["trace_plot"])
    ax.set_ylabel(core.y_labels["trace_plot"])

    pass
Ejemplo n.º 17
0
def plot_learningcurve(ax):
    data_nat=core.get_data("fig3/2018-08-24_naturalgradient_KL_errorN100.npy")
    data_euc=core.get_data("fig3/2018-08-24_euclideangradient_KL_errorN100.npy")
    #data_nat_std=core.get_data("fig3/2018-08-24_naturalgradient_rate_error_std.npy")
    #data_euc_std=core.get_data("fig3/2018-08-24_euclideangradient_rate_error_std.npy")
    data_time=np.arange(0.,16.,1.)*400./60.#core.get_data("fig3/lc_time.npy")
    
    
    core.show_axis(ax)
    core.make_spines(ax)
    
    ax.semilogy(data_time,data_euc[0:16],color=core.label_to_color["euclidean"],linewidth=core.linewidth["normal"])
    ax.semilogy(data_time,data_nat[0:16],color=core.label_to_color["natural"],linewidth=core.linewidth["normal"])
    
    #ax.plot(data_time,data_euc+data_euc_std,color=core.label_to_color["euclidean"],linewidth=core.linewidth["normal"])
    #ax.plot(data_time,data_nat+data_nat_std,color=core.label_to_color["natural"],linewidth=core.linewidth["normal"])
    
    #ax.plot(data_time,data_euc-data_euc_std,color=core.label_to_color["euclidean"],linewidth=core.linewidth["normal"])
    #ax.plot(data_time,data_nat-data_nat_std,color=core.label_to_color["natural"],linewidth=core.linewidth["normal"])
    
    ax.set_xlabel(core.x_labels["lc"])
    ax.set_ylabel(core.y_labels["lc"])
    ax.legend(("Euclidean gradient","Natural gradient"),loc="upper_right",fontsize=6.,labelspacing=0.05,borderaxespad=0.,borderpad=0.,handlelength=0.2,frameon=False)
Ejemplo n.º 18
0
def plot_spikes_after_teach(ax):
    
    
    data_teach=core.get_data("fig3/2019-02-02_output_spikes_psth_teacher.npy")
    
    ax.scatter(np.nonzero(data_teach)[1],np.nonzero(data_teach)[0],color=core.label_to_color["teacher"],s=0.01)
    core.show_axis(ax)
    core.make_spines(ax)
    
    ax.set_xlabel(core.x_labels["spikes_teach"])
    ax.set_ylabel(core.y_labels["spikes_teach"])

    
    pass
Ejemplo n.º 19
0
def plot_attenuation_summary_perc(ax):
    
    ax.set_xlim([0.,11.])
    
    data_wchange = core.get_data('fig6/att_weight_change_perc.npy')
    data_dist = core.get_data('fig6/distances.npy')
    color=[core.label_to_color["attenuation_im"]]*np.shape(data_dist)[0]
    color[2]=core.label_to_color["attenuation_ldist"]
    color[-3]=core.label_to_color["attenuation_hdist"]
    core.show_axis(ax)
    core.make_spines(ax)

    ax.scatter(data_dist,data_wchange,color=color,s=core.linewidth["scatter"])
    ax.get_yaxis().get_major_formatter().set_scientific(False)#prevent exponent notation on axis
    ax.yaxis.set_major_formatter(ticker.FormatStrFormatter('%.2f'))#cut y axis ticks 2 digits behind floating point
    ticks = np.linspace(0.,50.,2.)
    ax.yaxis.set_ticks(ticks) 
    ax.set_xlabel(r"$d[\mu m]$")
    ax.set_ylabel(core.y_labels["weightchange_dend"])
    


    pass
Ejemplo n.º 20
0
        self.model = model_from_json(open(m_name + '.json').read())
        self.model.load_weights(m_name + '.h5')
        self.model.compile(loss=self.loss,
                           optimizer=self.opt(lr=self.lr),
                           metrics=['accuracy'])


if __name__ == "__main__":

    nb_epoch = 10
    batch_size = 256
    k_folds = 5

    # get some data
    X_train, Y_train, _, _ = core.get_data(60000, 10000, 10)

    # split training into folds
    X_folds = np.array_split(X_train, k_folds)
    Y_folds = np.array_split(Y_train, k_folds)

    # create the model
    Model = ModelDM(lr=.001,
                    img_rows=28,
                    img_cols=28,
                    img_channels=1,
                    n_l1=16,
                    n_l2=None,
                    dout=0,
                    n_filt=8,
                    opt='Adam',