parameters: (self, preds, dataset)
return_statement: return grad, hess
docstring: Call passed function with appropriate arguments.
  
          Parameters
          ----------
          preds : numpy 1-D array of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task)
              The predicted values.
          dataset : Dataset
              The training dataset.
  
          Returns
          -------
          grad : list, numpy 1-D array or pandas Series of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task)
              The value of the first order derivative (gradient) of the loss
              with respect to the elements of preds for each sample point.
          hess : list, numpy 1-D array or pandas Series of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task)
              The value of the second order derivative (Hessian) of the loss
              with respect to the elements of preds for each sample point.
docstring_summary: Call passed function with appropriate arguments.
docstring_tokens: Call passed function with appropriate arguments .
function: def __call__(self, preds, dataset):
          """Call passed function with appropriate arguments.
  
          Parameters
          ----------
          preds : numpy 1-D array of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task)
              The predicted values.
          dataset : Dataset
              The training dataset.
  
          Returns
          -------
          grad : list, numpy 1-D array or pandas Series of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task)
              The value of the first order derivative (gradient) of the loss
              with respect to the elements of preds for each sample point.
          hess : list, numpy 1-D array or pandas Series of shape = [n_samples] or shape = [n_samples * n_classes] (for multi-class task)
              The value of the second order derivative (Hessian) of the loss
              with respect to the elements of preds for each sample point.
          """
          labels = dataset.get_label()
          argc = len(signature(self.func).parameters)
          if argc == 2:
              grad, hess = self.func(labels, preds)
          elif argc == 3:
              grad, hess = self.func(labels, preds, dataset.get_group())
          else:
              raise TypeError(f"Self-defined objective function should have 2 or 3 arguments, got {argc}")
          """weighted for objective"""
          weight = dataset.get_weight()
          if weight is not None:
              """only one class"""
              if len(weight) == len(grad):
                  grad = np.multiply(grad, weight)
                  hess = np.multiply(hess, weight)
              else:
                  num_data = len(weight)
                  num_class = len(grad) // num_data
                  if num_class * num_data != len(grad):
                      raise ValueError("Length of grad and hess should equal to num_class * num_data")
                  for k in range(num_class):
                      for i in range(num_data):
                          idx = k * num_data + i
                          grad[idx] *= weight[i]
                          hess[idx] *= weight[i]
          return grad, hess
function_tokens: def __call__ ( self , preds , dataset ) : labels = dataset . get_label ( ) argc = len ( signature ( self . func ) . parameters ) if argc == 2 : grad , hess = self . func ( labels , preds ) elif argc == 3 : grad , hess = self . func ( labels , preds , dataset . get_group ( ) ) else : raise TypeError ( f"Self-defined objective function should have 2 or 3 arguments, got {argc}" ) """weighted for objective""" weight = dataset . get_weight ( ) if weight is not None : """only one class""" if len ( weight ) == len ( grad ) : grad = np . multiply ( grad , weight ) hess = np . multiply ( hess , weight ) else : num_data = len ( weight ) num_class = len ( grad ) // num_data if num_class * num_data != len ( grad ) : raise ValueError ( "Length of grad and hess should equal to num_class * num_data" ) for k in range ( num_class ) : for i in range ( num_data ) : idx = k * num_data + i grad [ idx ] *= weight [ i ] hess [ idx ] *= weight [ i ] return grad , hess