예제 #1
0
def autocor(PSTH,N=None,T=20*br.ms,bin=None):
    if bin is None:
        bin = br.defaultclock.dt
    p = int(T/ bin)
    SAC = br.zeros(p)    
    if N is None:
        SAC[0] = br.mean(PSTH * PSTH)
    else: # correction to exclude self-coincidences
        PSTHnoself = br.clip(PSTH - 1. / (bin * N), 0*br.kHz, br.Inf*br.kHz)
        SAC[0] = br.mean(PSTH * PSTHnoself) * N / (N - 1.)
    SAC[1:] = [br.mean(PSTH[:-i] * PSTH[i:]) for i in range(1,p)]
    SAC = br.hstack((SAC[::-1], SAC[1:]))
    out = (br.arange(len(SAC)) - len(SAC) / 2) * bin    
    return out, SAC
예제 #2
0
def plot_average_membrane_potential(axes,
                                    population='E_non',
                                    group='non-selective',
                                    tmin=None,
                                    tmax=None,
                                    legend=True,
                                    title=True,
                                    namespace=namespace):
    # using formula:
    V_L = namespace['V_L']
    V_thr = namespace['V_thr']
    V_reset = namespace['V_reset']
    tau_m_E = namespace['tau_m_E']
    g_m_E = namespace['g_m_E']
    V_SS = V_L - net['st_' + population].I_syn.mean(axis=0) / (g_m_E)
    nu = net['r_' + population].smooth_rate('gaussian', 5 * b2.ms)
    V_avg = V_SS - (V_thr - V_reset) * nu * tau_m_E
    # using data:
    v_mean = b2.mean(net['st_' + population].v, axis=0)
    v_std = b2.std(net['st_' + population].v, axis=0)

    if tmin is None:
        tmin = net['r_' + population].t[0]
    if tmax is None:
        tmax = net['r_' + population].t[-1]
    mask = (net['r_I'].t >= tmin) & (net['r_I'].t <= tmax)

    true_line = axes.plot(net['r_' + population].t[mask] / b2.ms,
                          v_mean[mask] / b2.mV,
                          label='true avg.',
                          ls='--')
    colour = true_line[0].get_color()
    axes.fill_between(net['r_' + population].t[mask] / b2.ms,
                      (v_mean - v_std)[mask] / b2.mV,
                      (v_mean + v_std)[mask] / b2.mV,
                      alpha=0.6,
                      label=r'$\pm 1$ std',
                      color=colour)
    axes.fill_between(net['r_' + population].t[mask] / b2.ms,
                      (v_mean - 2 * v_std)[mask] / b2.mV,
                      (v_mean - v_std)[mask] / b2.mV,
                      alpha=0.3,
                      label=r'$\pm 2$ std',
                      color=colour)
    axes.fill_between(net['r_' + population].t[mask] / b2.ms,
                      (v_mean + 2 * v_std)[mask] / b2.mV,
                      (v_mean + v_std)[mask] / b2.mV,
                      alpha=0.3,
                      color=colour)

    axes.plot(net['r_' + population].t[mask] / b2.ms,
              V_avg[mask] / b2.mV,
              label='computed',
              color='darkorange',
              lw=1)
    if legend:
        axes.legend()
    axes.grid(alpha=0.5)
    if title:
        axes.set_title(r'Comparison of $\langle V \rangle$' +
                       f'\nGroup: {group}')
    return None