encrypted_mode_calculation_param.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2019 The FATE Authors. All Rights Reserved.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. from federatedml.param.base_param import BaseParam
  19. from federatedml.util import LOGGER
  20. class EncryptedModeCalculatorParam(BaseParam):
  21. """
  22. Define the encrypted_mode_calulator parameters.
  23. Parameters
  24. ----------
  25. mode: {'strict', 'fast', 'balance', 'confusion_opt'}
  26. encrypted mode, default: strict
  27. re_encrypted_rate: float or int
  28. numeric number in [0, 1], use when mode equals to 'balance', default: 1
  29. """
  30. def __init__(self, mode="strict", re_encrypted_rate=1):
  31. self.mode = mode
  32. self.re_encrypted_rate = re_encrypted_rate
  33. def check(self):
  34. descr = "encrypted_mode_calculator param"
  35. self.mode = self.check_and_change_lower(self.mode,
  36. ["strict", "fast", "balance", "confusion_opt", "confusion_opt_balance"],
  37. descr)
  38. if self.mode != "strict":
  39. LOGGER.warning("encrypted_mode_calculator will be remove in later version, "
  40. "but in current version user can still use it, but it only supports strict mode, "
  41. "other mode will be reset to strict for compatibility")
  42. self.mode = "strict"
  43. return True