pearson_model_converter.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from typing import Dict
  17. from federatedml.protobuf.generated.pearson_model_meta_pb2 import PearsonModelMeta
  18. from federatedml.protobuf.generated.pearson_model_param_pb2 import PearsonModelParam
  19. from federatedml.protobuf.model_migrate.converter.converter_base import ProtoConverterBase, AutoReplace
  20. class HeteroPearsonConverter(ProtoConverterBase):
  21. def convert(self, param: PearsonModelParam, meta: PearsonModelMeta,
  22. guest_id_mapping: Dict,
  23. host_id_mapping: Dict,
  24. arbiter_id_mapping: Dict
  25. ):
  26. replacer = AutoReplace(guest_id_mapping, host_id_mapping, arbiter_id_mapping)
  27. param.party = replacer.party_tuple_format(param.party)
  28. for i in range(len(param.parties)):
  29. param.parties[i] = replacer.party_tuple_format(param.parties[i])
  30. for anonymous in param.anonymous_map:
  31. anonymous.anonymous = replacer.migrate_anonymous_header(anonymous.anonymous)
  32. for names in param.all_names:
  33. for i, name in enumerate(names.names):
  34. names.names[i] = replacer.maybe_anonymous_format(name)
  35. return param, meta