Beispiel #1
0
def act(activation, idx):
    activation = activation.clip(0, 1)
    l_idx = b.arange(len(idx), step=2)
    r_idx = l_idx + 1

    a_avg = (activation[l_idx] + activation[r_idx]) / 2

    l_idx = b.arange(len(a_avg), step=2)
    r_idx = l_idx + 1

    theta = (a_avg[l_idx] - a_avg[r_idx]) * theta_max
    e.step(theta)
    e.render()
    return activation
Beispiel #2
0
def inp_rates(idx):
    la, ra = e.test_inp()
    la = la.repeat(2)
    ra = ra.repeat(2)
    l_idx = b.arange(len(idx), step=2)
    r_idx = l_idx + 1
    r = np.zeros(len(idx))
    r[l_idx] = la
    r[r_idx] = ra
    return r * b.Hz
Beispiel #3
0
def visualise_connectivity(S):
    Ns = len(S.source)
    Nt = len(S.target)
    b.figure(figsize=(10, 4))
    b.subplot(121)
    b.plot(b.zeros(Ns), b.arange(Ns), 'ok', ms=10)
    b.plot(b.ones(Nt), b.arange(Nt), 'ok', ms=10)
    for i, j in zip(S.i, S.j):
        b.plot([0, 1], [i, j], '-k')
    b.xticks([0, 1], ['Source', 'Target'])
    b.ylabel('Neuron index')
    b.xlim(-0.1, 1.1)
    b.ylim(-1, max(Ns, Nt))
    b.subplot(122)
    b.plot(S.i, S.j, 'ok')
    b.xlim(-1, Ns)
    b.ylim(-1, Nt)
    b.xlabel('Source neuron index')
    b.ylabel('Target neuron index')
Beispiel #4
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
Beispiel #5
0
def test_arange_linspace():
    # For dimensionless values, the unit-safe functions should give the same results
    assert_equal(brian2.arange(5), np.arange(5))
    assert_equal(brian2.arange(1, 5), np.arange(1, 5))
    assert_equal(brian2.arange(10, step=2), np.arange(10, step=2))
    assert_equal(brian2.arange(0, 5, 0.5), np.arange(0, 5, 0.5))
    assert_equal(brian2.linspace(0, 1), np.linspace(0, 1))
    assert_equal(brian2.linspace(0, 1, 10), np.linspace(0, 1, 10))

    # Make sure units are checked
    with pytest.raises(DimensionMismatchError):
        brian2.arange(1 * mV, 5)
    with pytest.raises(DimensionMismatchError):
        brian2.arange(1 * mV, 5 * mV)
    with pytest.raises(DimensionMismatchError):
        brian2.arange(1, 5 * mV)
    with pytest.raises(DimensionMismatchError):
        brian2.arange(1 * mV, 5 * ms)
    with pytest.raises(DimensionMismatchError):
        brian2.arange(1 * mV, 5 * mV, step=1 * ms)
    with pytest.raises(DimensionMismatchError):
        brian2.arange(1 * ms, 5 * mV)

    # Check correct functioning with units
    assert_quantity(brian2.arange(5 * mV, step=1 * mV),
                    float(mV) * np.arange(5, step=1), mV)
    assert_quantity(brian2.arange(1 * mV, 5 * mV, 1 * mV),
                    float(mV) * np.arange(1, 5, 1), mV)
    assert_quantity(brian2.linspace(1 * mV, 2 * mV),
                    float(mV) * np.linspace(1, 2), mV)

    # Check errors for arange with incorrect numbers of arguments/duplicate arguments
    with pytest.raises(TypeError):
        brian2.arange()
    with pytest.raises(TypeError):
        brian2.arange(0, 5, 1, 0)
    with pytest.raises(TypeError):
        brian2.arange(0, stop=1)
    with pytest.raises(TypeError):
        brian2.arange(0, 5, stop=1)
    with pytest.raises(TypeError):
        brian2.arange(0, 5, start=1)
    with pytest.raises(TypeError):
        brian2.arange(0, 5, 1, start=1)
    with pytest.raises(TypeError):
        brian2.arange(0, 5, 1, stop=2)
    with pytest.raises(TypeError):
        brian2.arange(0, 5, 1, step=2)
Beispiel #6
0
def test_arange_linspace():
    # For dimensionless values, the unit-safe functions should give the same results
    assert_equal(brian2.arange(5), np.arange(5))
    assert_equal(brian2.arange(1, 5), np.arange(1, 5))
    assert_equal(brian2.arange(10, step=2), np.arange(10, step=2))
    assert_equal(brian2.arange(0, 5, 0.5), np.arange(0, 5, 0.5))
    assert_equal(brian2.linspace(0, 1), np.linspace(0, 1))
    assert_equal(brian2.linspace(0, 1, 10), np.linspace(0, 1, 10))

    # Make sure units are checked
    assert_raises(DimensionMismatchError, lambda: brian2.arange(1*mV, 5))
    assert_raises(DimensionMismatchError, lambda: brian2.arange(1*mV, 5*mV))
    assert_raises(DimensionMismatchError, lambda: brian2.arange(1, 5*mV))
    assert_raises(DimensionMismatchError, lambda: brian2.arange(1*mV, 5*ms))
    assert_raises(DimensionMismatchError, lambda: brian2.arange(1*mV, 5*mV, step=1*ms))
    assert_raises(DimensionMismatchError, lambda: brian2.arange(1*ms, 5*mV))

    # Check correct functioning with units
    assert_quantity(brian2.arange(5*mV, step=1*mV), float(mV)*np.arange(5, step=1), mV)
    assert_quantity(brian2.arange(1*mV, 5*mV, 1*mV), float(mV)*np.arange(1, 5, 1), mV)
    assert_quantity(brian2.linspace(1*mV, 2*mV), float(mV)*np.linspace(1, 2), mV)

    # Check errors for arange with incorrect numbers of arguments/duplicate arguments
    assert_raises(TypeError, lambda: brian2.arange())
    assert_raises(TypeError, lambda: brian2.arange(0, 5, 1, 0))
    assert_raises(TypeError, lambda: brian2.arange(0, stop=1))
    assert_raises(TypeError, lambda: brian2.arange(0, 5, stop=1))
    assert_raises(TypeError, lambda: brian2.arange(0, 5, start=1))
    assert_raises(TypeError, lambda: brian2.arange(0, 5, 1, start=1))
    assert_raises(TypeError, lambda: brian2.arange(0, 5, 1, stop=2))
    assert_raises(TypeError, lambda: brian2.arange(0, 5, 1, step=2))