当前位置: 首页>>代码示例>>Python>>正文


Python NeuronGroup.v['rand()+<=+1']方法代码示例

本文整理汇总了Python中brian2.groups.neurongroup.NeuronGroup.v['rand()+<=+1']方法的典型用法代码示例。如果您正苦于以下问题:Python NeuronGroup.v['rand()+<=+1']方法的具体用法?Python NeuronGroup.v['rand()+<=+1']怎么用?Python NeuronGroup.v['rand()+<=+1']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在brian2.groups.neurongroup.NeuronGroup的用法示例。


在下文中一共展示了NeuronGroup.v['rand()+<=+1']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_state_variable_access_strings

# 需要导入模块: from brian2.groups.neurongroup import NeuronGroup [as 别名]
# 或者: from brian2.groups.neurongroup.NeuronGroup import v['rand()+<=+1'] [as 别名]
def test_state_variable_access_strings():
    for codeobj_class in codeobj_classes:
        G = NeuronGroup(10, 'v:volt', codeobj_class=codeobj_class)
        G.v = np.arange(10) * volt
        # Indexing with strings
        assert G.v['i==2'] == G.v[2]
        assert G.v_['i==2'] == G.v_[2]
        assert_equal(G.v['v >= 3*volt'], G.v[3:])
        assert_equal(G.v_['v >= 3*volt'], G.v_[3:])
        # Should also check for units
        assert_raises(DimensionMismatchError, lambda: G.v['v >= 3'])
        assert_raises(DimensionMismatchError, lambda: G.v['v >= 3*second'])

        # Setting with strings
        # --------------------
        # String value referring to i
        G.v = '2*i*volt'
        assert_equal(G.v[:], 2*np.arange(10)*volt)
        # String value referring to i
        G.v[:5] = '3*i*volt'
        assert_equal(G.v[:],
                     np.array([0, 3, 6, 9, 12, 10, 12, 14, 16, 18])*volt)

        G.v = np.arange(10) * volt
        # String value referring to a state variable
        G.v = '2*v'
        assert_equal(G.v[:], 2*np.arange(10)*volt)
        G.v[:5] = '2*v'
        assert_equal(G.v[:],
                     np.array([0, 4, 8, 12, 16, 10, 12, 14, 16, 18])*volt)

        G.v = np.arange(10) * volt
        # String value referring to state variables, i, and an external variable
        ext = 5*volt
        G.v = 'v + ext + (N + i)*volt'
        assert_equal(G.v[:], 2*np.arange(10)*volt + 15*volt)

        G.v = np.arange(10) * volt
        G.v[:5] = 'v + ext + (N + i)*volt'
        assert_equal(G.v[:],
                     np.array([15, 17, 19, 21, 23, 5, 6, 7, 8, 9])*volt)

        G.v = 'v + randn()*volt'  # only check that it doesn't raise an error
        G.v[:5] = 'v + randn()*volt'  # only check that it doesn't raise an error

        G.v = np.arange(10) * volt
        # String index using a random number
        G.v['rand() <= 1'] = 0*mV
        assert_equal(G.v[:], np.zeros(10)*volt)

        G.v = np.arange(10) * volt
        # String index referring to i and setting to a scalar value
        G.v['i>=5'] = 0*mV
        assert_equal(G.v[:], np.array([0, 1, 2, 3, 4, 0, 0, 0, 0, 0])*volt)
        # String index referring to a state variable
        G.v['v<3*volt'] = 0*mV
        assert_equal(G.v[:], np.array([0, 0, 0, 3, 4, 0, 0, 0, 0, 0])*volt)
        # String index referring to state variables, i, and an external variable
        ext = 2*volt
        G.v['v>=ext and i==(N-6)'] = 0*mV
        assert_equal(G.v[:], np.array([0, 0, 0, 3, 0, 0, 0, 0, 0, 0])*volt)

        G.v = np.arange(10) * volt
        # Strings for both condition and values
        G.v['i>=5'] = 'v*2'
        assert_equal(G.v[:], np.array([0, 1, 2, 3, 4, 10, 12, 14, 16, 18])*volt)
        G.v['v>=5*volt'] = 'i*volt'
        assert_equal(G.v[:], np.arange(10)*volt)
开发者ID:msGenDev,项目名称:brian2,代码行数:70,代码来源:test_neurongroup.py

示例2: test_state_variable_access_strings

# 需要导入模块: from brian2.groups.neurongroup import NeuronGroup [as 别名]
# 或者: from brian2.groups.neurongroup.NeuronGroup import v['rand()+<=+1'] [as 别名]
def test_state_variable_access_strings():
    G = NeuronGroup(10, '''v : volt
                           dv_ref/dt = -v_ref/(10*ms) : 1 (unless refractory)''',
                    threshold='v_ref>1', reset='v_ref=1', refractory=1*ms)
    G.v = np.arange(10) * volt
    # Indexing with strings
    assert G.v['i==2'] == G.v[2]
    assert G.v_['i==2'] == G.v_[2]
    assert_equal(G.v['v >= 3*volt'], G.v[3:])
    assert_equal(G.v_['v >= 3*volt'], G.v_[3:])
    # Should also check for units
    assert_raises(DimensionMismatchError, lambda: G.v['v >= 3'])
    assert_raises(DimensionMismatchError, lambda: G.v['v >= 3*second'])

    # Setting with strings
    # --------------------
    # String value referring to i
    G.v = '2*i*volt'
    assert_equal(G.v[:], 2*np.arange(10)*volt)
    # String value referring to i
    G.v[:5] = '3*i*volt'
    assert_equal(G.v[:],
                 np.array([0, 3, 6, 9, 12, 10, 12, 14, 16, 18])*volt)

    G.v = np.arange(10) * volt

    # Conditional write variable
    G.v_ref = '2*i'
    assert_equal(G.v_ref[:], 2*np.arange(10))

    # String value referring to a state variable
    G.v = '2*v'
    assert_equal(G.v[:], 2*np.arange(10)*volt)
    G.v[:5] = '2*v'
    assert_equal(G.v[:],
                 np.array([0, 4, 8, 12, 16, 10, 12, 14, 16, 18])*volt)

    G.v = np.arange(10) * volt
    # String value referring to state variables, i, and an external variable
    ext = 5*volt
    G.v = 'v + ext + (N + i)*volt'
    assert_equal(G.v[:], 2*np.arange(10)*volt + 15*volt)

    G.v = np.arange(10) * volt
    G.v[:5] = 'v + ext + (N + i)*volt'
    assert_equal(G.v[:],
                 np.array([15, 17, 19, 21, 23, 5, 6, 7, 8, 9])*volt)

    G.v = 'v + randn()*volt'  # only check that it doesn't raise an error
    G.v[:5] = 'v + randn()*volt'  # only check that it doesn't raise an error

    G.v = np.arange(10) * volt
    # String index using a random number
    G.v['rand() <= 1'] = 0*mV
    assert_equal(G.v[:], np.zeros(10)*volt)

    G.v = np.arange(10) * volt
    # String index referring to i and setting to a scalar value
    G.v['i>=5'] = 0*mV
    assert_equal(G.v[:], np.array([0, 1, 2, 3, 4, 0, 0, 0, 0, 0])*volt)
    # String index referring to a state variable
    G.v['v<3*volt'] = 0*mV
    assert_equal(G.v[:], np.array([0, 0, 0, 3, 4, 0, 0, 0, 0, 0])*volt)
    # String index referring to state variables, i, and an external variable
    ext = 2*volt
    G.v['v>=ext and i==(N-6)'] = 0*mV
    assert_equal(G.v[:], np.array([0, 0, 0, 3, 0, 0, 0, 0, 0, 0])*volt)

    G.v = np.arange(10) * volt
    # Strings for both condition and values
    G.v['i>=5'] = 'v*2'
    assert_equal(G.v[:], np.array([0, 1, 2, 3, 4, 10, 12, 14, 16, 18])*volt)
    G.v['v>=5*volt'] = 'i*volt'
    assert_equal(G.v[:], np.arange(10)*volt)
    G.v['i<=5'] = '(100 + rand())*volt'
    assert_equal(G.v[6:], np.arange(4)*volt + 6*volt)  # unchanged
    assert all(G.v[:6] >= 100*volt)
    assert all(G.v[:6] <= 101*volt)
    assert np.var(G.v_[:6]) > 0
开发者ID:rcaze,项目名称:brian2,代码行数:81,代码来源:test_neurongroup.py


注:本文中的brian2.groups.neurongroup.NeuronGroup.v['rand()+<=+1']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。