Exemplo n.º 1
0
    def test_create_table_with_array_2(self):

        feature_count = 10
        expect_data = np.random.rand(feature_count)
        actual_data = np.zeros((feature_count, 1))
        dtable = create_table(expect_data)
        for item in dtable.collect():
            actual_data[item[0]] = item[1]

        assert dtable.count() == feature_count
        assert_matrix(np.expand_dims(expect_data, axis=1), actual_data)
Exemplo n.º 2
0
    def test_create_table_with_array_1(self):

        row_count = 10
        expect_data = np.random.rand(row_count, 10)
        actual_data = np.zeros((row_count, 10))
        dtable = create_table(expect_data)
        for item in dtable.collect():
            actual_data[item[0]] = item[1]

        assert dtable.count() == row_count
        assert_matrix(expect_data, actual_data)
Exemplo n.º 3
0
    def predict(self, host_data, predict_param):
        LOGGER.info("@ start host predict")
        features, labels, instances_indexes = convert_instance_table_to_array(
            host_data)
        host_x = np.squeeze(features)
        LOGGER.debug("host_x: " + str(host_x.shape))

        host_prob = self.host_model.predict(host_x)
        self._do_remote(host_prob,
                        name=self.transfer_variable.host_prob.name,
                        tag=self.transfer_variable.generate_transferid(
                            self.transfer_variable.host_prob),
                        role=consts.GUEST,
                        idx=-1)

        pred_prob = self._do_get(
            name=self.transfer_variable.pred_prob.name,
            tag=self.transfer_variable.generate_transferid(
                self.transfer_variable.pred_prob),
            idx=-1)[0]

        pred_prob = np.squeeze(pred_prob)
        LOGGER.debug("pred_prob: " + str(pred_prob.shape))

        pred_prob_table = create_table(pred_prob, instances_indexes)
        actual_label_table = create_table(labels, instances_indexes)
        pred_label_table = self.classified(pred_prob_table,
                                           predict_param.threshold)
        if predict_param.with_proba:
            predict_result = actual_label_table.join(
                pred_prob_table, lambda label, prob:
                (label if label > 0 else 0, prob))
            predict_result = predict_result.join(pred_label_table, lambda x, y:
                                                 (x[0], x[1], y))
        else:
            predict_result = actual_label_table.join(
                pred_label_table, lambda a_label, p_label:
                (a_label, None, p_label))
        return predict_result
Exemplo n.º 4
0
    def test_create_table_with_dict(self):

        row_count = 10
        expect_data = np.random.rand(row_count, 10)
        indexes = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
        actual_data = {}
        dtable = create_table(expect_data, indexes)
        for item in dtable.collect():
            actual_data[item[0]] = item[1]

        assert dtable.count() == len(indexes)
        for i, index in enumerate(indexes):
            assert_array(actual_data[indexes[i]], expect_data[i])
Exemplo n.º 5
0
    def test_destroy_table(self):

        row_count = 10
        expect_data = np.random.rand(row_count, 10)

        table_name = "table_name"
        table_ns = "table_ns"
        dtable = create_table(expect_data, model_table_name=table_name, model_namespace=table_ns, persistent=True)
        dtable_2 = table(name=table_name, namespace=table_ns)
        assert dtable.count() == dtable_2.count()

        dtable_2.destroy()
        dtable_3 = table(name=table_name, namespace=table_ns)
        assert dtable_3.count() == 0
Exemplo n.º 6
0
    def test_hetero_plain_guest_prepare_table(self):
        U_A = np.array([[1, 2, 3, 4, 5], [4, 5, 6, 7, 8], [7, 8, 9, 10, 11],
                        [4, 5, 6, 7, 8]])
        y = np.array([[1], [-1], [1], [-1]])

        Wh = np.ones((5, U_A.shape[1]))
        bh = np.zeros(U_A.shape[1])

        model_param = FTLModelParam(alpha=1, max_iteration=1)

        autoencoderA = MockAutoencoder(0)
        autoencoderA.build(U_A.shape[1], Wh, bh)
        guest = PlainFTLGuestModel(autoencoderA, model_param)

        converge_func = MockDiffConverge(None)
        ftl_guest = TestHeteroFTLGuest(guest, model_param,
                                       HeteroFTLTransferVariable())
        ftl_guest.set_converge_function(converge_func)

        guest_sample_indexes = np.array([0, 1, 2, 3])
        guest_x_dict = {}
        guest_label_dict = {}
        instance_dict = {}
        instance_list = []
        np.random.seed(100)
        for i, feature, label, in zip(guest_sample_indexes, U_A, y):
            instance = Instance(inst_id=i, features=feature, label=label[0])
            guest_x_dict[i] = feature
            guest_label_dict[i] = label[0]
            instance_dict[i] = instance
            instance_list.append(instance)

        guest_x = create_table(instance_list, indexes=guest_sample_indexes)

        guest_x, overlap_indexes, non_overlap_indexes, guest_y = ftl_guest.prepare_data(
            guest_x)
        print("guest_x", guest_x)
        print("overlap_indexes", overlap_indexes)
        print("non_overlap_indexes", non_overlap_indexes)
        print("guest_y", guest_y)