class_docstr: Downbeat tracking with RNNs and a dynamic Bayesian network (DBN)
  approximated by a Hidden Markov Model (HMM).
  
  Parameters
  ----------
  beats_per_bar : int or list
      Number of beats per bar to be modeled. Can be either a single number
      or a list or array with bar lengths (in beats).
  min_bpm : float or list, optional
      Minimum tempo used for beat tracking [bpm]. If a list is given, each
      item corresponds to the number of beats per bar at the same position.
  max_bpm : float or list, optional
      Maximum tempo used for beat tracking [bpm]. If a list is given, each
      item corresponds to the number of beats per bar at the same position.
  num_tempi : int or list, optional
      Number of tempi to model; if set, limit the number of tempi and use a
      log spacing, otherwise a linear spacing. If a list is given, each
      item corresponds to the number of beats per bar at the same position.
  transition_lambda : float or list, optional
      Lambda for the exponential tempo change distribution (higher values
      prefer a constant tempo from one beat to the next one).  If a list is
      given, each item corresponds to the number of beats per bar at the
      same position.
  observation_lambda : int, optional
      Split one (down-)beat period into `observation_lambda` parts, the first
      representing (down-)beat states and the remaining non-beat states.
  threshold : float, optional
      Threshold the RNN (down-)beat activations before Viterbi decoding.
  correct : bool, optional
      Correct the beats (i.e. align them to the nearest peak of the
      (down-)beat activation function).
  fps : float, optional
      Frames per second.
  
  References
  ----------
  .. [1] Sebastian Böck, Florian Krebs and Gerhard Widmer,
         "Joint Beat and Downbeat Tracking with Recurrent Neural Networks"
         Proceedings of the 17th International Society for Music Information
         Retrieval Conference (ISMIR), 2016.
  
  Examples
  --------
  Create a DBNDownBeatTrackingProcessor. The returned array represents the
  positions of the beats and their position inside the bar. The position is
  given in seconds, thus the expected sampling rate is needed. The position
  inside the bar follows the natural counting and starts at 1.
  
  The number of beats per bar which should be modelled must be given, all
  other parameters (e.g. tempo range) are optional but must have the same
  length as `beats_per_bar`, i.e. must be given for each bar length.
  
  >>> proc = DBNDownBeatTrackingProcessor(beats_per_bar=[3, 4], fps=100)
  >>> proc  # doctest: +ELLIPSIS
  <madmom.features.downbeats.DBNDownBeatTrackingProcessor object at 0x...>
  
  Call this DBNDownBeatTrackingProcessor with the beat activation function
  returned by RNNDownBeatProcessor to obtain the beat positions.
  
  >>> act = RNNDownBeatProcessor()('tests/data/audio/sample.wav')
  >>> proc(act)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
  array([[0.09, 1. ],
         [0.45, 2. ],
         ...,
         [2.14, 3. ],
         [2.49, 4. ]])
class_docstr_tok: ["Downbeat","tracking","with","RNNs","and","a","dynamic","Bayesian","network","(","DBN",")","approximated","by","a","Hidden","Markov","Model","(","HMM",")",".","Parameters","--","--","--","--","--","beats_per_bar",":","int","or","list","Number","of","beats","per","bar","to","be","modeled",".","Can","be","either","a","single","number","or","a","list","or","array","with","bar","lengths","(","in","beats",")",".","min_bpm",":","float","or","list",",","optional","Minimum","tempo","used","for","beat","tracking","[","bpm","]",".","If","a","list","is","given",",","each","item","corresponds","to","the","number","of","beats","per","bar","at","the","same","position",".","max_bpm",":","float","or","list",",","optional","Maximum","tempo","used","for","beat","tracking","[","bpm","]",".","If","a","list","is","given",",","each","item","corresponds","to","the","number","of","beats","per","bar","at","the","same","position",".","num_tempi",":","int","or","list",",","optional","Number","of","tempi","to","model",";","if","set",",","limit","the","number","of","tempi","and","use","a","log","spacing",",","otherwise","a","linear","spacing",".","If","a","list","is","given",",","each","item","corresponds","to","the","number","of","beats","per","bar","at","the","same","position",".","transition_lambda",":","float","or","list",",","optional","Lambda","for","the","exponential","tempo","change","distribution","(","higher","values","prefer","a","constant","tempo","from","one","beat","to","the","next","one",")",".","If","a","list","is","given",",","each","item","corresponds","to","the","number","of","beats","per","bar","at","the","same","position",".","observation_lambda",":","int",",","optional","Split","one","(","down-",")","beat","period","into","`","observation_lambda","`","parts",",","the","first","representing","(","down-",")","beat","states","and","the","remaining","non-beat","states",".","threshold",":","float",",","optional","Threshold","the","RNN","(","down-",")","beat","activations","before","Viterbi","decoding",".","correct",":","bool",",","optional","Correct","the","beats","(","i.e",".","align","them","to","the","nearest","peak","of","the","(","down-",")","beat","activation","function",")",".","fps",":","float",",","optional","Frames","per","second",".","References","--","--","--","--","--","..","[","1","]","Sebastian","B\u00f6ck",",","Florian","Krebs","and","Gerhard","Widmer",",","``","Joint","Beat","and","Downbeat","Tracking","with","Recurrent","Neural","Networks","''","Proceedings","of","the","17th","International","Society","for","Music","Information","Retrieval","Conference","(","ISMIR",")",",","2016",".","Examples","--","--","--","--","Create","a","DBNDownBeatTrackingProcessor",".","The","returned","array","represents","the","positions","of","the","beats","and","their","position","inside","the","bar",".","The","position","is","given","in","seconds",",","thus","the","expected","sampling","rate","is","needed",".","The","position","inside","the","bar","follows","the","natural","counting","and","starts","at","1",".","The","number","of","beats","per","bar","which","should","be","modelled","must","be","given",",","all","other","parameters","(","e.g",".","tempo","range",")","are","optional","but","must","have","the","same","length","as","`","beats_per_bar","`",",","i.e",".","must","be","given","for","each","bar","length",".",">",">",">","proc","=","DBNDownBeatTrackingProcessor","(","beats_per_bar=","[","3",",","4","]",",","fps=100",")",">",">",">","proc","#","doctest",":","+ELLIPSIS","<","madmom.features.downbeats.DBNDownBeatTrackingProcessor","object","at","0x","...",">","Call","this","DBNDownBeatTrackingProcessor","with","the","beat","activation","function","returned","by","RNNDownBeatProcessor","to","obtain","the","beat","positions",".",">",">",">","act","=","RNNDownBeatProcessor","(",")","(","'tests\/data\/audio\/sample.wav","'",")",">",">",">","proc","(","act",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","array","(","[","[","0.09",",","1",".","]",",","[","0.45",",","2",".","]",",","...",",","[","2.14",",","3",".","]",",","[","2.49",",","4",".","]","]",")"]
docstr: Add DBN downbeat tracking related arguments to an existing parser
  object.
  
  Parameters
  ----------
  parser : argparse parser instance
      Existing argparse parser object.
  beats_per_bar : int or list, optional
      Number of beats per bar to be modeled. Can be either a single
      number or a list with bar lengths (in beats).
  min_bpm : float or list, optional
      Minimum tempo used for beat tracking [bpm]. If a list is given,
      each item corresponds to the number of beats per bar at the same
      position.
  max_bpm : float or list, optional
      Maximum tempo used for beat tracking [bpm]. If a list is given,
      each item corresponds to the number of beats per bar at the same
      position.
  num_tempi : int or list, optional
      Number of tempi to model; if set, limit the number of tempi and use
      a log spacing, otherwise a linear spacing. If a list is given,
      each item corresponds to the number of beats per bar at the same
      position.
  transition_lambda : float or list, optional
      Lambda for the exponential tempo change distribution (higher values
      prefer a constant tempo over a tempo change from one beat to the
      next one). If a list is given, each item corresponds to the number
      of beats per bar at the same position.
  observation_lambda : float, optional
      Split one (down-)beat period into `observation_lambda` parts, the
      first representing (down-)beat states and the remaining non-beat
      states.
  threshold : float, optional
      Threshold the RNN (down-)beat activations before Viterbi decoding.
  correct : bool, optional
      Correct the beats (i.e. align them to the nearest peak of the
      (down-)beat activation function).
  
  Returns
  -------
  parser_group : argparse argument group
      DBN downbeat tracking argument parser group
code: def add_arguments(
      parser,
      beats_per_bar,
      min_bpm=MIN_BPM,
      max_bpm=MAX_BPM,
      num_tempi=NUM_TEMPI,
      transition_lambda=TRANSITION_LAMBDA,
      observation_lambda=OBSERVATION_LAMBDA,
      threshold=THRESHOLD,
      correct=CORRECT,
  ):
      """
      Add DBN downbeat tracking related arguments to an existing parser
      object.
  
      Parameters
      ----------
      parser : argparse parser instance
          Existing argparse parser object.
      beats_per_bar : int or list, optional
          Number of beats per bar to be modeled. Can be either a single
          number or a list with bar lengths (in beats).
      min_bpm : float or list, optional
          Minimum tempo used for beat tracking [bpm]. If a list is given,
          each item corresponds to the number of beats per bar at the same
          position.
      max_bpm : float or list, optional
          Maximum tempo used for beat tracking [bpm]. If a list is given,
          each item corresponds to the number of beats per bar at the same
          position.
      num_tempi : int or list, optional
          Number of tempi to model; if set, limit the number of tempi and use
          a log spacing, otherwise a linear spacing. If a list is given,
          each item corresponds to the number of beats per bar at the same
          position.
      transition_lambda : float or list, optional
          Lambda for the exponential tempo change distribution (higher values
          prefer a constant tempo over a tempo change from one beat to the
          next one). If a list is given, each item corresponds to the number
          of beats per bar at the same position.
      observation_lambda : float, optional
          Split one (down-)beat period into `observation_lambda` parts, the
          first representing (down-)beat states and the remaining non-beat
          states.
      threshold : float, optional
          Threshold the RNN (down-)beat activations before Viterbi decoding.
      correct : bool, optional
          Correct the beats (i.e. align them to the nearest peak of the
          (down-)beat activation function).
  
      Returns
      -------
      parser_group : argparse argument group
          DBN downbeat tracking argument parser group
  
      """
      # pylint: disable=arguments-differ
      from ..utils import OverrideDefaultListAction
  
      # add DBN parser group
      g = parser.add_argument_group(
          "dynamic Bayesian Network arguments"
      )
      # add a transition parameters
      g.add_argument(
          "--beats_per_bar",
          action=OverrideDefaultListAction,
          default=beats_per_bar,
          type=int,
          sep=",",
          help="number of beats per bar to be modeled (comma "
          "separated list of bar length in beats) "
          "[default=%(default)s]",
      )
      g.add_argument(
          "--min_bpm",
          action=OverrideDefaultListAction,
          default=min_bpm,
          type=float,
          sep=",",
          help="minimum tempo (comma separated list with one "
          "value per bar length) [bpm, default=%(default)s]",
      )
      g.add_argument(
          "--max_bpm",
          action=OverrideDefaultListAction,
          default=max_bpm,
          type=float,
          sep=",",
          help="maximum tempo (comma separated list with one "
          "value per bar length) [bpm, default=%(default)s]",
      )
      g.add_argument(
          "--num_tempi",
          action=OverrideDefaultListAction,
          default=num_tempi,
          type=int,
          sep=",",
          help="limit the number of tempi; if set, align the "
          "tempi with log spacings, otherwise linearly "
          "(comma separated list with one value per bar "
          "length) [default=%(default)s]",
      )
      g.add_argument(
          "--transition_lambda",
          action=OverrideDefaultListAction,
          default=transition_lambda,
          type=float,
          sep=",",
          help="lambda of the tempo transition distribution; "
          "higher values prefer a constant tempo over a "
          "tempo change from one beat to the next one ("
          "comma separated list with one value per bar "
          "length) [default=%(default)s]",
      )
      # observation model stuff
      g.add_argument(
          "--observation_lambda",
          action="store",
          type=float,
          default=observation_lambda,
          help="split one (down-)beat period into N parts, the "
          "first representing beat states and the remaining "
          "non-beat states [default=%(default)i]",
      )
      g.add_argument(
          "-t",
          dest="threshold",
          action="store",
          type=float,
          default=threshold,
          help="threshold the observations before Viterbi "
          "decoding [default=%(default).2f]",
      )
      # option to correct the beat positions
      if correct is True:
          g.add_argument(
              "--no_correct",
              dest="correct",
              action="store_false",
              default=correct,
              help="do not correct the (down-)beat positions "
              "(i.e. do not align them to the nearest peak "
              "of the (down-)beat activation function)",
          )
      elif correct is False:
          g.add_argument(
              "--correct",
              dest="correct",
              action="store_true",
              default=correct,
              help="correct the (down-)beat positions (i.e. "
              "align them to the nearest peak of the "
              "(down-)beat  activation function)",
          )
      # add output format stuff
      g = parser.add_argument_group("output arguments")
      g.add_argument(
          "--downbeats",
          action="store_true",
          default=False,
          help="output only the downbeats",
      )
      # return the argument group so it can be modified if needed
      return g
  
imports: from __future__ import absolute_import, division, print_function
  import sys
  import warnings
  import numpy
  from .beats import threshold_activations
  from .beats_hmm import BarStateSpace, BarTransitionModel, GMMPatternTrackingObservationModel, MultiPatternStateSpace, MultiPatternTransitionModel, RNNBeatTrackingObservationModel, RNNDownBeatTrackingObservationModel
  from ..ml.hmm import HiddenMarkovModel
  from ..processors import ParallelProcessor, Processor, SequentialProcessor
  from ..utils import string_types
label_desc: Use image node_id 3 for calling the DBNDownBeatTrackingProcessor obj's underlying member method code with example usage: obj.add_arguments(parser, beats_per_bar, min_bpm, max_bpm, num_tempi, transition_lambda, observation_lambda, threshold, correct) and returns: g