Esempio n. 1
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):

    fake_model_param = MockFTLModelParam(alpha=1)

    partyA = FasterEncryptedFTLGuestModel(autoencoderA,
                                          fake_model_param,
                                          public_key=public_key,
                                          private_key=private_key)
    partyA.set_batch(U_A, y, non_overlap_indexes, overlap_indexes)
    partyB = FasterEncryptedFTLHostModel(autoencoderB,
                                         fake_model_param,
                                         public_key=public_key,
                                         private_key=private_key)
    partyB.set_batch(U_B, overlap_indexes)

    [y_overlap_phi, mapping_comp_A, phi, phi_2] = partyA.send_components()
    [uB_overlap, mapping_comp_B] = partyB.send_components()

    partyA.receive_components([uB_overlap, mapping_comp_B])
    partyB.receive_components([y_overlap_phi, mapping_comp_A, phi, phi_2])

    precomputed_components_A = partyA.send_precomputed_components()
    precomputed_components_B = partyB.send_precomputed_components()

    partyA.receive_precomputed_components(precomputed_components_B)
    partyB.receive_precomputed_components(precomputed_components_A)

    # encrypt_gradients_A = partyA.send_gradients()
    # encrypt_gradients_B = partyB.send_gradients()

    # partyA.receive_gradients(__decrypt_gradients(encrypt_gradients_A))
    # partyB.receive_gradients(__decrypt_gradients(encrypt_gradients_B))

    return partyA, partyB
Esempio n. 2
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 = MockFTLModelParam(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
Esempio n. 3
0
    print("validate_indexes len", len(validate_indexes))
    print("test_indexes len", len(test_indexes))

    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)

    fake_model_param = MockFTLModelParam(alpha=100)
    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)