示例#1
0
def show_cell_density(rd, xran=(0, 143000),
                      overlay=False):
    """
    rd is the result of cell_resp_d.  xran is the x range of the plot
    Will glitch if the various conditions in rd used different stimulus sets -
    avoid this. If overlay, plot all data in one subplot in different colors

    """
    f = plt.figure(1)
    plt.clf()
    cols = 'brgkcy'
    x = np.arange(xran[0], xran[1])
    pad = .9
    conds = rd.keys(0, 'cond')
    stims = rd[conds[0]].keys(sort=cmp)
    for i, sn in enumerate(stims):
        for j, cn in enumerate(conds):
            if overlay:
                col = cols[j]
                siz = 10 - 2 * j
            else:
                plt.subplot(1, len(conds), j + 1)
                col = 'k'
                siz = 6
            sf = rd[cn][sn]['responses']
            mm = evaluate(rd[cn][sn], x)
            if mm.max() - mm.min() > 0:
                mm = pad * mm / mm.max()
            plt.plot(x, mm + i, linewidth=3, color=col)
            sp = pad / (len(sf) + 1)
            for k in range(len(sf)):
                if sf[k]:
                    y = np.ones(len(sf[k])) * (k + 1) * sp + i
                    plt.plot(sf[k], y, '.', color=col, markersize=siz)
    if not overlay:
        plt.subplot(1, len(conds), 1)
    plt.xlim(xran)
    plt.yticks(range(len(stims)), stims)
    if not overlay:
        f.subplots_adjust(left=.04, right=.99, bottom=.03, top=.94, wspace=.05)
        for i in range(2, len(conds) + 1):
            sp = plt.subplot(1, len(conds), i)
            plt.xlim(xran)
            sp.yaxis.set_visible(False)
            sp.xaxis.set_visible(False)
    f.canvas.draw()
示例#2
0
def likelihood(gmm, st, mode='log'):
    """
    returns a measure of the probability of spike train st under model gmm.
    mode may be:

    log: conventional log likelihood. This measure makes the fewest assumptions,
        but is also monotonically decreasing with len(st) (each actual event is
        improbable, so any possible long event sequence is massively improbable)
    av: log of the average of the activation for each spike. Essentially assumes
        all spikes are independent. A spike train with many spikes, a few of
        which are in strongly excluded regions of the model, may still have
        relatively good likelihood.
    la: the log measure, devided by the length of the spike train.

    """
    acts = evaluate(gmm, st)
    if mode == 'log':
        return np.log(acts).sum()
    elif mode == 'av':
        return np.log(acts.mean())
    elif mode == 'la':
        return np.log(acts).sum() / len(st)