def test_compute_partition_gradient(self):
     fore_gradient = self.en_wx.join(self.data_inst, lambda wx, d: 0.25 * wx - 0.5 * d.label)
     sparse_data = self._make_sparse_data()
     for fit_intercept in [True, False]:
         dense_result = hetero_linear_model_gradient.compute_gradient(self.data_inst, fore_gradient, fit_intercept)
         dense_result = [self.paillier_encrypt.decrypt(iterator) for iterator in dense_result]
         if fit_intercept:
             self.assertListEqual(dense_result, self.gradient_fit_intercept)
         else:
             self.assertListEqual(dense_result, self.gradient)
         sparse_result = hetero_linear_model_gradient.compute_gradient(sparse_data, fore_gradient, fit_intercept)
         sparse_result = [self.paillier_encrypt.decrypt(iterator) for iterator in sparse_result]
         self.assertListEqual(dense_result, sparse_result)
 def compute_forward_hess(self, data_instances, delta_s, host_forwards):
     """
     To compute Hessian matrix, y, s are needed.
     g = (1/N)*∑(wx - y) * x
     y = ∇2^F(w_t)s_t = g' * s = (1/N)*∑(x * s) * x
     define forward_hess = (1/N)*∑(x * s)
     """
     forwards = data_instances.mapValues(
         lambda v: (np.dot(v.features, delta_s.coef_) + delta_s.intercept_))
     for host_forward in host_forwards:
         forwards = forwards.join(host_forward, lambda g, h: g + h)
     hess_vector = hetero_linear_model_gradient.compute_gradient(
         data_instances, forwards, delta_s.fit_intercept)
     return forwards, np.array(hess_vector)