code: def nlog_likelihood(self, w):
          
          time = self.time
          n_samples = self.x.shape[0]
          xw = numpy.dot(self.x, w)
  
          loss = 0
          risk_set = 0
          k = 0
          for i in range(n_samples):
              ti = time[i]
              while k < n_samples and ti == time[k]:
                  risk_set += numpy.exp(xw[k])
                  k += 1
  
              if self.event[i]:
                  loss -= (xw[i] - numpy.log(risk_set)) / n_samples
  
          # add regularization term to log-likelihood
          return loss + self.alpha * squared_norm(w) / (2. * n_samples)
docs: Compute negative partial log-likelihood
  
          Parameters
          ----------
          w : array, shape = (n_features,)
              Estimate of coefficients
  
          Returns
          -------
          loss : float
              Average negative partial log-likelihood