Esempio n. 1
0
    def load_model(self, name, namespace):

        result_obj = feature_binning_param_pb2.FeatureBinningParam()
        return_code = model_manager.read_model(buffer_type="HeteroFeatureBinning{}.param".format(self.party_name),
                                               proto_buffer=result_obj,
                                               name=name,
                                               namespace=namespace)
        binning_result_obj = dict(result_obj.binning_result.binning_result)
        host_params = dict(result_obj.host_results)
        # LOGGER.debug("Party name is :{}".format(self.party_name))
        # LOGGER.debug('Loading model, binning_result_obj is : {}'.format(binning_result_obj))
        self.binning_result = {}
        self.host_results = {}
        self.cols = []
        for col_name, iv_attr_obj in binning_result_obj.items():
            iv_attr = IVAttributes([], [], [], [], [], [])
            iv_attr.reconstruct(iv_attr_obj)
            self.binning_result[col_name] = iv_attr
            self.cols.append(col_name)

        for host_name, host_result_obj in host_params.items():
            host_result_obj = dict(host_result_obj.binning_result)
            for col_name, iv_attr_obj in host_result_obj.items():
                iv_attr = IVAttributes([], [], [], [], [], [])
                iv_attr.reconstruct(iv_attr_obj)
                host_result_obj[col_name] = iv_attr
            self.host_results[host_name] = host_result_obj
        return return_code
Esempio n. 2
0
    def save_model(self, name, namespace):
        meta_buffer_type = self._save_meta(name, namespace)

        iv_attrs = []
        for idx, iv_attr in enumerate(self.iv_attrs):
            LOGGER.debug("{}th iv attr: {}".format(idx, iv_attr.__dict__))
            iv_result = iv_attr.result_dict()
            iv_object = feature_binning_param_pb2.IVParam(**iv_result)

            iv_attrs.append(iv_object)

        host_iv_attrs = []
        if self.host_iv_attrs is not None:
            for idx, iv_attr in enumerate(self.host_iv_attrs):
                iv_result = iv_attr.result_dict()
                iv_object = feature_binning_param_pb2.IVParam(**iv_result)

                host_iv_attrs.append(iv_object)

        result_obj = feature_binning_param_pb2.FeatureBinningParam(iv_result=iv_attrs,
                                                                   host_iv_result=host_iv_attrs,
                                                                   cols=self.cols)
        param_buffer_type = "HeteroFeatureBinningGuest.param"

        model_manager.save_model(buffer_type=param_buffer_type,
                                 proto_buffer=result_obj,
                                 name=name,
                                 namespace=namespace)

        return [(meta_buffer_type, param_buffer_type)]
Esempio n. 3
0
    def _get_param(self):

        binning_result = self.binning_result

        host_results = self.host_results

        iv_attrs = {}
        for col_name, iv_attr in binning_result.items():
            iv_result = iv_attr.result_dict()
            iv_object = feature_binning_param_pb2.IVParam(**iv_result)
            iv_attrs[col_name] = iv_object
        binning_result_obj = feature_binning_param_pb2.FeatureBinningResult(
            binning_result=iv_attrs)

        final_host_results = {}
        for host_id, this_host_results in host_results.items():
            host_result = {}
            for host_col_idx, iv_attr in this_host_results.items():
                iv_result = iv_attr.result_dict()
                iv_object = feature_binning_param_pb2.IVParam(**iv_result)
                host_result[str(host_col_idx)] = iv_object
            final_host_results[
                host_id] = feature_binning_param_pb2.FeatureBinningResult(
                    binning_result=host_result)

        result_obj = feature_binning_param_pb2.FeatureBinningParam(
            binning_result=binning_result_obj, host_results=final_host_results)
        # json_result = json_format.MessageToJson(result_obj)
        # LOGGER.debug("json_result: {}".format(json_result))
        return result_obj
Esempio n. 4
0
    def load_model(self, name, namespace):

        result_obj = feature_binning_param_pb2.FeatureBinningParam()
        model_manager.read_model(buffer_type="HeteroFeatureBinningGuest.param",
                                 proto_buffer=result_obj,
                                 name=name,
                                 namespace=namespace)

        self.iv_attrs = []
        for iv_dict in list(result_obj.iv_result):
            iv_attr = IVAttributes([], [], [], [], [], [], [])
            iv_attr.reconstruct(iv_dict)
            self.iv_attrs.append(iv_attr)

        self.host_iv_attrs = []
        for iv_dict in list(result_obj.host_iv_result):
            iv_attr = IVAttributes([], [], [], [], [], [], [])
            iv_attr.reconstruct(iv_dict)
            self.host_iv_attrs.append(iv_attr)

        self.cols = list(result_obj.cols)
Esempio n. 5
0
    def save_model(self, name, namespace, binning_result=None, host_results=None):

        if binning_result is None:
            binning_result = self.binning_result

        if host_results is None:
            host_results = self.host_results

        meta_buffer_type = self._save_meta(name, namespace)

        iv_attrs = {}
        for col_name, iv_attr in binning_result.items():
            iv_result = iv_attr.result_dict()
            iv_object = feature_binning_param_pb2.IVParam(**iv_result)

            iv_attrs[col_name] = iv_object
        binning_result_obj = feature_binning_param_pb2.FeatureBinningResult(binning_result=iv_attrs)

        final_host_results = {}
        for host_id, this_host_results in host_results.items():
            host_result = {}
            for col_name, iv_attr in this_host_results.items():
                iv_result = iv_attr.result_dict()
                iv_object = feature_binning_param_pb2.IVParam(**iv_result)
                host_result[col_name] = iv_object
            final_host_results[host_id] = feature_binning_param_pb2.FeatureBinningResult(binning_result=host_result)

        result_obj = feature_binning_param_pb2.FeatureBinningParam(binning_result=binning_result_obj,
                                                                   host_results=final_host_results)

        param_buffer_type = "HeteroFeatureBinning{}.param".format(self.party_name)

        model_manager.save_model(buffer_type=param_buffer_type,
                                 proto_buffer=result_obj,
                                 name=name,
                                 namespace=namespace)

        return [(meta_buffer_type, param_buffer_type)]