Esempio n. 1
0
    def testfindLCA(self):

        root = Node(1)
        root.children.append(dag.Node(2))
        root.children.append(dag.Node(3))
        root.children[0].children.append(dag.Node(4))
        root.children[0].children.append(dag.Node(5))
        root.children[1].children.append(dag.Node(6))
        root.children[1].children.append(dag.Node(7))

        # test all nodes are None
        self.assertEqual(dag.findLCA(None, None, None), None)

        #test when root is euqal to node
        self.assertEqual(dag.findLCA(root, 1, 1), 1)

        #test if n1 is not present
        self.assertEqual(dag.findLCA(root, None, 2), None)

        #test if n2 is not present
        self.assertEqual(dag.findLCA(root, 2, None), None)

        #test when node is value is not in tree
        self.assertEqual(dag.findLCA(root, 2, 13), None)

        #test dag for different values
        self.assertEqual(dag.findLCA(root, 3, 7), 3)
        self.assertEqual(dag.findLCA(root, 4, 6), 1)
        self.assertEqual(dag.findLCA(root, 2, 5), 2)
        self.assertEqual(dag.findLCA(root, 3, 4), 1)
Esempio n. 2
0
    def test_root_node(
            self):  # Test case where root is a node of interest for lca
        root = Node(1)
        node1 = Node(2)
        node2 = Node(3)
        root.succ = [node1, node2]

        lca = daglca(root, node1, node1)

        assert lca is 2

        lca = daglca(root, node2, root)

        assert lca is 1

        lca = daglca(root, node1, root)

        assert lca is 1, "test_root_node failed"
Esempio n. 3
0
    def testNodes(self):  #Testing root value in the tree

        root = Node(1)
        self.assertEqual(1, root.key)
                                      net=_dense_net(),
                                      trainset=splited_trainset[i],
                                      testset=splited_testset[i],
                                      log=True)
        else:  # Honest nodes
            client = Client(args=args,
                            net=_dense_net(),
                            trainset=splited_trainset[i],
                            testset=splited_testset[i],
                            log=True)
        client.set_weights(tmp_client.get_weights())  # same init. weights
        clients.append(client)
    """Set DAG
    # TODO: DAG connection
    """
    genesis = Node(weights=tmp_client.get_weights(), _id=-1)

    nodes = []
    nodes.append(genesis)
    """Run simulator
    # TODO: logging time (train, test)
    """
    latest_nodes = deepcopy(nodes)  # in DAG

    for epoch in range(1, args.nEpochs + 1):
        print(">>> Round %5d" % (epoch))

        # select activated clients
        # At least one honest node
        n_activated_byz = random.randint(0, args.nByzs)  # in Byz.
        n_activated_norm = random.randint(1, args.norm)  # in Norm.
Esempio n. 5
0
File: main.py Progetto: jaeykim/ddl
    """set nodes"""
    clients = []
    for i in range(ns):
        clients.append(
            Client(trainset=splited_trainset[i],
                   testset=splited_testset[i],
                   net=Net(),
                   _id=i))

    tmp_client = Client(  # tmp
        trainset=None, testset=splited_testset[i], net=Net(), _id=-1)
    """set DAG"""
    global_id = -1
    nodes = []

    genesis = Node(r=-1, w=clients[0].get_weights(), _id=global_id)
    nodes.append(genesis)
    global_id += 1
    """run simulator"""
    latest_nodes = deepcopy(nodes)  # in DAG

    for r in range(rs):
        print(">>> Round %5d" % (r))

        # select activated clients
        n_activated = random.randint(1, ns)  # TODO: range
        activateds = random.sample([t for t in range(ns)], n_activated)

        current_nodes = []
        current_accs = []
Esempio n. 6
0
    def test_lowest_node(
            self):  # Test case with one of the lowest nodes in graph
        root = Node(1)
        node1 = Node(2)
        node2 = Node(3)
        node3 = Node(4)
        node4 = Node(5)
        node5 = Node(6)
        root.succ = [node1, node2, node3, node4]
        node1.succ = [node3]
        node1.pred = [root]
        node2.succ = [node3, node4]
        node2.pred = [root]
        node3.succ = [node4]
        node3.pred = [node1, node2, root]
        node4.pred = [node2, node3, root]
        node5.pred = [node3]

        lca = daglca(root, node5, node1)

        assert lca is 1, "test_lowest_node failed"
Esempio n. 7
0
    def test_basic(self):  #Test for basic case, nodes present in graph
        root = Node(1)
        node1 = Node(2)
        node2 = Node(3)
        node3 = Node(4)
        node4 = Node(5)
        node5 = Node(6)
        root.succ = [node1, node2, node3, node4]
        node1.succ = [node3]
        node1.pred = [root]
        node2.succ = [node3, node4]
        node2.pred = [root]
        node3.succ = [node4]
        node3.pred = [node1, node2, root]
        node4.pred = [node2, node3, root]
        node5.pred = [node3]

        lca = daglca(root, node3, node4)

        assert lca is 3, "test_basic failed"