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


Python Network.run方法代码示例

本文整理汇总了Python中brian2.core.network.Network.run方法的典型用法代码示例。如果您正苦于以下问题:Python Network.run方法的具体用法?Python Network.run怎么用?Python Network.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在brian2.core.network.Network的用法示例。


在下文中一共展示了Network.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_custom_events

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_custom_events():
    G = NeuronGroup(2, '''event_time1 : second
                          event_time2 : second''',
                    events={'event1': 't>=i*ms and t<i*ms+dt',
                            'event2': 't>=(i+1)*ms and t<(i+1)*ms+dt'})
    G.run_on_event('event1', 'event_time1 = t')
    G.run_on_event('event2', 'event_time2 = t')
    net = Network(G)
    net.run(2.1*ms)
    assert_allclose(G.event_time1[:], [0, 1]*ms)
    assert_allclose(G.event_time2[:], [1, 2]*ms)
开发者ID:appusom,项目名称:brian2,代码行数:13,代码来源:test_neurongroup.py

示例2: test_stochastic_variable

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_stochastic_variable():
    '''
    Test that a NeuronGroup with a stochastic variable can be simulated. Only
    makes sure no error occurs.
    '''
    tau = 10 * ms
    for codeobj_class in codeobj_classes:
        G = NeuronGroup(1, 'dv/dt = -v/tau + xi*tau**-0.5: 1',
                        codeobj_class=codeobj_class)
        net = Network(G)
        net.run(defaultclock.dt)
开发者ID:msGenDev,项目名称:brian2,代码行数:13,代码来源:test_neurongroup.py

示例3: test_random_vector_values

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_random_vector_values():
    # Make sure that the new "loop-invariant optimisation" does not pull out
    # the random number generation and therefore makes all neurons receiving
    # the same values
    tau = 10*ms
    G = NeuronGroup(100, 'dv/dt = -v / tau + xi*tau**-0.5: 1')
    G.v[:] = 'rand()'
    assert np.var(G.v[:]) > 0
    G.v[:] = 0
    net = Network(G)
    net.run(defaultclock.dt)
    assert np.var(G.v[:]) > 0
开发者ID:appusom,项目名称:brian2,代码行数:14,代码来源:test_neurongroup.py

示例4: test_threshold_reset

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_threshold_reset():
    '''
    Test that threshold and reset work in the expected way.
    '''
    for codeobj_class in codeobj_classes:
        # Membrane potential does not change by itself
        G = NeuronGroup(3, 'dv/dt = 0 / second : 1',
                        threshold='v > 1', reset='v=0.5', codeobj_class=codeobj_class)
        G.v = np.array([0, 1, 2])
        net = Network(G)
        net.run(defaultclock.dt)
        assert_equal(G.v[:], np.array([0, 1, 0.5]))
开发者ID:msGenDev,项目名称:brian2,代码行数:14,代码来源:test_neurongroup.py

示例5: test_stochastic_variable_multiplicative

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_stochastic_variable_multiplicative():
    '''
    Test that a NeuronGroup with multiplicative noise can be simulated. Only
    makes sure no error occurs.
    '''
    for codeobj_class in codeobj_classes:
        mu = 0.5/second # drift
        sigma = 0.1/second #diffusion
        G = NeuronGroup(1, 'dX/dt = (mu - 0.5*second*sigma**2)*X + X*sigma*xi*second**.5: 1',
                        codeobj_class=codeobj_class)
        net = Network(G)
        net.run(defaultclock.dt)
开发者ID:msGenDev,项目名称:brian2,代码行数:14,代码来源:test_neurongroup.py

示例6: test_linked_variable_scalar

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_linked_variable_scalar():
    '''
    Test linked variable from a size 1 group.
    '''
    G1 = NeuronGroup(1, 'dx/dt = -x / (10*ms) : 1')
    G2 = NeuronGroup(10, '''dy/dt = (-y + x) / (20*ms) : 1
                            x : 1 (linked)''')
    G1.x = 1
    G2.y = np.linspace(0, 1, 10)
    G2.x = linked_var(G1.x)
    mon = StateMonitor(G2, 'y', record=True)
    net = Network(G1, G2, mon)
    net.run(10*ms)
开发者ID:msGenDev,项目名称:brian2,代码行数:15,代码来源:test_neurongroup.py

示例7: test_aliasing_in_statements

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_aliasing_in_statements():
    '''
    Test an issue around variables aliasing other variables (#259)
    '''
    runner_code = '''x_1 = x_0
                     x_0 = -1'''
    g = NeuronGroup(1, model='''x_0 : 1
                                x_1 : 1 ''', codeobj_class=NumpyCodeObject)
    custom_code_obj = g.custom_operation(runner_code)
    net = Network(g, custom_code_obj)
    net.run(defaultclock.dt)
    assert_equal(g.x_0_[:], np.array([-1]))
    assert_equal(g.x_1_[:], np.array([0]))
开发者ID:msGenDev,项目名称:brian2,代码行数:15,代码来源:test_neurongroup.py

示例8: test_linked_variable_correct

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_linked_variable_correct():
    '''
    Test correct uses of linked variables.
    '''
    tau = 10*ms
    G1 = NeuronGroup(10, 'dv/dt = -v / tau : volt')
    G1.v = np.linspace(0*mV, 20*mV, 10)
    G2 = NeuronGroup(10, 'v : volt (linked)')
    G2.v = linked_var(G1.v)
    mon1 = StateMonitor(G1, 'v', record=True)
    mon2 = StateMonitor(G2, 'v', record=True)
    net = Network(G1, G2, mon1, mon2)
    net.run(10*ms)
    assert_equal(mon1.v[:, :], mon2.v[:, :])
开发者ID:msGenDev,项目名称:brian2,代码行数:16,代码来源:test_neurongroup.py

示例9: test_incomplete_namespace

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_incomplete_namespace():
    '''
    Test that the namespace does not have to be complete at creation time.
    '''
    # This uses tau which is not defined yet (explicit namespace)
    G = NeuronGroup(1, 'dv/dt = -v/tau : 1', namespace={})
    G.namespace['tau'] = 10*ms
    net = Network(G)
    net.run(0*ms)

    # This uses tau which is not defined yet (implicit namespace)
    G = NeuronGroup(1, 'dv/dt = -v/tau : 1')
    tau = 10*ms
    net = Network(G)
    net.run(0*ms)
开发者ID:appusom,项目名称:brian2,代码行数:17,代码来源:test_neurongroup.py

示例10: test_custom_events_schedule

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_custom_events_schedule():
    # In the same time step: event2 will be checked and its code executed
    # before event1 is checked and its code executed
    G = NeuronGroup(2, '''x : 1
                          event_time : second''',
                    events={'event1': 'x>0',
                            'event2': 't>=(i+1)*ms and t<(i+1)*ms+dt'})
    G.set_event_schedule('event1', when='after_resets')
    G.run_on_event('event2', 'x = 1', when='resets')
    G.run_on_event('event1',
                   '''event_time = t
                      x = 0''', when='after_resets', order=1)
    net = Network(G)
    net.run(2.1*ms)
    assert_allclose(G.event_time[:], [1, 2]*ms)
开发者ID:appusom,项目名称:brian2,代码行数:17,代码来源:test_neurongroup.py

示例11: test_namespace_errors

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_namespace_errors():

    # model equations use unknown identifier
    G = NeuronGroup(1, 'dv/dt = -v/tau : 1')
    net = Network(G)
    assert_raises(KeyError, lambda: net.run(1*ms))

    # reset uses unknown identifier
    G = NeuronGroup(1, 'dv/dt = -v/tau : 1', threshold='False', reset='v = v_r')
    net = Network(G)
    assert_raises(KeyError, lambda: net.run(1*ms))

    # threshold uses unknown identifier
    G = NeuronGroup(1, 'dv/dt = -v/tau : 1', threshold='v > v_th')
    net = Network(G)
    assert_raises(KeyError, lambda: net.run(1*ms))
开发者ID:appusom,项目名称:brian2,代码行数:18,代码来源:test_neurongroup.py

示例12: test_aliasing_in_statements

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_aliasing_in_statements():
    '''
    Test an issue around variables aliasing other variables (#259)
    '''
    if prefs.codegen.target != 'numpy':
        raise SkipTest('numpy-only test')

    runner_code = '''x_1 = x_0
                     x_0 = -1'''
    g = NeuronGroup(1, model='''x_0 : 1
                                x_1 : 1 ''')
    g.run_regularly(runner_code)
    net = Network(g)
    net.run(defaultclock.dt)
    assert_equal(g.x_0_[:], np.array([-1]))
    assert_equal(g.x_1_[:], np.array([0]))
开发者ID:appusom,项目名称:brian2,代码行数:18,代码来源:test_neurongroup.py

示例13: test_referred_scalar_variable

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_referred_scalar_variable():
    '''
    Test the correct handling of referred scalar variables in subexpressions
    '''
    for codeobj_class in codeobj_classes:
        G = NeuronGroup(10, '''out = sin(2*pi*t*freq) + x: 1
                               x : 1
                               freq : Hz (shared)''',
                        codeobj_class=codeobj_class)
        G.freq = 1*Hz
        G.x = np.arange(10)
        G2 = NeuronGroup(10, '', codeobj_class=codeobj_class)
        G2.variables.add_reference('out', G)
        net = Network(G, G2)
        net.run(.25*second)
        assert_allclose(G2.out[:], np.arange(10)+1)
开发者ID:msGenDev,项目名称:brian2,代码行数:18,代码来源:test_neurongroup.py

示例14: test_scalar_variable

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_scalar_variable():
    '''
    Test the correct handling of scalar variables
    '''
    tau = 10*ms
    G = NeuronGroup(10, '''E_L : volt (shared)
                           s2 : 1 (shared)
                           dv/dt = (E_L - v) / tau : volt''')
    # Setting should work in these ways
    G.E_L = -70*mV
    assert_allclose(G.E_L[:], -70*mV)
    G.E_L[:] = -60*mV
    assert_allclose(G.E_L[:], -60*mV)
    G.E_L = 'E_L + s2*mV - 10*mV'
    assert_allclose(G.E_L[:], -70*mV)
    G.E_L[:] = '-75*mV'
    assert_allclose(G.E_L[:], -75*mV)
    net = Network(G)
    net.run(defaultclock.dt)
开发者ID:appusom,项目名称:brian2,代码行数:21,代码来源:test_neurongroup.py

示例15: test_linked_subexpression

# 需要导入模块: from brian2.core.network import Network [as 别名]
# 或者: from brian2.core.network.Network import run [as 别名]
def test_linked_subexpression():
    '''
    Test a subexpression referring to a linked variable.
    '''
    G = NeuronGroup(2, 'dv/dt = 100*Hz : 1',
                    threshold='v>1', reset='v=0')
    G.v = [0, .5]
    G2 = NeuronGroup(10, '''I = clip(x, 0, inf) : 1
                            x : 1 (linked) ''')

    G2.x = linked_var(G.v, index=np.array([0, 1]).repeat(5))
    mon = StateMonitor(G2, 'I', record=True)

    net = Network(G, G2, mon)
    net.run(5*ms)

    # Due to the linking, the first 5 and the second 5 recorded I vectors should
    # be identical
    assert all((all(mon[i].I == mon[0].I) for i in xrange(5)))
    assert all((all(mon[i+5].I == mon[5].I) for i in xrange(5)))
开发者ID:msGenDev,项目名称:brian2,代码行数:22,代码来源:test_neurongroup.py


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