docstr: Compute the logarithm of the external field, where the
  external field is defined as the likelihood times the
  first-order component of the prior.
docstr_tok: ["Compute","the","logarithm","of","the","external","field",",","where","the","external","field","is","defined","as","the","likelihood","times","the","first-order","component","of","the","prior","."]
code: def log_external_field(self):
      """
      Compute the logarithm of the external field, where the
      external field is defined as the likelihood times the
      first-order component of the prior.
      """
      lef = np.zeros([self.data.shape[0], self.nclasses])
  
      for i in range(self.nclasses):
          centered_data = self.data - self.mu[i]
          if self.nchannels == 1:
              inv_sigma = 1.0 / nonzero(self.sigma[i])
              norm_factor = np.sqrt(inv_sigma.squeeze())
          else:
              inv_sigma = np.linalg.inv(self.sigma[i])
              norm_factor = 1.0 / np.sqrt(
                  nonzero(np.linalg.det(self.sigma[i]))
              )
          maha_dist = np.sum(
              centered_data * np.dot(inv_sigma, centered_data.T).T, 1
          )
          lef[:, i] = -0.5 * maha_dist
          lef[:, i] += log(norm_factor)
  
      if self.prior is not None:
          lef += log(self.prior)
  
      return lef
  
file_path: nipy/nipy/algorithms/segmentation/segmentation.py
imports: import numpy
  from ._segmentation import _interaction_energy, _ve_step
label_desc: Use image node_id 4 for calling the Segmentation obj's underlying member method code with example usage: obj.log_external_field() and returns: lef