sqn_param.py 1.8 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. from federatedml.param.base_param import BaseParam
  18. class StochasticQuasiNewtonParam(BaseParam):
  19. """
  20. Parameters used for stochastic quasi-newton method.
  21. Parameters
  22. ----------
  23. update_interval_L : int, default: 3
  24. Set how many iteration to update hess matrix
  25. memory_M : int, default: 5
  26. Stack size of curvature information, i.e. y_k and s_k in the paper.
  27. sample_size : int, default: 5000
  28. Sample size of data that used to update Hess matrix
  29. """
  30. def __init__(self, update_interval_L=3, memory_M=5, sample_size=5000, random_seed=None):
  31. super().__init__()
  32. self.update_interval_L = update_interval_L
  33. self.memory_M = memory_M
  34. self.sample_size = sample_size
  35. self.random_seed = random_seed
  36. def check(self):
  37. descr = "hetero sqn param's"
  38. self.check_positive_integer(self.update_interval_L, descr)
  39. self.check_positive_integer(self.memory_M, descr)
  40. self.check_positive_integer(self.sample_size, descr)
  41. if self.random_seed is not None:
  42. self.check_positive_integer(self.random_seed, descr)
  43. return True