Ejemplo n.º 1
0
 def create(cls, ftl_model_param: FTLModelParam, transfer_variable: HeteroFTLTransferVariable, ftl_local_model):
     if ftl_model_param.is_encrypt:
         if ftl_model_param.enc_ftl == "dct_enc_ftl":
             # decentralized encrypted ftl guest
             LOGGER.debug("@ create decentralized encrypted ftl_guest")
             guest_model = EncryptedFTLGuestModel(local_model=ftl_local_model, model_param=ftl_model_param)
             guest = HeteroDecentralizedEncryptFTLGuest(guest_model, ftl_model_param, transfer_variable)
         elif ftl_model_param.enc_ftl == "dct_enc_ftl2":
             # decentralized encrypted faster ftl guest
             LOGGER.debug("@ create decentralized encrypted faster ftl_guest")
             guest_model = FasterEncryptedFTLGuestModel(local_model=ftl_local_model, model_param=ftl_model_param)
             guest = FasterHeteroDecentralizedEncryptFTLGuest(guest_model, ftl_model_param, transfer_variable)
         elif ftl_model_param.enc_ftl == "enc_ftl2":
             # encrypted faster ftl guest
             LOGGER.debug("@ create encrypt faster ftl_guest")
             guest_model = FasterEncryptedFTLGuestModel(local_model=ftl_local_model, model_param=ftl_model_param)
             guest = FasterHeteroEncryptFTLGuest(guest_model, ftl_model_param, transfer_variable)
         else:
             # encrypted ftl guest
             LOGGER.debug("@ create encrypt ftl_guest")
             guest_model = EncryptedFTLGuestModel(local_model=ftl_local_model, model_param=ftl_model_param)
             guest = HeteroEncryptFTLGuest(guest_model, ftl_model_param, transfer_variable)
     else:
         # plain ftl guest
         LOGGER.debug("@ create plain ftl_guest")
         guest_model = PlainFTLGuestModel(local_model=ftl_local_model, model_param=ftl_model_param)
         guest = HeteroPlainFTLGuest(guest_model, ftl_model_param, transfer_variable)
     return guest
Ejemplo n.º 2
0
 def _do_initialize_model(self, ftl_model_param, ftl_local_model_param,
                          ftl_data_model_param):
     self.ftl_local_model = self._create_local_model(
         ftl_local_model_param, ftl_data_model_param)
     if ftl_model_param.is_encrypt:
         LOGGER.debug("@ create encrypt ftl_guest")
         guest_model = EncryptedFTLGuestModel(
             local_model=self.ftl_local_model, model_param=ftl_model_param)
         self.model = HeteroEncryptFTLGuest(guest_model, ftl_model_param,
                                            self._get_transfer_variable())
     else:
         LOGGER.debug("@ create plain ftl_guest")
         guest_model = PlainFTLGuestModel(local_model=self.ftl_local_model,
                                          model_param=ftl_model_param)
         self.model = HeteroPlainFTLGuest(guest_model, ftl_model_param,
                                          self._get_transfer_variable())
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def run_one_party_msg_exchange(autoencoderA,
                               autoencoderB,
                               U_A,
                               U_B,
                               y,
                               overlap_indexes,
                               non_overlap_indexes,
                               public_key=None,
                               private_key=None,
                               is_encrypted=False):

    fake_model_param = FakeFTLModelParam(alpha=1)
    if is_encrypted:
        partyA = EncryptedFTLGuestModel(autoencoderA,
                                        fake_model_param,
                                        public_key=public_key,
                                        private_key=private_key)
        partyA.set_batch(U_A, y, non_overlap_indexes, overlap_indexes)
        partyB = EncryptedFTLHostModel(autoencoderB,
                                       fake_model_param,
                                       public_key=public_key,
                                       private_key=private_key)
        partyB.set_batch(U_B, overlap_indexes)
    else:
        partyA = PlainFTLGuestModel(autoencoderA, fake_model_param)
        partyA.set_batch(U_A, y, non_overlap_indexes, overlap_indexes)
        partyB = PlainFTLHostModel(autoencoderB, fake_model_param)
        partyB.set_batch(U_B, overlap_indexes)

    comp_A_beta1, comp_A_beta2, mapping_comp_A = partyA.send_components()
    U_B_overlap, U_B_overlap_2, mapping_comp_B = partyB.send_components()

    partyA.receive_components([U_B_overlap, U_B_overlap_2, mapping_comp_B])
    partyB.receive_components([comp_A_beta1, comp_A_beta2, mapping_comp_A])

    return partyA, partyB
Ejemplo n.º 5
0
    print(
        "################################ Build Federated Models ############################"
    )

    tf.reset_default_graph()

    autoencoder_A = Autoencoder(1)
    autoencoder_B = Autoencoder(2)

    autoencoder_A.build(X_A.shape[-1], 200, learning_rate=0.01)
    autoencoder_B.build(X_B.shape[-1], 200, learning_rate=0.01)

    # alpha = 100
    fake_model_param = FakeFTLModelParam()
    partyA = PlainFTLGuestModel(autoencoder_A, fake_model_param)
    partyB = PlainFTLHostModel(autoencoder_B, fake_model_param)

    federatedLearning = LocalPlainFederatedTransferLearning(partyA, partyB)

    print(
        "################################ Train Federated Models ############################"
    )
    start_time = time.time()
    epochs = 100
    init = tf.global_variables_initializer()
    with tf.Session() as sess:
        autoencoder_A.set_session(sess)
        autoencoder_B.set_session(sess)

        sess.run(init)