class_docstr: A Markov chain.
  
  A Markov chain is the simplest sequential model which factorizes the
  joint probability distribution P(X_{0} ... X_{t}) along a chain into the
  product of a marginal distribution P(X_{0}) P(X_{1} | X_{0}) ... with
  k conditional probability distributions for a k-th order Markov chain.
  
  Despite sometimes being thought of as an independent model, Markov chains
  are probability distributions over sequences just like hidden Markov
  models. Because a Markov chain has the same theoretical properties as a
  probability distribution, it can be used in any situation that a simpler 
  distribution could, such as an emission distribution for a HMM or a 
  component of a Bayes classifier.
  
  
  Parameters
  ----------
  distributions: tuple or list or None
          A set of distribution objects. These objects do not need to be
          initialized, i.e., can be "Categorical()". 
  
  k: int or None
          The number of conditional distributions to include in the chain, also
          the number of steps back to model in the sequence. This must be passed
          in if the distributions are not passed in.
  
  n_categories: list, numpy.ndarray, torch.tensor, or None, shape=(d,)
          A vector with the maximum number of categories that each column
          can have. If not given, this will be inferred from the data. 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","Markov","chain",".","A","Markov","chain","is","the","simplest","sequential","model","which","factorizes","the","joint","probability","distribution","P","(","X_","{","0","}","...","X_","{","t","}",")","along","a","chain","into","the","product","of","a","marginal","distribution","P","(","X_","{","0","}",")","P","(","X_","{","1","}","|","X_","{","0","}",")","...","with","k","conditional","probability","distributions","for","a","k-th","order","Markov","chain",".","Despite","sometimes","being","thought","of","as","an","independent","model",",","Markov","chains","are","probability","distributions","over","sequences","just","like","hidden","Markov","models",".","Because","a","Markov","chain","has","the","same","theoretical","properties","as","a","probability","distribution",",","it","can","be","used","in","any","situation","that","a","simpler","distribution","could",",","such","as","an","emission","distribution","for","a","HMM","or","a","component","of","a","Bayes","classifier",".","Parameters","--","--","--","--","--","distributions",":","tuple","or","list","or","None","A","set","of","distribution","objects",".","These","objects","do","not","need","to","be","initialized",",","i.e.",",","can","be","``","Categorical","(",")","''",".","k",":","int","or","None","The","number","of","conditional","distributions","to","include","in","the","chain",",","also","the","number","of","steps","back","to","model","in","the","sequence",".","This","must","be","passed","in","if","the","distributions","are","not","passed","in",".","n_categories",":","list",",","numpy.ndarray",",","torch.tensor",",","or","None",",","shape=","(","d",",",")","A","vector","with","the","maximum","number","of","categories","that","each","column","can","have",".","If","not","given",",","this","will","be","inferred","from","the","data",".","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: Extract the sufficient statistics from a batch of data.
  
  This method calculates the sufficient statistics from optionally
  weighted data and adds them to the stored cache for each distribution
  in the network. Sample weights can either be provided as one
  value per example or as a 2D matrix of weights for each feature in
  each example.
  
  
  Parameters
  ----------
  X: list, tuple, numpy.ndarray, torch.Tensor, shape=(-1, length, self.d)
          A set of examples to summarize.
  
  sample_weight: list, tuple, numpy.ndarray, torch.Tensor, optional
          A set of weights for the examples. This can be either of shape
          (-1, self.d) or a vector of shape (-1,). Default is ones.
  
  
  Returns
  -------
  logp: torch.Tensor, shape=(-1,)
          The log probability of each example.
docstr_tok: ["Extract","the","sufficient","statistics","from","a","batch","of","data",".","This","method","calculates","the","sufficient","statistics","from","optionally","weighted","data","and","adds","them","to","the","stored","cache","for","each","distribution","in","the","network",".","Sample","weights","can","either","be","provided","as","one","value","per","example","or","as","a","2D","matrix","of","weights","for","each","feature","in","each","example",".","Parameters","--","--","--","--","--","X",":","list",",","tuple",",","numpy.ndarray",",","torch.Tensor",",","shape=","(","-1",",","length",",","self.d",")","A","set","of","examples","to","summarize",".","sample_weight",":","list",",","tuple",",","numpy.ndarray",",","torch.Tensor",",","optional","A","set","of","weights","for","the","examples",".","This","can","be","either","of","shape","(","-1",",","self.d",")","or","a","vector","of","shape","(","-1",",",")",".","Default","is","ones",".","Returns","--","--","--","-","logp",":","torch.Tensor",",","shape=","(","-1",",",")","The","log","probability","of","each","example","."]
code: def summarize(self, X, sample_weight=None):
      """Extract the sufficient statistics from a batch of data.
  
      This method calculates the sufficient statistics from optionally
      weighted data and adds them to the stored cache for each distribution
      in the network. Sample weights can either be provided as one
      value per example or as a 2D matrix of weights for each feature in
      each example.
  
  
      Parameters
      ----------
      X: list, tuple, numpy.ndarray, torch.Tensor, shape=(-1, length, self.d)
              A set of examples to summarize.
  
      sample_weight: list, tuple, numpy.ndarray, torch.Tensor, optional
              A set of weights for the examples. This can be either of shape
              (-1, self.d) or a vector of shape (-1,). Default is ones.
  
  
      Returns
      -------
      logp: torch.Tensor, shape=(-1,)
              The log probability of each example.
      """
  
      if self.frozen:
          return
  
      if not self._initialized:
          self._initialize(len(X[0]))
  
      X = _check_parameter(
          _cast_as_tensor(X),
          "X",
          ndim=3,
          check_parameter=self.check_data,
      )
      sample_weight = _check_parameter(
          _cast_as_tensor(sample_weight),
          "sample_weight",
          min_value=0,
          ndim=(1, 2),
          check_parameter=self.check_data,
      )
  
      if sample_weight is None:
          sample_weight = torch.ones_like(X[:, 0])
      elif len(sample_weight.shape) == 1:
          sample_weight = sample_weight.reshape(-1, 1).expand(
              -1, X.shape[2]
          )
      elif sample_weight.shape[1] == 1:
          sample_weight = sample_weight.expand(-1, X.shape[2])
  
      _check_parameter(
          _cast_as_tensor(sample_weight),
          "sample_weight",
          min_value=0,
          ndim=2,
          shape=(X.shape[0], X.shape[2]),
          check_parameter=self.check_data,
      )
  
      self.distributions[0].summarize(
          X[:, 0], sample_weight=sample_weight
      )
      for i, distribution in enumerate(self.distributions[1:-1]):
          distribution.summarize(
              X[:, : i + 2], sample_weight=sample_weight
          )
  
      distribution = self.distributions[-1]
      for i in range(X.shape[1] - self.k):
          j = i + self.k + 1
          distribution.summarize(X[:, i:j], sample_weight=sample_weight)
  
file_path: pomegranate/pomegranate/markov_chain.py
imports: import torch
  from ._utils import _cast_as_tensor
  from ._utils import _update_parameter
  from ._utils import _check_parameter
  from ._utils import _reshape_weights
  from .distributions._distribution import Distribution
  from .distributions import Categorical
  from .distributions import ConditionalCategorical
label_desc: Use image node_id 7 for calling the MarkovChain obj's underlying member method code with example usage: obj.summarize(X, sample_weight) without return types