encrypted_mode_calculation_param.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 pipeline.param.base_param import BaseParam
  19. class EncryptedModeCalculatorParam(BaseParam):
  20. """
  21. Define the encrypted_mode_calulator parameters.
  22. Parameters
  23. ----------
  24. mode: {'strict', 'fast', 'balance', 'confusion_opt'}
  25. encrypted mode, default: strict
  26. re_encrypted_rate: float or int
  27. numeric number in [0, 1], use when mode equals to 'balance', default: 1
  28. """
  29. def __init__(self, mode="strict", re_encrypted_rate=1):
  30. self.mode = mode
  31. self.re_encrypted_rate = re_encrypted_rate
  32. def check(self):
  33. descr = "encrypted_mode_calculator param"
  34. self.mode = self.check_and_change_lower(self.mode,
  35. ["strict", "fast", "balance", "confusion_opt", "confusion_opt_balance"],
  36. descr)
  37. if self.mode in ["balance", "confusion_opt_balance"]:
  38. if type(self.re_encrypted_rate).__name__ not in ["int", "long", "float"]:
  39. raise ValueError("re_encrypted_rate should be a numeric number")
  40. if not 0.0 <= self.re_encrypted_rate <= 1:
  41. raise ValueError("re_encrypted_rate should in [0, 1]")
  42. return True