Exemplo n.º 1
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)
Exemplo n.º 2
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
Exemplo n.º 3
0
 def test_stoptrain_result1(self):
     """Test that stop_result is handled correctly."""
     stop_result = ({"test": 0}, 1)
     bi_sfa_node = SFABiNode(stop_result=stop_result,
                             node_id="testing binode")
     assert bi_sfa_node.is_trainable()
     x = n.random.random((100,10))
     train_result = bi_sfa_node.train(x)
     assert train_result is None
     assert bi_sfa_node.is_training()
     result = bi_sfa_node.stop_training()
     assert result == (None,) + stop_result
     assert bi_sfa_node.input_dim == 10
     assert bi_sfa_node.output_dim == 10
     assert bi_sfa_node.dtype == "float64"
Exemplo n.º 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
Exemplo n.º 5
0
 def test_mixed_parallel_flow(self):
     """Test a ParallelBiFlow with both standard and BiNodes."""
     flow = ParallelBiFlow([
         mdp.nodes.PCANode(output_dim=8),
         SFABiNode(output_dim=5),
         SFA2BiNode(output_dim=20)
     ])
     data_iterables = [[n.random.random((20, 10)) for _ in range(6)]] * 3
     scheduler = mdp.parallel.Scheduler()
     flow.train(data_iterables, scheduler=scheduler)
     x = n.random.random([100, 10])
     flow.execute(x)
     iterator = [n.random.random((20, 10)) for _ in range(6)]
     flow.execute(iterator, scheduler=scheduler)
     scheduler.shutdown()
Exemplo n.º 6
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
     }, EXIT_TARGET)
     stop_sfa_node = SFABiNode(stop_result=stop_result,
                               input_dim=10,
                               output_dim=3)
     biflownode = BiFlowNode(BiFlow([stop_sfa_node]))
     clonelayer = ParallelCloneBiLayer(node=biflownode,
                                       n_nodes=3,
                                       use_copies=False,
                                       node_id="clonelayer")
     data = [[n.random.random((100, 30)) for _ in range(5)]]
     biflow = ParallelBiFlow([clonelayer])
     biflow.train(data, scheduler=mdp.parallel.Scheduler())
     assert clonelayer.use_copies is True
Exemplo n.º 7
0
 def test_stop_message_attribute(self):
     """Test that the stop_result attribute is present in forked node."""
     stop_result = ({"test": "blabla"}, "node123")
     x = n.random.random([100, 10])
     node = SFABiNode(stop_result=stop_result)
     try:
         mdp.activate_extension("parallel")
         node2 = node.fork()
         node2.train(x)
         forked_result = node2.stop_training()
         assert forked_result == (None, ) + stop_result
         # same with derived sfa2 node
         node = SFA2BiNode(stop_result=stop_result)
         mdp.activate_extension("parallel")
         node2 = node.fork()
         node2.train(x)
         forked_result = node2.stop_training()
         assert forked_result == (None, ) + stop_result
     finally:
         mdp.deactivate_extension("parallel")