class_docstr: A base hidden Markov model.
  
  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.
  
  There are two main ways one can implement a hidden Markov model: either the
  transition matrix can be implemented in a dense, or a sparse, manner. If the
  transition matrix is dense, implementing it in a dense manner allows for
  the primary computation to use matrix multiplications which can be very
  fast. However, if the matrix is sparse, these matrix multiplications will
  be fairly slow and end up significantly slower than the sparse version of
  a matrix multiplication.
  
  This object is a wrapper for both implementations, which can be specified
  using the `kind` parameter. Choosing the right implementation will not
  effect the accuracy of the results but will change the speed at which they
  are calculated.         
  
  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 nodes using the `add_nodes` 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), optional
          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. Default is None.
  
  starts: list, numpy.ndarray, torch.Tensor, or None. shape=(k,), optional
          The probability of starting at each node. If not provided, assumes
          these probabilities are uniform. Default is None.
  
  ends: list, numpy.ndarray, torch.Tensor, or None. shape=(k,), optional
          The probability of ending at each node. If not provided, assumes
          these probabilities are uniform. Default is None.
  
  kind: str, 'sparse' or 'dense', optional
          The underlying implementation of the transition matrix to use.
          Default is 'sparse'. 
  
  init: str, optional
          The initialization to use for the k-means initialization approach.
          Default is 'first-k'. Must be one of:
  
                  'first-k': Use the first k examples from the data set
                  'random': Use a random set of k examples from the data set
                  'submodular-facility-location': Use a facility location submodular
                          objective to initialize the k-means algorithm
                  'submodular-feature-based': Use a feature-based submodular objective
                          to initialize the k-means algorithm.
  
  max_iter: int, optional
          The number of iterations to do in the EM step, which for HMMs is
          sometimes called Baum-Welch. Default is 10.
  
  tol: float, optional
          The threshold at which to stop during fitting when the improvement
          goes under. Default is 0.1.
  
  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.
  
  random_state: int or None, optional
          The random state to make randomness deterministic. If None, not
          deterministic. Default is None.
  
  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.
  
  verbose: bool, optional
          Whether to print the improvement and timings during training.
class_docstr_tok: ["A","base","hidden","Markov","model",".","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",".","There","are","two","main","ways","one","can","implement","a","hidden","Markov","model",":","either","the","transition","matrix","can","be","implemented","in","a","dense",",","or","a","sparse",",","manner",".","If","the","transition","matrix","is","dense",",","implementing","it","in","a","dense","manner","allows","for","the","primary","computation","to","use","matrix","multiplications","which","can","be","very","fast",".","However",",","if","the","matrix","is","sparse",",","these","matrix","multiplications","will","be","fairly","slow","and","end","up","significantly","slower","than","the","sparse","version","of","a","matrix","multiplication",".","This","object","is","a","wrapper","for","both","implementations",",","which","can","be","specified","using","the","`","kind","`","parameter",".","Choosing","the","right","implementation","will","not","effect","the","accuracy","of","the","results","but","will","change","the","speed","at","which","they","are","calculated",".","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","nodes","using","the","`","add_nodes","`","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",")",",","optional","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",".","Default","is","None",".","starts",":","list",",","numpy.ndarray",",","torch.Tensor",",","or","None",".","shape=","(","k",",",")",",","optional","The","probability","of","starting","at","each","node",".","If","not","provided",",","assumes","these","probabilities","are","uniform",".","Default","is","None",".","ends",":","list",",","numpy.ndarray",",","torch.Tensor",",","or","None",".","shape=","(","k",",",")",",","optional","The","probability","of","ending","at","each","node",".","If","not","provided",",","assumes","these","probabilities","are","uniform",".","Default","is","None",".","kind",":","str",",","'sparse","'","or","'dense","'",",","optional","The","underlying","implementation","of","the","transition","matrix","to","use",".","Default","is","'sparse","'",".","init",":","str",",","optional","The","initialization","to","use","for","the","k-means","initialization","approach",".","Default","is","'first-k","'",".","Must","be","one","of",":","'first-k","'",":","Use","the","first","k","examples","from","the","data","set","'random","'",":","Use","a","random","set","of","k","examples","from","the","data","set","'submodular-facility-location","'",":","Use","a","facility","location","submodular","objective","to","initialize","the","k-means","algorithm","'submodular-feature-based","'",":","Use","a","feature-based","submodular","objective","to","initialize","the","k-means","algorithm",".","max_iter",":","int",",","optional","The","number","of","iterations","to","do","in","the","EM","step",",","which","for","HMMs","is","sometimes","called","Baum-Welch",".","Default","is","10.","tol",":","float",",","optional","The","threshold","at","which","to","stop","during","fitting","when","the","improvement","goes","under",".","Default","is","0.1.","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",".","random_state",":","int","or","None",",","optional","The","random","state","to","make","randomness","deterministic",".","If","None",",","not","deterministic",".","Default","is","None",".","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",".","verbose",":","bool",",","optional","Whether","to","print","the","improvement","and","timings","during","training","."]
docstr: Add a distribution to the model.
  
  
  Parameters
  ----------
  distribution: torchegranate.distributions.Distribution
          A distribution object.
docstr_tok: ["Add","a","distribution","to","the","model",".","Parameters","--","--","--","--","--","distribution",":","torchegranate.distributions.Distribution","A","distribution","object","."]
code: def add_distribution(self, distribution):
      """Add a distribution to the model.
  
  
      Parameters
      ----------
      distribution: torchegranate.distributions.Distribution
              A distribution object.
      """
  
      if self.distributions is None:
          self.distributions = []
  
      if not isinstance(distribution, Distribution):
          raise ValueError(
              "distribution must be a distribution object."
          )
  
      self.distributions.append(distribution)
      self.d = distribution.d
  
imports: import time
  import numpy
  import torch
  from .._utils import _cast_as_tensor
  from .._utils import _cast_as_parameter
  from .._utils import _check_parameter
  from .._utils import partition_sequences
  from ..distributions._distribution import Distribution
  from ..kmeans import KMeans
label_desc: Use image node_id 6 for calling the _BaseHMM obj's underlying member method code with example usage: obj.add_distribution(distribution) without return types