class_docstr: A categorical distribution object.
  
  A categorical distribution models the probability of a set of distinct
  values happening. It is an extension of the Bernoulli distribution to
  multiple values. Sometimes it is refered to as a discrete distribution,
  but this distribution does not enforce that the numeric values used for the
  keys have any relationship based on their identity. Permuting the keys will
  have no effect on the calculation. This distribution assumes that the
  features are independent from each other.
  
  The keys must be contiguous non-negative integers that begin at zero. 
  Because the probabilities are represented as a single tensor, each feature
  must have values for all keys up to the maximum key of any one distribution.
  Specifically, if one feature has 10 keys and a second feature has only 4,
  the tensor must go out to 10 for each feature but encode probabilities of
  zero for the second feature. 
  
  
  Parameters
  ----------
  probs: list, numpy.ndarray, torch.tensor or None, shape=(k, d), optional
          Probabilities for each key for each feature, where k is the largest
          number of keys across all features. Default is None
  
  inertia: float, (0, 1), optional
          Indicates the proportion of the update to apply to the parameters
          during training. When the inertia is 0.0, the update is applied in
          its entirety and the previous parameters are ignored. When the
          inertia is 1.0, the update is entirely ignored and the previous
          parameters are kept, equivalently to if the parameters were frozen.
  
  frozen: bool, optional
          Whether all the parameters associated with this distribution are frozen.
          If you want to freeze individual pameters, or individual values in those
          parameters, you must modify the `frozen` attribute of the tensor or
          parameter directly. Default is False.
  
  check_data: bool, optional
          Whether to check properties of the data and potentially recast it to
          torch.tensors. This does not prevent checking of parameters but can
          slightly speed up computation when you know that your inputs are valid.
          Setting this to False is also necessary for compiling.
class_docstr_tok: ["A","categorical","distribution","object",".","A","categorical","distribution","models","the","probability","of","a","set","of","distinct","values","happening",".","It","is","an","extension","of","the","Bernoulli","distribution","to","multiple","values",".","Sometimes","it","is","refered","to","as","a","discrete","distribution",",","but","this","distribution","does","not","enforce","that","the","numeric","values","used","for","the","keys","have","any","relationship","based","on","their","identity",".","Permuting","the","keys","will","have","no","effect","on","the","calculation",".","This","distribution","assumes","that","the","features","are","independent","from","each","other",".","The","keys","must","be","contiguous","non-negative","integers","that","begin","at","zero",".","Because","the","probabilities","are","represented","as","a","single","tensor",",","each","feature","must","have","values","for","all","keys","up","to","the","maximum","key","of","any","one","distribution",".","Specifically",",","if","one","feature","has","10","keys","and","a","second","feature","has","only","4",",","the","tensor","must","go","out","to","10","for","each","feature","but","encode","probabilities","of","zero","for","the","second","feature",".","Parameters","--","--","--","--","--","probs",":","list",",","numpy.ndarray",",","torch.tensor","or","None",",","shape=","(","k",",","d",")",",","optional","Probabilities","for","each","key","for","each","feature",",","where","k","is","the","largest","number","of","keys","across","all","features",".","Default","is","None","inertia",":","float",",","(","0",",","1",")",",","optional","Indicates","the","proportion","of","the","update","to","apply","to","the","parameters","during","training",".","When","the","inertia","is","0.0",",","the","update","is","applied","in","its","entirety","and","the","previous","parameters","are","ignored",".","When","the","inertia","is","1.0",",","the","update","is","entirely","ignored","and","the","previous","parameters","are","kept",",","equivalently","to","if","the","parameters","were","frozen",".","frozen",":","bool",",","optional","Whether","all","the","parameters","associated","with","this","distribution","are","frozen",".","If","you","want","to","freeze","individual","pameters",",","or","individual","values","in","those","parameters",",","you","must","modify","the","`","frozen","`","attribute","of","the","tensor","or","parameter","directly",".","Default","is","False",".","check_data",":","bool",",","optional","Whether","to","check","properties","of","the","data","and","potentially","recast","it","to","torch.tensors",".","This","does","not","prevent","checking","of","parameters","but","can","slightly","speed","up","computation","when","you","know","that","your","inputs","are","valid",".","Setting","this","to","False","is","also","necessary","for","compiling","."]
docstr: Calculate the log probability of each example.
  
  This method calculates the log probability of each example given the
  parameters of the distribution. The examples must be given in a 2D
  format. For a categorical distribution, each entry in the data must
  be an integer in the range [0, n_keys).
  
  Note: This differs from some other log probability calculation
  functions, like those in torch.distributions, because it is not
  returning the log probability of each feature independently, but rather
  the total log probability of the entire example.
  
  
  Parameters
  ----------
  X: list, tuple, numpy.ndarray, torch.Tensor, shape=(-1, self.d)
          A set of examples to evaluate.
  
  
  Returns
  -------
  logp: torch.Tensor, shape=(-1,)
          The log probability of each example.
docstr_tok: ["Calculate","the","log","probability","of","each","example",".","This","method","calculates","the","log","probability","of","each","example","given","the","parameters","of","the","distribution",".","The","examples","must","be","given","in","a","2D","format",".","For","a","categorical","distribution",",","each","entry","in","the","data","must","be","an","integer","in","the","range","[","0",",","n_keys",")",".","Note",":","This","differs","from","some","other","log","probability","calculation","functions",",","like","those","in","torch.distributions",",","because","it","is","not","returning","the","log","probability","of","each","feature","independently",",","but","rather","the","total","log","probability","of","the","entire","example",".","Parameters","--","--","--","--","--","X",":","list",",","tuple",",","numpy.ndarray",",","torch.Tensor",",","shape=","(","-1",",","self.d",")","A","set","of","examples","to","evaluate",".","Returns","--","--","--","-","logp",":","torch.Tensor",",","shape=","(","-1",",",")","The","log","probability","of","each","example","."]
code: def log_probability(self, X):
      """Calculate the log probability of each example.
  
      This method calculates the log probability of each example given the
      parameters of the distribution. The examples must be given in a 2D
      format. For a categorical distribution, each entry in the data must
      be an integer in the range [0, n_keys).
  
      Note: This differs from some other log probability calculation
      functions, like those in torch.distributions, because it is not
      returning the log probability of each feature independently, but rather
      the total log probability of the entire example.
  
  
      Parameters
      ----------
      X: list, tuple, numpy.ndarray, torch.Tensor, shape=(-1, self.d)
              A set of examples to evaluate.
  
  
      Returns
      -------
      logp: torch.Tensor, shape=(-1,)
              The log probability of each example.
      """
  
      X = _check_parameter(
          _cast_as_tensor(X),
          "X",
          min_value=0.0,
          max_value=self.n_keys - 1,
          ndim=2,
          shape=(-1, self.d),
          check_parameter=self.check_data,
      )
  
      logps = torch.zeros(X.shape[0], dtype=self.probs.dtype)
      for i in range(self.d):
          if isinstance(X, torch.masked.MaskedTensor):
              logp_ = self._log_probs[i][X[:, i]._masked_data]
              logp_[~X[:, i]._masked_mask] = 0
              logps += logp_
          else:
              logps += self._log_probs[i][X[:, i]]
  
      return logps
  
file_path: pomegranate/pomegranate/distributions/categorical.py
imports: import torch
  from .._utils import _inplace_add
  from .._utils import _cast_as_tensor
  from .._utils import _cast_as_parameter
  from .._utils import _update_parameter
  from .._utils import _check_parameter
  from .._utils import _reshape_weights
  from ._distribution import Distribution
label_desc: Use image node_id 5 for calling the Categorical obj's underlying member method code with example usage: obj.log_probability(X) and returns: logps