code: def _func(self, X, *args):
      user_data = args[0]
      item_data = args[1]
      R_user = user_data[1]
      R_item = item_data[1]
      grad = np.zeros_like(X)
      (
          alpha,
          kappa,
          beta_u,
          beta_i,
          gamma_u,
          gamma_i,
          topic_word,
      ) = self._get_view(params=X)
      (
          dalpha,
          dkappa,
          dbeta_u,
          dbeta_i,
          dgamma_u,
          dgamma_i,
          dtopic_word,
      ) = self._get_view(params=grad)
      cf_loss = 0.0
      reg_loss = 0.0
      corpus_likelihood = 0.0
  
      for i in range(self.n_user):
          idx_item = user_data[0][i]
          if not len(idx_item):  # user without any rating
              continue
          gamma_items = gamma_i[idx_item]
          R_i = R_user[i]
          pred = (
              alpha
              + beta_u[i]
              + beta_i[idx_item]
              + gamma_items.dot(gamma_u[i])
          )
          err = (pred - R_i).reshape(-1, 1)
          cf_loss += np.sum(err**2)
  
          total_err = np.sum(err)
          dalpha += 2 * total_err
          dbeta_u[i] += 2 * total_err
          dgamma_u[i] += 2 * np.sum(err * gamma_items, axis=0)
  
      for j in range(self.n_item):
          idx_user = item_data[0][j]
          if not len(idx_user):  # item without any rating
              continue
          gamma_users = gamma_u[idx_user]
          R_j = R_item[j]
          pred = (
              alpha
              + beta_u[idx_user]
              + beta_i[j]
              + gamma_users.dot(gamma_i[j])
          )
          err = (pred - R_j).reshape(-1, 1)
          total_err = np.sum(err)
          dbeta_i[j] += 2 * total_err
          dgamma_i[j] += 2 * np.sum(err * gamma_users, axis=0)
  
      if self.l2_reg > 0:
          reg_loss += self.l2_reg * np.sum(gamma_u**2)
          dgamma_u += 2 * self.l2_reg * gamma_u
          reg_loss += self.l2_reg * np.sum(gamma_i**2)
          dgamma_i += 2 * self.l2_reg * gamma_i
  
      e_theta = np.exp(self.kappa * self.gamma_i)
      t_z = e_theta.sum(axis=1, keepdims=True)
      corpus_likelihood += self.lambda_text * np.sum(
          self.item_topic_cnt
          * (self.kappa * self.gamma_i - np.log(t_z))
      )
  
      e_phi = np.exp(self.background_word + topic_word)
      word_z = e_phi.sum(axis=0, keepdims=True)
      corpus_likelihood += self.lambda_text * np.sum(
          self.word_topic_cnt
          * (self.background_word + topic_word - np.log(word_z))
      )
  
      q = -self.lambda_text * (
          self.item_topic_cnt - self.item_word * e_theta / t_z
      )
      dgamma_i += kappa * q
      dkappa += np.sum(gamma_i * q)
      dtopic_word += -self.lambda_text * (
          self.word_topic_cnt - self.topic_cnt * e_phi / word_z
      )
  
      loss = cf_loss + reg_loss - corpus_likelihood
  
      return loss, grad
  
file_path: cornac/cornac/models/hft/hft.py
imports: import numpy
  import scipy.optimize
label_desc: Use image node_id 9 for calling the Model obj's underlying member method code with example usage: obj._func(X) and returns: loss,  grad