Ejemplo n.º 1
0
    def __init__(self, network_embedding_params: NetworkEmbeddingParam):
        self.param = network_embedding_params
        # set params
        NetworkEmbeddingChecker.check_param(network_embedding_params)
        self.dim = network_embedding_params.dim
        self.n_node = network_embedding_params.n_node
        self.init_param_obj = network_embedding_params.init_param
        self.learning_rate = network_embedding_params.learning_rate
        self.encrypted_mode_calculator_param = network_embedding_params.encrypted_mode_calculator_param
        self.encrypted_calculator = None

        self.updater = EmUpdater()

        self.eps = network_embedding_params.eps
        self.batch_size = network_embedding_params.batch_size
        self.max_iter = network_embedding_params.max_iter

        if network_embedding_params.encrypt_param.method == consts.PAILLIER:
            self.encrypt_operator = PaillierEncrypt()
        else:
            self.encrypt_operator = FakeEncrypt()

        # attribute:
        self.n_iter_ = 0
        self.embedding_ = None

        self.gradient_operator = None
        self.initializer = EmbeddingInitializer()
        self.transfer_variable = None
        self.model_meta = NetworkEmbeddingModelMeta()
        self.loss_history = []
        self.is_converged = False
        self.class_name = self.__class__.__name__
Ejemplo n.º 2
0
    def __init__(self, logistic_params: LogisticParam):
        # set params
        self.alpha = logistic_params.alpha
        self.init_param_obj = logistic_params.init_param
        self.fit_intercept = self.init_param_obj.fit_intercept
        self.learning_rate = logistic_params.learning_rate

        if logistic_params.penalty == consts.L1_PENALTY:
            self.updater = L1Updater(self.alpha, self.learning_rate)
        elif logistic_params.penalty == consts.L2_PENALTY:
            self.updater = L2Updater(self.alpha, self.learning_rate)
        else:
            self.updater = None

        self.eps = logistic_params.eps
        self.batch_size = logistic_params.batch_size
        self.max_iter = logistic_params.max_iter

        if logistic_params.encrypt_param.method == consts.PAILLIER:
            self.encrypt_operator = PaillierEncrypt()
        else:
            self.encrypt_operator = FakeEncrypt()

        # attribute:
        self.n_iter_ = 0
        self.coef_ = None
        self.intercept_ = 0
        self.classes_ = None

        self.gradient_operator = None
        self.initializer = Initializer()
        self.transfer_variable = None
        self.model_meta = LogisticRegressionModelMeta()
Ejemplo n.º 3
0
    def __synchronize_encryption(self):
        """
        Communicate with hosts. Specify whether use encryption or not and transfer the public keys.
        """
        # 1. Use Encrypt: Specify which host use encryption
        host_use_encryption_id = self.transfer_variable.generate_transferid(
            self.transfer_variable.use_encrypt)
        host_use_encryption = federation.get(
            name=self.transfer_variable.use_encrypt.name,
            tag=host_use_encryption_id,
            idx=-1)
        self.host_use_encryption = host_use_encryption

        LOGGER.info("host use encryption: {}".format(self.host_use_encryption))
        # 2. Send pubkey to those use-encryption hosts
        for idx, use_encryption in enumerate(self.host_use_encryption):
            if not use_encryption:
                encrypter = FakeEncrypt()
            else:
                encrypter = PaillierEncrypt()
                encrypter.generate_key(self.encrypt_param.key_length)
                pub_key = encrypter.get_public_key()
                pubkey_id = self.transfer_variable.generate_transferid(
                    self.transfer_variable.paillier_pubkey)
                federation.remote(
                    pub_key,
                    name=self.transfer_variable.paillier_pubkey.name,
                    tag=pubkey_id,
                    role=consts.HOST,
                    idx=idx)
                # LOGGER.debug("send pubkey to host: {}".format(idx))

            self.host_encrypter.append(encrypter)
        self.has_sychronized_encryption = True
Ejemplo n.º 4
0
    def _init_model(self, params):
        super(HomoLRBase, self)._init_model(params)
        self.re_encrypt_batches = params.re_encrypt_batches

        if params.encrypt_param.method == consts.PAILLIER:
            self.cipher_operator = PaillierEncrypt()
        else:
            self.cipher_operator = FakeEncrypt()

        self.transfer_variable = HomoLRTransferVariable()
        self.aggregator.register_aggregator(self.transfer_variable)
        self.optimizer = optimizer_factory(params)
        self.aggregate_iters = params.aggregate_iters
Ejemplo n.º 5
0
    def __init__(self, logistic_params: LogisticParam):
        self.param = logistic_params
        # set params
        LogisticParamChecker.check_param(logistic_params)
        self.alpha = logistic_params.alpha
        self.init_param_obj = logistic_params.init_param
        self.fit_intercept = self.init_param_obj.fit_intercept
        self.learning_rate = logistic_params.learning_rate
        self.encrypted_mode_calculator_param = logistic_params.encrypted_mode_calculator_param
        self.encrypted_calculator = None

        if logistic_params.penalty == consts.L1_PENALTY:
            self.updater = L1Updater(self.alpha, self.learning_rate)
        elif logistic_params.penalty == consts.L2_PENALTY:
            self.updater = L2Updater(self.alpha, self.learning_rate)
        else:
            self.updater = None

        self.eps = logistic_params.eps
        self.batch_size = logistic_params.batch_size
        self.max_iter = logistic_params.max_iter

        if logistic_params.encrypt_param.method == consts.PAILLIER:
            self.encrypt_operator = PaillierEncrypt()
        else:
            self.encrypt_operator = FakeEncrypt()

        # attribute:
        self.n_iter_ = 0
        self.coef_ = None
        self.intercept_ = 0
        self.classes_ = None
        self.feature_shape = None

        self.gradient_operator = None
        self.initializer = Initializer()
        self.transfer_variable = None
        self.model_meta = LogisticRegressionModelMeta()
        self.loss_history = []
        self.is_converged = False
        self.header = None
        self.class_name = self.__class__.__name__
Ejemplo n.º 6
0
    def _init_model(self, params):
        self.model_param = params
        self.alpha = params.alpha
        self.init_param_obj = params.init_param
        self.fit_intercept = self.init_param_obj.fit_intercept
        self.learning_rate = params.learning_rate
        self.encrypted_mode_calculator_param = params.encrypted_mode_calculator_param
        self.encrypted_calculator = None

        if params.penalty == consts.L1_PENALTY:
            self.updater = L1Updater(self.alpha, self.learning_rate)
        elif params.penalty == consts.L2_PENALTY:
            self.updater = L2Updater(self.alpha, self.learning_rate)
        else:
            self.updater = None

        self.eps = params.eps
        self.batch_size = params.batch_size
        self.max_iter = params.max_iter
        self.learning_rate = params.learning_rate
        self.party_weight = params.party_weight
        self.penalty = params.penalty

        if params.encrypt_param.method == consts.PAILLIER:
            self.encrypt_operator = PaillierEncrypt()
        else:
            self.encrypt_operator = FakeEncrypt()

        if params.converge_func == 'diff':
            self.converge_func = convergence.DiffConverge(eps=self.eps)
        elif params.converge_func == 'weight_diff':
            self.converge_func = convergence.WeightDiffConverge(eps=self.eps)
        else:
            self.converge_func = convergence.AbsConverge(eps=self.eps)

        self.re_encrypt_batches = params.re_encrypt_batches
        self.predict_param = params.predict_param
        self.optimizer = Optimizer(params.learning_rate, params.optimizer)
        self.key_length = params.encrypt_param.key_length