예제 #1
0
 def __init__(self,
              network,
              eps=0.07,
              alpha=None,
              bounds=None,
              loss_fn=None):
     super(GradientMethod, self).__init__()
     self._network = check_model('network', network, Cell)
     self._eps = check_value_positive('eps', eps)
     self._dtype = None
     if bounds is not None:
         self._bounds = check_param_multi_types('bounds', bounds,
                                                [list, tuple])
         for b in self._bounds:
             _ = check_param_multi_types('bound', b, [int, float])
     else:
         self._bounds = bounds
     if alpha is not None:
         self._alpha = check_value_positive('alpha', alpha)
     else:
         self._alpha = alpha
     if loss_fn is None:
         loss_fn = SoftmaxCrossEntropyWithLogits(is_grad=False,
                                                 sparse=False)
     with_loss_cell = WithLossCell(self._network, loss_fn)
     self._grad_all = GradWrapWithLoss(with_loss_cell)
     self._grad_all.set_train()
예제 #2
0
파일: lbfgs.py 프로젝트: x361023/mindarmour
 def __init__(self,
              network,
              eps=1e-5,
              bounds=(0.0, 1.0),
              is_targeted=True,
              nb_iter=150,
              search_iters=30,
              loss_fn=None,
              sparse=False):
     super(LBFGS, self).__init__()
     self._network = check_model('network', network, Cell)
     self._eps = check_value_positive('eps', eps)
     self._is_targeted = check_param_type('is_targeted', is_targeted, bool)
     self._nb_iter = check_int_positive('nb_iter', nb_iter)
     self._search_iters = check_int_positive('search_iters', search_iters)
     if loss_fn is None:
         loss_fn = SoftmaxCrossEntropyWithLogits(is_grad=False,
                                                 sparse=False)
     with_loss_cell = WithLossCell(self._network, loss_fn)
     self._grad_all = GradWrapWithLoss(with_loss_cell)
     self._dtype = None
     self._bounds = check_param_multi_types('bounds', bounds, [list, tuple])
     self._sparse = check_param_type('sparse', sparse, bool)
     for b in self._bounds:
         _ = check_param_multi_types('bound', b, [int, float])
     box_max, box_min = bounds
     if box_max < box_min:
         self._box_min = box_max
         self._box_max = box_min
     else:
         self._box_min = box_min
         self._box_max = box_max
 def __init__(self, network, eps=0.3, eps_iter=0.1, bounds=(0.0, 1.0), nb_iter=5,
              loss_fn=None):
     super(IterativeGradientMethod, self).__init__()
     self._network = check_model('network', network, Cell)
     self._eps = check_value_positive('eps', eps)
     self._eps_iter = check_value_positive('eps_iter', eps_iter)
     self._nb_iter = check_int_positive('nb_iter', nb_iter)
     self._bounds = None
     if bounds is not None:
         self._bounds = check_param_multi_types('bounds', bounds, [list, tuple])
         for b in self._bounds:
             _ = check_param_multi_types('bound', b, [int, float])
     if loss_fn is None:
         self._loss_grad = network
     else:
         self._loss_grad = GradWrapWithLoss(WithLossCell(self._network, loss_fn))
     self._loss_grad.set_train()