Example #1
0
 def test_use_copies_msg(self):
     """Test the correct reaction to an outgoing use_copies message."""
     stop_result = ({"clonelayer" + MSG_ID_SEP + "use_copies": True}, 1)
     stop_sfa_node = SFABiNode(stop_result=stop_result,
                               input_dim=10, output_dim=3)
     clonelayer = CloneBiLayer(node=stop_sfa_node,
                               n_nodes=3,
                               use_copies=False,
                               node_id="clonelayer")
     x = n.random.random((100,30))
     clonelayer.train(x)
     clonelayer.stop_training()
     assert clonelayer.use_copies is True
Example #2
0
 def test_clonelayer(self):
     """Test a simple clonelayer with three SFA Nodes."""
     sfa_node = SFABiNode(input_dim=3, output_dim=2)
     clonelayer = CloneBiLayer(sfa_node, 3)
     x = n.random.random((100,9))
     clonelayer.train(x)
     clonelayer.stop_training()
     clonelayer.execute(x)
Example #3
0
 def test_clonelayer(self):
     """Test a simple clonelayer with three SFA Nodes."""
     sfa_node = SFABiNode(input_dim=3, output_dim=2)
     clonelayer = CloneBiLayer(sfa_node, 3)
     x = n.random.random((100,9))
     clonelayer.train(x)
     clonelayer.stop_training()
     clonelayer.execute(x)
Example #4
0
 def test_use_copies_msg_flownode(self):
     """Test the correct reaction to an outgoing use_copies message."""
     stop_result = ({"clonelayer" + MSG_ID_SEP + "use_copies": True},
                    EXIT_TARGET)
     stop_sfa_node = SFABiNode(stop_result=stop_result,
                               input_dim=10, output_dim=3)
     biflownode = BiFlowNode(BiFlow([stop_sfa_node]))
     clonelayer = CloneBiLayer(node=biflownode,
                               n_nodes=3,
                               use_copies=False,
                               node_id="clonelayer")
     biflow = clonelayer + IdentityBiNode()
     x = n.random.random((100,30))
     biflow.train(x)
     assert clonelayer.use_copies is True
Example #5
0
 def test_message_splitting(self):
     """Test message array splitting and combination."""
     node = DummyBiNode(input_dim=3)
     clonelayer = CloneBiLayer(node, 2, use_copies=True)
     x = n.random.random((10, 6))
     data1 = n.random.random((10, 4))  # should be split
     data2 = n.random.random((10, 5))  # should not be touched
     msg = {
         "string": "blabla",
         "list": [1,2],
         "data1": data1,
         "data2": data2,
     }
     y, out_msg = clonelayer.execute(x, msg)
     node1, node2 = clonelayer.nodes
     assert n.all(x == y)
     assert out_msg["string"] == msg["string"]
     assert out_msg["list"] == msg["list"]
     assert n.all(out_msg["data1"] == data1)
     assert n.all(node1.data1 == data1[:,:2])
     assert n.all(node2.data1 == data1[:,2:])
     assert out_msg["data2"] is data2
     assert n.all(node1.data2 is data2)
     assert n.all(node2.data2 is data2)
Example #6
0
 def test_message_splitting(self):
     """Test message array splitting and combination."""
     node = DummyBiNode(input_dim=3)
     clonelayer = CloneBiLayer(node, 2, use_copies=True)
     x = n.random.random((10, 6))
     data1 = n.random.random((10, 4))  # should be split
     data2 = n.random.random((10, 5))  # should not be touched
     msg = {
         "string": "blabla",
         "list": [1,2],
         "data1": data1,
         "data2": data2,
     }
     y, out_msg = clonelayer.execute(x, msg)
     node1, node2 = clonelayer.nodes
     assert n.all(x == y)
     assert out_msg["string"] == msg["string"]
     assert out_msg["list"] == msg["list"]
     assert n.all(out_msg["data1"] == data1)
     assert n.all(node1.data1 == data1[:,:2])
     assert n.all(node2.data1 == data1[:,2:])
     assert out_msg["data2"] is data2
     assert n.all(node1.data2 is data2)
     assert n.all(node2.data2 is data2)
Example #7
0
 def test_use_copies_msg(self):
     """Test the correct reaction to an outgoing use_copies message."""
     stop_result = ({"clonelayer" + MSG_ID_SEP + "use_copies": True}, 1)
     stop_sfa_node = SFABiNode(stop_result=stop_result,
                               input_dim=10, output_dim=3)
     clonelayer = CloneBiLayer(node=stop_sfa_node,
                               n_nodes=3,
                               use_copies=False,
                               node_id="clonelayer")
     x = n.random.random((100,30))
     clonelayer.train(x)
     clonelayer.stop_training()
     assert clonelayer.use_copies is True