class_docstr: Helper class to record arbitrary stats during VI
  
  It is possible to pass a function that takes no arguments
  If call fails then (approx, hist, i) are passed
  
  
  Parameters
  ----------
  kwargs: key word arguments
      keys mapping statname to callable that records the stat
  
  Examples
  --------
  Consider we want time on each iteration
  >>> import time
  >>> tracker = Tracker(time=time.time)
  >>> with model:
  ...     approx = pm.fit(callbacks=[tracker])
  
  Time can be accessed via :code:`tracker['time']` now
  For more complex summary one can use callable that takes
  (approx, hist, i) as arguments
  >>> with model:
  ...     my_callable = lambda ap, h, i: h[-1]
  ...     tracker = Tracker(some_stat=my_callable)
  ...     approx = pm.fit(callbacks=[tracker])
  
  Multiple stats are valid too
  >>> with model:
  ...     tracker = Tracker(some_stat=my_callable, time=time.time)
  ...     approx = pm.fit(callbacks=[tracker])
class_docstr_tok: ["Helper","class","to","record","arbitrary","stats","during","VI","It","is","possible","to","pass","a","function","that","takes","no","arguments","If","call","fails","then","(","approx",",","hist",",","i",")","are","passed","Parameters","--","--","--","--","--","kwargs",":","key","word","arguments","keys","mapping","statname","to","callable","that","records","the","stat","Examples","--","--","--","--","Consider","we","want","time","on","each","iteration",">",">",">","import","time",">",">",">","tracker","=","Tracker","(","time=time.time",")",">",">",">","with","model",":","...","approx","=","pm.fit","(","callbacks=","[","tracker","]",")","Time","can","be","accessed","via",":","code",":","`","tracker","[","'time","'","]","`","now","For","more","complex","summary","one","can","use","callable","that","takes","(","approx",",","hist",",","i",")","as","arguments",">",">",">","with","model",":","...","my_callable","=","lambda","ap",",","h",",","i",":","h","[","-1","]","...","tracker","=","Tracker","(","some_stat=my_callable",")","...","approx","=","pm.fit","(","callbacks=","[","tracker","]",")","Multiple","stats","are","valid","too",">",">",">","with","model",":","...","tracker","=","Tracker","(","some_stat=my_callable",",","time=time.time",")","...","approx","=","pm.fit","(","callbacks=","[","tracker","]",")"]
code: def record(self, approx, hist, i):
      for key, fn in self.whatchdict.items():
          try:
              res = fn()
          # if `*t` argument is used
          # fail will be somehow detected.
          # We want both calls to be tried.
          # Upper one has more priority as
          # arbitrary functions can have some
          # defaults in positionals. Bad idea
          # to try fn(approx, hist, i) first
          except Exception:
              res = fn(approx, hist, i)
          self.hist[key].append(res)
  
file_path: pymc/pymc/variational/callbacks.py
imports: import collections
  from typing import Callable, Dict
  import numpy
label_desc: Use image node_id 2 for calling the Tracker obj's underlying member method code with example usage: obj.record(approx, hist, i) without return types