• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python runtime.get_nodenet函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中micropsi_core.runtime.get_nodenet函数的典型用法代码示例。如果您正苦于以下问题:Python get_nodenet函数的具体用法?Python get_nodenet怎么用?Python get_nodenet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: fixed_nodenet

def fixed_nodenet(request, test_world, engine):
    """
    A test nodenet filled with some example data (nodenet_data.py)
    Structure:

          ->  A1 ->  A2
        /
       S                     ACTA
        \
          ->  B1 ->  B2

    S: Sensor, brightness_l
    A1: Pipe
    A2: Pipe
    B1: Pipe
    B2: Pipe
    ACTA: Activator, por
    """
    from micropsi_core.tests.nodenet_data import fixed_nodenet_data
    if engine == "theano_engine":
        fixed_nodenet_data = fixed_nodenet_data.replace('Root', 's0001')
    success, uid = micropsi.new_nodenet("Fixednet", engine=engine, worldadapter="Braitenberg", owner="Pytest User", world_uid=test_world, uid='fixed_test_nodenet')
    micropsi.get_nodenet(uid)
    micropsi.merge_nodenet(uid, fixed_nodenet_data, keep_uids=True)
    micropsi.save_nodenet(uid)
    yield uid
    try:
        micropsi.delete_nodenet(uid)
    except:
        pass
开发者ID:joschabach,项目名称:micropsi2,代码行数:30,代码来源:conftest.py


示例2: fixed_nodenet

def fixed_nodenet(request, test_world, engine):
    from micropsi_core.tests.nodenet_data import fixed_nodenet_data
    if engine == "theano_engine":
        fixed_nodenet_data = fixed_nodenet_data.replace('Root', 's0001')
    success, uid = micropsi.new_nodenet("Fixednet", engine=engine, worldadapter="Braitenberg", owner="Pytest User", world_uid=test_world, uid='fixed_test_nodenet')
    micropsi.get_nodenet(uid)
    micropsi.merge_nodenet(uid, fixed_nodenet_data, keep_uids=True)
    micropsi.save_nodenet(uid)
    return uid
开发者ID:ianupright,项目名称:micropsi2,代码行数:9,代码来源:conftest.py


示例3: fixed_nodenet

def fixed_nodenet(request, test_world):
    from micropsi_core.tests.nodenet_data import fixed_nodenet_data
    success, uid = micropsi.new_nodenet("Fixednet", "Braitenberg", owner="Pytest User", world_uid=test_world, uid='fixed_test_nodenet')
    micropsi.get_nodenet(uid)
    micropsi.merge_nodenet(uid, fixed_nodenet_data)
    def fin():
        if DELETE_TEST_FILES_ON_EXIT:
            micropsi.delete_nodenet(uid)
    request.addfinalizer(fin)
    return uid
开发者ID:pBartels,项目名称:micropsi2,代码行数:10,代码来源:conftest.py


示例4: test_clone_nodes_copies_gate_params

def test_clone_nodes_copies_gate_params(fixed_nodenet):
    nodenet = micropsi.get_nodenet(fixed_nodenet)
    micropsi.set_gate_parameters(fixed_nodenet, 'A1', 'gen', {'decay': 0.1})
    success, result = micropsi.clone_nodes(fixed_nodenet, ['A1'], 'internal')
    assert success
    copy = nodenet.get_node(result['nodes'][0]['uid'])
    assert copy.get_gate_parameters()['gen']['decay'] == 0.1
开发者ID:hyperdrive,项目名称:micropsi2,代码行数:7,代码来源:test_runtime_nodenet_basics.py


示例5: test_modulators_sensor_actor_connection

def test_modulators_sensor_actor_connection(test_nodenet, test_world):
    nodenet = micropsi.get_nodenet(test_nodenet)
    micropsi.set_nodenet_properties(test_nodenet, worldadapter="Braitenberg", world_uid=test_world)
    res, s1_id = micropsi.add_node(test_nodenet, "Sensor", [10, 10], None, name="brightness_l", parameters={'datasource': 'brightness_l'})
    res, s2_id = micropsi.add_node(test_nodenet, "Sensor", [20, 20], None, name="emo_activation", parameters={'datasource': 'emo_activation'})
    res, a1_id = micropsi.add_node(test_nodenet, "Actor", [30, 30], None, name="engine_l", parameters={'datatarget': 'engine_l'})
    res, a2_id = micropsi.add_node(test_nodenet, "Actor", [40, 40], None, name="base_importance_of_intention", parameters={'datatarget': 'base_importance_of_intention'})
    res, r1_id = micropsi.add_node(test_nodenet, "Register", [10, 30], None, name="r1")
    res, r2_id = micropsi.add_node(test_nodenet, "Register", [10, 30], None, name="r2")
    s1 = nodenet.get_node(s1_id)
    s2 = nodenet.get_node(s2_id)
    r1 = nodenet.get_node(r1_id)
    r2 = nodenet.get_node(r2_id)
    s2.set_gate_parameter('gen', 'maximum', 999)
    micropsi.add_link(test_nodenet, r1_id, 'gen', a1_id, 'gen')
    micropsi.add_link(test_nodenet, r2_id, 'gen', a2_id, 'gen')
    r1.activation = 0.3
    r2.activation = 0.7
    emo_val = nodenet.get_modulator("emo_activation")

    # patch reset method, to check if datatarget was written
    def nothing():
        pass
    nodenet.worldadapter_instance.reset_datatargets = nothing

    nodenet.step()
    assert round(nodenet.worldadapter_instance.datatargets['engine_l'], 3) == 0.3
    assert round(s1.activation, 3) == round(nodenet.worldadapter_instance.get_datasource_value('brightness_l'), 3)
    assert round(s2.activation, 3) == round(emo_val, 3)
    assert round(nodenet.get_modulator('base_importance_of_intention'), 3) == 0.7
    assert round(nodenet.worldadapter_instance.datatargets['engine_l'], 3) == 0.3
    emo_val = nodenet.get_modulator("emo_activation")
    nodenet.step()
    assert round(s2.activation, 3) == round(emo_val, 3)
开发者ID:joschabach,项目名称:micropsi2,代码行数:34,代码来源:test_runtime_nodenet_basics.py


示例6: test_unlink_slot

def test_unlink_slot(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    node = netapi.create_node("Pipe", None)
    pipe1 = netapi.create_node("Pipe", None)
    pipe2 = netapi.create_node("Pipe", None)
    netapi.link_with_reciprocal(node, pipe1, 'subsur')
    netapi.link_with_reciprocal(node, pipe2, 'subsur')
    netapi.link(pipe1, 'gen', node, 'por')
    netapi.link(pipe2, 'gen', node, 'por')
    netapi.link(pipe1, 'sur', node, 'por')
    micropsi.save_nodenet(test_nodenet)
    netapi.unlink_slot(node, 'por')
    assert node.get_slot('por').empty
    assert not node.get_slot('sur').empty
    micropsi.revert_nodenet(test_nodenet)
    netapi = micropsi.nodenets[test_nodenet].netapi
    node = netapi.get_node(node.uid)
    netapi.unlink_slot(node, 'por', source_node_uid=pipe1.uid)
    assert len(node.get_slot('por').get_links()) == 1
    assert node.get_slot('por').get_links()[0].source_node.uid == pipe2.uid
    micropsi.revert_nodenet(test_nodenet)
    netapi = micropsi.nodenets[test_nodenet].netapi
    node = netapi.get_node(node.uid)
    netapi.unlink_slot(node, 'por', source_gate_name='sur')
    assert len(node.get_slot('por').get_links()) == 2  # pipe1:gen, pipe2:gen
    assert len(node.get_slot('sur').get_links()) == 2  # only sur->por unlinked
开发者ID:joschabach,项目名称:micropsi2,代码行数:27,代码来源:test_node_netapi.py


示例7: test_clone_nodes_all_links

def test_clone_nodes_all_links(fixed_nodenet):
    nodenet = micropsi.get_nodenet(fixed_nodenet)
    success, result = micropsi.clone_nodes(fixed_nodenet, ['A1', 'A2'], 'all')
    assert success
    assert len(result['nodes']) == 2
    assert len(result['links']) == 2

    if result['nodes'][0]['name'] == 'A1_copy':
        a1_copy = result['nodes'][0]
        a2_copy = result['nodes'][1]
    else:
        a1_copy = result['nodes'][1]
        a2_copy = result['nodes'][0]

    a1_copy = nodenet.nodes[a1_copy['uid']]
    a2_copy = nodenet.nodes[a2_copy['uid']]
    l1_uid = list(a1_copy.gates['por'].outgoing.keys())[0]
    l2_uid = list(a1_copy.slots['gen'].incoming.keys())[0]

    assert nodenet.links[l1_uid].source_node.uid == a1_copy.uid
    assert nodenet.links[l1_uid].target_node.uid == a2_copy.uid
    assert nodenet.links[l1_uid].source_gate.type == 'por'
    assert nodenet.links[l1_uid].target_slot.type == 'gen'

    assert l1_uid in [l['uid'] for l in result['links']]

    assert nodenet.links[l2_uid].source_node.uid == 'S'
    assert nodenet.links[l2_uid].target_node.uid == a1_copy.uid
    assert nodenet.links[l2_uid].source_gate.type == 'gen'
    assert nodenet.links[l2_uid].target_slot.type == 'gen'

    assert l2_uid in [l['uid'] for l in result['links']]
开发者ID:conorshankey,项目名称:micropsi2,代码行数:32,代码来源:test_runtime_nodenet_basics.py


示例8: test_add_custom_monitor

def test_add_custom_monitor(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    function = "return len(netapi.get_nodes())"
    uid = netapi.add_custom_monitor(function, 'number_of_nodes', color=None)
    assert nodenet.get_monitor(uid).name == 'number_of_nodes'
    assert nodenet.get_monitor(uid).function == function
开发者ID:joschabach,项目名称:micropsi2,代码行数:7,代码来源:test_node_netapi.py


示例9: test_add_gate_monitor

def test_add_gate_monitor(test_nodenet, node):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    uid = netapi.add_gate_monitor(node, 'gen', name='sepp', color='#987654')
    assert nodenet.get_monitor(uid).name == 'sepp'
    assert nodenet.get_monitor(uid).type == 'gate'
    assert nodenet.get_monitor(uid).color == '#987654'
开发者ID:joschabach,项目名称:micropsi2,代码行数:7,代码来源:test_node_netapi.py


示例10: test_add_modulator_monitor

def test_add_modulator_monitor(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodenet.step()
    uid = netapi.add_modulator_monitor('base_age', 'age')
    assert nodenet.get_monitor(uid).modulator == 'base_age'
    assert nodenet.get_monitor(uid).name == 'age'
开发者ID:joschabach,项目名称:micropsi2,代码行数:7,代码来源:test_node_netapi.py


示例11: test_clone_nodes_copies_gate_params

def test_clone_nodes_copies_gate_params(fixed_nodenet):
    nodenet = micropsi.get_nodenet(fixed_nodenet)
    micropsi.set_gate_parameters(fixed_nodenet, 'n0001', 'gen', {'maximum': 0.1})
    success, result = micropsi.clone_nodes(fixed_nodenet, ['n0001'], 'internal')
    assert success
    copy = nodenet.get_node(result['nodes'][0]['uid'])
    assert round(copy.get_gate_parameters()['gen']['maximum'], 2) == 0.1
开发者ID:ianupright,项目名称:micropsi2,代码行数:7,代码来源:test_runtime_nodenet_basics.py


示例12: test_announce_nodes

def test_announce_nodes(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace = netapi.create_nodespace(None, name="partition", options={
        "new_partition": True,
        "initial_number_of_nodes": 2,
        "average_elements_per_node_assumption": 4,
        "initial_number_of_nodespaces": 1
    })

    # announce 20 pipe nodes
    netapi.announce_nodes(nodespace.uid, 20, 8)

    partition = nodespace.partition

    # 18 nodes needed
    assert partition.NoN == 26  # growby: 18 + 18//3
    # 152 elements needed
    assert partition.NoE == 210  # growby: 152 + 152//3

    for i in range(20):
        netapi.create_node("Pipe", nodespace.uid, "N %d" % i)

    # assert that we did not grow again
    assert partition.NoN == 26
    assert partition.NoE == 210
开发者ID:joschabach,项目名称:micropsi2,代码行数:26,代码来源:test_nodenet_partitions.py


示例13: test_delete_linked_nodes

def test_delete_linked_nodes(fixed_nodenet):

    nodenet = micropsi.get_nodenet(fixed_nodenet)
    netapi = nodenet.netapi

    # create all evil (there will never be another dawn)
    root_of_all_evil = netapi.create_node("Pipe", None)
    evil_one = netapi.create_node("Pipe", None)
    evil_two = netapi.create_node("Pipe", None)

    netapi.link_with_reciprocal(root_of_all_evil, evil_one, "subsur")
    netapi.link_with_reciprocal(root_of_all_evil, evil_two, "subsur")

    for link in evil_one.get_gate("sub").get_links():
        link.source_node.name  # touch of evil
        link.target_node.name  # touch of evil

    for link in evil_two.get_gate("sur").get_links():
        link.source_node.name  # touch of evil
        link.target_node.name  # touch of evil

    # and the name of the horse was death
    netapi.delete_node(root_of_all_evil)
    netapi.delete_node(evil_one)
    netapi.delete_node(evil_two)
开发者ID:pi19404,项目名称:micropsi2,代码行数:25,代码来源:test_runtime_nodenet_basics.py


示例14: test_clone_nodes_internal_links

def test_clone_nodes_internal_links(fixed_nodenet):
    nodenet = micropsi.get_nodenet(fixed_nodenet)
    success, result = micropsi.clone_nodes(fixed_nodenet, ['n0001', 'n0002'], 'internal')
    assert success
    assert len(result['nodes']) == 2
    assert len(result['links']) == 1

    if result['nodes'][0]['name'] == 'A1_copy':
        a1_copy = result['nodes'][0]
        a2_copy = result['nodes'][1]
    else:
        a1_copy = result['nodes'][1]
        a2_copy = result['nodes'][0]

    a1_copy = nodenet.get_node(a1_copy['uid'])
    a2_copy = nodenet.get_node(a2_copy['uid'])
    l1_uid = result['links'][0]['uid']

    links = a1_copy.get_associated_links()
    link = None
    for candidate in links:
        if candidate.source_node.uid == a1_copy.uid and \
                candidate.target_node.uid == a2_copy.uid and \
                candidate.source_gate.type == 'por' and \
                candidate.target_slot.type == 'gen':
            link = candidate
    assert link is not None
开发者ID:ianupright,项目名称:micropsi2,代码行数:27,代码来源:test_runtime_nodenet_basics.py


示例15: test_nodespace_properties

def test_nodespace_properties(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    rootns = netapi.get_nodespace(None)
    netapi.set_nodespace_properties(None, {'foo': 'bar'})
    data = netapi.get_nodespace_properties()
    assert data[rootns.uid] == {'foo': 'bar'}
开发者ID:joschabach,项目名称:micropsi2,代码行数:7,代码来源:test_node_netapi.py


示例16: test_grow_partitions

def test_grow_partitions(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace = netapi.create_nodespace(None, name="partition", options={
        "new_partition": True,
        "initial_number_of_nodes": 2,
        "average_elements_per_node_assumption": 4,
        "initial_number_of_nodespaces": 1
    })

    for i in range(20):
        netapi.create_node("Pipe", nodespace.uid, "N %d" % i)

    partition = nodespace.partition

    # growby (NoN // 2): 2,3,4,6,9,13,19,28
    assert len(partition.allocated_nodes) == 28
    assert partition.NoE > 28 * 4

    for i in range(2):
        netapi.create_nodespace(nodespace.uid, name="NS %d" % i)

    assert len(partition.allocated_nodespaces) == 4

    # step, save, and load the net to make sure all data structures have been grown properly
    micropsi.step_nodenet(test_nodenet)
    micropsi.save_nodenet(test_nodenet)
    micropsi.revert_nodenet(test_nodenet)
    micropsi.step_nodenet(test_nodenet)
开发者ID:joschabach,项目名称:micropsi2,代码行数:29,代码来源:test_nodenet_partitions.py


示例17: test_partition_get_node_data

def test_partition_get_node_data(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace, source, register = prepare(netapi)

    nodes = []
    for i in range(10):
        n = netapi.create_node("Pipe", nodespace.uid if i > 4 else None, "node %d" % i)
        nodes.append(n)

    for i in range(4):
        netapi.link(nodes[i], 'gen', nodes[5], 'gen', weight=((i + 2) / 10))
    netapi.link(nodes[9], 'gen', nodes[4], 'gen', 0.375)

    third_ns = netapi.create_nodespace(None, "third")
    third = netapi.create_node("Register", third_ns.uid, "third")
    netapi.link(nodes[4], 'gen', third, 'gen')

    node_data = nodenet.get_nodes(nodespace_uids=[None])['nodes']
    assert set(node_data.keys()) == set([n.uid for n in nodes[:5]] + [source.uid, register.uid, third.uid] + [nodes[9].uid, nodes[5].uid])

    node_data = nodenet.get_nodes()['nodes']
    n1, n3, n4, n9 = nodes[1], nodes[3], nodes[4], nodes[9]
    assert round(node_data[n1.uid]['links']['gen'][0]['weight'], 3) == 0.3
    assert round(node_data[n3.uid]['links']['gen'][0]['weight'], 3) == 0.5
    assert round(node_data[n9.uid]['links']['gen'][0]['weight'], 3) == 0.375
    # assert node_data[n4.uid]['links'] == {}

    node_data = nodenet.get_nodes(nodespace_uids=[nodespace.uid])['nodes']
    assert len(node_data.keys()) == 12
    assert node_data[n4.uid]['links'] == {}
    assert third.uid not in node_data
开发者ID:joschabach,项目名称:micropsi2,代码行数:32,代码来源:test_nodenet_partitions.py


示例18: test_delete_nodespace_unlinks_native_module

def test_delete_nodespace_unlinks_native_module(test_nodenet, resourcepath):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    nodespace = netapi.create_nodespace(None, "foo")
    foopipe = netapi.create_node("Pipe", nodespace.uid, 'foopipe')
    import os
    nodetype_file = os.path.join(resourcepath, 'Test', 'nodetypes.json')
    nodefunc_file = os.path.join(resourcepath, 'Test', 'nodefunctions.py')
    with open(nodetype_file, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "gatetypes": ["gen", "foo", "bar"]}}')
    with open(nodefunc_file, 'w') as fp:
        fp.write("def testnodefunc(netapi, node=None, **prams):\r\n    return 17")
    micropsi.reload_native_modules()
    testnode = netapi.create_node("Testnode", None, "test")
    netapi.link(testnode, 'foo', foopipe, 'sub')
    netapi.link(foopipe, 'sur', testnode, 'bar')
    micropsi.save_nodenet(test_nodenet)
    # I don't understand why, but this is necessary.
    micropsi.revert_nodenet(test_nodenet)
    netapi.delete_nodespace(nodespace)
    data = netapi.get_node(testnode.uid).get_data(include_links=True)
    assert data['links'] == {}
开发者ID:joschabach,项目名称:micropsi2,代码行数:26,代码来源:test_nodenet_partitions.py


示例19: test_set_agent_properties

def test_set_agent_properties(test_world, test_nodenet):
    world = runtime.worlds[test_world]
    nodenet = runtime.get_nodenet(test_nodenet)
    nodenet.world = world
    runtime.load_nodenet(test_nodenet)
    runtime.set_worldagent_properties(test_world, test_nodenet, position=(5, 5))
    assert world.agents[test_nodenet].position == (5, 5)
    assert world.data['agents'][test_nodenet]['position'] == (5, 5)
开发者ID:brucepro,项目名称:micropsi2,代码行数:8,代码来源:test_runtime_world_basics.py


示例20: test_modulators

def test_modulators(fixed_nodenet):
    nodenet = micropsi.get_nodenet(fixed_nodenet)

    nodenet.netapi.change_modulator("test_modulator", 0.42)
    assert nodenet.netapi.get_modulator("test_modulator") == 0.42

    nodenet.set_modulator("test_modulator", -1)
    assert nodenet.netapi.get_modulator("test_modulator") == -1
开发者ID:ianupright,项目名称:micropsi2,代码行数:8,代码来源:test_runtime_nodenet_basics.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python runtime.step_nodenet函数代码示例发布时间:2022-05-27
下一篇:
Python runtime.get_available_worlds函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap