本文整理汇总了Python中micropsi_core.runtime.get_nodenet函数的典型用法代码示例。如果您正苦于以下问题:Python get_nodenet函数的具体用法?Python get_nodenet怎么用?Python get_nodenet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_nodenet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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
示例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)
示例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
示例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']]
示例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
示例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'
示例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'
示例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
示例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
示例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)
示例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
示例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'}