class_docstr: A hidden Markov model with a sparse transition matrix.
  
  A hidden Markov model is an extension of a mixture model to sequences by
  including a transition matrix between the elements of the mixture. Each of
  the algorithms for a hidden Markov model are essentially just a revision
  of those algorithms to incorporate this transition matrix.
  
  This object is a wrapper for a hidden Markov model with a sparse transition
  matrix.
  
  Separately, there are two ways to instantiate the hidden Markov model. The
  first is by passing in a set of distributions, a dense transition matrix, 
  and optionally start/end probabilities. The second is to initialize the
  object without these and then to add edges using the `add_edge` method
  and to add distributions using the `add_distributions` method. Importantly, 
  the way that you choose to initialize the hidden Markov model is independent of the
  implementation that you end up choosing. If you pass in a dense transition
  matrix, this will be converted to a sparse matrix with all the zeros
  dropped if you choose `kind='sparse'`.
  
  
  Parameters
  ----------
  distributions: tuple or list
          A set of distribution objects. These objects do not need to be
          initialized, i.e., can be "Normal()". 
  
  edges: numpy.ndarray, torch.Tensor, or None. shape=(k,k)
          A dense transition matrix of probabilities for how each node or
          distribution passed in connects to each other one. This can contain
          many zeroes, and when paired with `kind='sparse'`, will drop those
          elements from the matrix.
  
  starts: list, numpy.ndarray, torch.Tensor, or None. shape=(k,)
          The probability of starting at each node. If not provided, assumes
          these probabilities are uniform.
  
  ends: list, numpy.ndarray, torch.Tensor, or None. shape=(k,)
          The probability of ending at each node. If not provided, assumes
          these probabilities are uniform.
  
  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","hidden","Markov","model","with","a","sparse","transition","matrix",".","A","hidden","Markov","model","is","an","extension","of","a","mixture","model","to","sequences","by","including","a","transition","matrix","between","the","elements","of","the","mixture",".","Each","of","the","algorithms","for","a","hidden","Markov","model","are","essentially","just","a","revision","of","those","algorithms","to","incorporate","this","transition","matrix",".","This","object","is","a","wrapper","for","a","hidden","Markov","model","with","a","sparse","transition","matrix",".","Separately",",","there","are","two","ways","to","instantiate","the","hidden","Markov","model",".","The","first","is","by","passing","in","a","set","of","distributions",",","a","dense","transition","matrix",",","and","optionally","start\/end","probabilities",".","The","second","is","to","initialize","the","object","without","these","and","then","to","add","edges","using","the","`","add_edge","`","method","and","to","add","distributions","using","the","`","add_distributions","`","method",".","Importantly",",","the","way","that","you","choose","to","initialize","the","hidden","Markov","model","is","independent","of","the","implementation","that","you","end","up","choosing",".","If","you","pass","in","a","dense","transition","matrix",",","this","will","be","converted","to","a","sparse","matrix","with","all","the","zeros","dropped","if","you","choose","`","kind='sparse","'","`",".","Parameters","--","--","--","--","--","distributions",":","tuple","or","list","A","set","of","distribution","objects",".","These","objects","do","not","need","to","be","initialized",",","i.e.",",","can","be","``","Normal","(",")","''",".","edges",":","numpy.ndarray",",","torch.Tensor",",","or","None",".","shape=","(","k",",","k",")","A","dense","transition","matrix","of","probabilities","for","how","each","node","or","distribution","passed","in","connects","to","each","other","one",".","This","can","contain","many","zeroes",",","and","when","paired","with","`","kind='sparse","'","`",",","will","drop","those","elements","from","the","matrix",".","starts",":","list",",","numpy.ndarray",",","torch.Tensor",",","or","None",".","shape=","(","k",",",")","The","probability","of","starting","at","each","node",".","If","not","provided",",","assumes","these","probabilities","are","uniform",".","ends",":","list",",","numpy.ndarray",",","torch.Tensor",",","or","None",".","shape=","(","k",",",")","The","probability","of","ending","at","each","node",".","If","not","provided",",","assumes","these","probabilities","are","uniform",".","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. The examples must be
  given in a 2D format. 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, 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.
  
  emissions: torch.Tensor, shape=(-1, -1, self.n_distributions)
          Precalculated emission log probabilities. These are the
          probabilities of each observation under each probability 
          distribution. When running some algorithms it is more efficient
          to precalculate these and pass them into each call.     
  
  priors: list, numpy.ndarray, torch.Tensor, shape=(-1, -1, self.k)
          Prior probabilities of assigning each symbol to each node. If not
          provided, do not include in the calculations (conceptually
          equivalent to a uniform probability, but without scaling the
          probabilities). This can be used to assign labels to observatons
          by setting one of the probabilities for an observation to 1.0.
          Note that this can be used to assign hard labels, but does not
          have the same semantics for soft labels, in that it only
          influences the initial estimate of an observation being generated
          by a component, not gives a target. Default is None.
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",".","The","examples","must","be","given","in","a","2D","format",".","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",",","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",".","emissions",":","torch.Tensor",",","shape=","(","-1",",","-1",",","self.n_distributions",")","Precalculated","emission","log","probabilities",".","These","are","the","probabilities","of","each","observation","under","each","probability","distribution",".","When","running","some","algorithms","it","is","more","efficient","to","precalculate","these","and","pass","them","into","each","call",".","priors",":","list",",","numpy.ndarray",",","torch.Tensor",",","shape=","(","-1",",","-1",",","self.k",")","Prior","probabilities","of","assigning","each","symbol","to","each","node",".","If","not","provided",",","do","not","include","in","the","calculations","(","conceptually","equivalent","to","a","uniform","probability",",","but","without","scaling","the","probabilities",")",".","This","can","be","used","to","assign","labels","to","observatons","by","setting","one","of","the","probabilities","for","an","observation","to","1.0",".","Note","that","this","can","be","used","to","assign","hard","labels",",","but","does","not","have","the","same","semantics","for","soft","labels",",","in","that","it","only","influences","the","initial","estimate","of","an","observation","being","generated","by","a","component",",","not","gives","a","target",".","Default","is","None","."]
code: def summarize(
      self, X, sample_weight=None, emissions=None, priors=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. The examples must be
      given in a 2D format. 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, 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.
  
      emissions: torch.Tensor, shape=(-1, -1, self.n_distributions)
              Precalculated emission log probabilities. These are the
              probabilities of each observation under each probability
              distribution. When running some algorithms it is more efficient
              to precalculate these and pass them into each call.
  
      priors: list, numpy.ndarray, torch.Tensor, shape=(-1, -1, self.k)
              Prior probabilities of assigning each symbol to each node. If not
              provided, do not include in the calculations (conceptually
              equivalent to a uniform probability, but without scaling the
              probabilities). This can be used to assign labels to observatons
              by setting one of the probabilities for an observation to 1.0.
              Note that this can be used to assign hard labels, but does not
              have the same semantics for soft labels, in that it only
              influences the initial estimate of an observation being generated
              by a component, not gives a target. Default is None.
      """
  
      X, emissions, sample_weight = super().summarize(
          X,
          sample_weight=sample_weight,
          emissions=emissions,
          priors=priors,
      )
  
      t, r, starts, ends, logps = self.forward_backward(
          emissions=emissions
      )
  
      self._xw_starts_sum += torch.sum(starts * sample_weight, dim=0)
      self._xw_ends_sum += torch.sum(ends * sample_weight, dim=0)
      self._xw_sum += torch.sum(t * sample_weight, dim=0)
  
      X = X.reshape(-1, X.shape[-1])
      r = torch.exp(r) * sample_weight.unsqueeze(1)
      for i, node in enumerate(self.distributions):
          w = r[:, :, i].reshape(-1, 1)
          node.summarize(X, sample_weight=w)
  
      return logps
  
imports: import math
  import numpy
  import torch
  from .._utils import _cast_as_tensor
  from .._utils import _cast_as_parameter
  from .._utils import _update_parameter
  from .._utils import _check_parameter
  from ..distributions._distribution import Distribution
  from ._base import _BaseHMM
  from ._base import _check_inputs
label_desc: Use image node_id 8 for calling the SparseHMM obj's underlying member method code with example usage: obj.summarize(X, sample_weight, emissions, priors) and returns: logps