feldman_verifiable_sum_param.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. class FeldmanVerifiableSumParam(BaseParam):
  20. """
  21. Define how to transfer the cols
  22. Parameters
  23. ----------
  24. sum_cols : list of column index, default: None
  25. Specify which columns need to be sum. If column index is None, each of columns will be sum.
  26. q_n : int, positive integer less than or equal to 16, default: 6
  27. q_n is the number of significant decimal digit, If the data type is a float,
  28. the maximum significant digit is 16. The sum of integer and significant decimal digits should
  29. be less than or equal to 16.
  30. """
  31. def __init__(self, sum_cols=None, q_n=6):
  32. self.sum_cols = sum_cols
  33. self.q_n = q_n
  34. def check(self):
  35. self.sum_cols = [] if self.sum_cols is None else self.sum_cols
  36. if isinstance(self.sum_cols, list):
  37. for idx in self.sum_cols:
  38. if not isinstance(idx, int):
  39. raise ValueError(f"type mismatch, column_indexes with element {idx}(type is {type(idx)})")
  40. if not isinstance(self.q_n, int):
  41. raise ValueError(f"Init param's q_n {self.q_n} not supported, should be int type", type is {type(self.q_n)})
  42. if self.q_n < 0:
  43. raise ValueError(f"param's q_n {self.q_n} not supported, should be non-negative int value")
  44. elif self.q_n > 16:
  45. raise ValueError(f"param's q_n {self.q_n} not supported, should be less than or equal to 16")