Ejemplo n.º 1
0
def run_example():

    data_dir = join(split(__file__)[0], 'data')
    data_file = 'STRFs_ChirpsBlocks_IC_2012-01-31_50dB_chan01_unit01.h5'

    block = load_data(data_dir, data_file)
    X, Y, rfsize, axes, fs = convert_data(block)

    # Add some models
    n_jobs = 3  # number of processes used for hyperparameter optimization
    n_griditer = 3
    models = []

    model = STA()
    models.append(model)

    model = GaussianGLM(n_griditer=n_griditer,
                        n_jobs=n_jobs,
                        optimizer='ridge')
    models.append(model)

    model = CbRF(n_griditer=n_griditer, n_jobs=n_jobs)
    models.append(model)

    model = PoissonGLM(n_griditer=n_griditer, n_jobs=n_jobs)
    models.append(model)

    # Fit models
    for model in models:
        print 50 * '-'
        print "Fitting model:", model.name
        print 50 * '-'
        model.fit(X, Y)

    # Plot STRFs
    fig, axarr = plt.subplots(nrows=1,
                              ncols=len(models),
                              sharex=True,
                              sharey=True)
    for i, model in enumerate(models):

        ax = axarr[i]
        ax.set_title(model.name)

        W = np.reshape(model.coef_, rfsize)
        rf = STRF(W,
                  fs,
                  time=axes[0].values.base,
                  frequency=axes[1].values.base)
        rf.show(ax=ax, show_now=False, colorbar=False)

        if i > 0:
            ax.set_ylabel('')

    fig.set_size_inches(8, 2.5)
    fig.tight_layout()
    plt.show()
Ejemplo n.º 2
0
def run_example():

    data_dir = join(split(__file__)[0], 'data')
    data_file = 'STRFs_ChirpsBlocks_IC_2012-01-31_50dB_chan01_unit01.h5'

    block = load_data(data_dir, data_file)
    X, Y, rfsize, axes, fs = convert_data(block)

    # Add some models
    n_jobs = 3  # number of processes used for hyperparameter optimization
    n_griditer = 3
    models = []

    model = STA()
    models.append(model)

    model = GaussianGLM(n_griditer=n_griditer, n_jobs=n_jobs,
                        optimizer='ridge')
    models.append(model)

    model = CbRF(n_griditer=n_griditer, n_jobs=n_jobs)
    models.append(model)

    model = PoissonGLM(n_griditer=n_griditer, n_jobs=n_jobs)
    models.append(model)

    # Fit models
    for model in models:
        print 50 * '-'
        print "Fitting model:", model.name
        print 50 * '-'
        model.fit(X, Y)

    # Plot STRFs
    fig, axarr = plt.subplots(nrows=1, ncols=len(models), sharex=True,
                              sharey=True)
    for i, model in enumerate(models):

        ax = axarr[i]
        ax.set_title(model.name)

        W = np.reshape(model.coef_, rfsize)
        rf = STRF(W, fs, time=axes[0].values.base,
                  frequency=axes[1].values.base)
        rf.show(ax=ax, show_now=False, colorbar=False)

        if i > 0:
            ax.set_ylabel('')

    fig.set_size_inches(8, 2.5)
    fig.tight_layout()
    plt.show()
Ejemplo n.º 3
0
def run_example():

    t_spikefilt = 0.05

    data_dir = join(split(__file__)[0], 'data')
    data_file = 'STRFs_ChirpsBlocks_IC_2012-01-31_50dB_chan01_unit01.h5'
#    data_file = 'STRFs_ChirpsBlocks_IC_2012-04-26_Pos_02_30dB_chan01_unit01.h5'

    block = load_data(data_dir, data_file)
    X, Y, rfsize, axes, fs, n_spikefilt = convert_data(block, t_spikefilt)

    # Add some models
    n_jobs = 3  # number of workers used for hyperparameter optimization
    n_griditer = 3
    models = []

#    model = STA(n_postfilt=n_postfilt)
#    models.append(model)

#    model = GaussianGLM(n_griditer=n_griditer, n_jobs=n_jobs,
#                        optimizer='ridge')
#    models.append(model)

    model = CbRF(n_griditer=n_griditer, n_jobs=n_jobs, n_spikefilt=n_spikefilt)
    models.append(model)
#
#    model = PoissonGLM(n_griditer=n_griditer, n_jobs=n_jobs)
#    models.append(model)

    # Fit models
    for model in models:
        print 50 * '-'
        print "Fitting model:", model.name
        print 50 * '-'
        model.fit(X, Y)

    # Plot STRFs
    fig, axarr = plt.subplots(nrows=len(models), ncols=1+int(n_spikefilt > 0))
    axarr = np.atleast_2d(axarr)
    for i, model in enumerate(models):

        ax = axarr[i, 0]
        ax.set_title(model.name)

        W = np.reshape(model.get_weights(), rfsize)
        rf = STRF(W, fs, time=axes[0].values.base,
                  frequency=axes[1].values.base)
        rf.show(ax=ax, show_now=False, colorbar=False)

        if n_spikefilt > 0:
            # Post-spike filter
            ax = axarr[i, 1]
            xx = np.linspace(-t_spikefilt, 0, n_spikefilt) * 1000
            h = model.get_spikefilt()
            ax.plot(xx, h)
            ax.set_xlabel('Time (ms)')
            ax.set_ylabel('Gain (a.u.)')

    fig.set_size_inches(8, 4)
    fig.tight_layout()
    plt.show()