class_docstr: Maintains the moving averages (i.e., the average of the latest N
  records) of (possibly multiple) fields.
  
  Fields are determined by the first call of :meth:`add`.
  
  Args:
      size (int, optional): The window size of moving average. If `None`,
          the average of all added records is maintained.
  
  Example:
  
      .. code-block:: python
  
          ## Use to maintain moving average of training loss
          avg_rec = AverageRecorder(size=10) # average over latest 10 records
          while training:
              loss_0, loss_1  = ...
              avg_rec.add([loss_0, loss_1])
              # avg_rec.avg() == [0.12343452, 0.567800323]
              # avg_rec.avg(0) == 0.12343452
              # avg_rec.to_str(precision=2, ) == '0.12 0.57'
  
          ## Use to maintain average of test metrics on the whole test set
          avg_rec = AverageRecorder() # average over ALL records
          while test:
              metric_0, metric_1  = ...
              avg_rec.add({'m0': metric_0, 'm1': metric_1}) # dict is allowed
          print(avg_rec.to_str(precision=4, delimiter=' , '))
          # 'm0: 0.1234 , m1: 0.5678'
          #
          # avg_rec.avg() == {'m0': 0.12343452, 'm1': 0.567800323}
          # avg_rec.avg(0) == 0.12343452
class_docstr_tok: ["Maintains","the","moving","averages","(","i.e.",",","the","average","of","the","latest","N","records",")","of","(","possibly","multiple",")","fields",".","Fields","are","determined","by","the","first","call","of",":","meth",":","`","add","`",".","Args",":","size","(","int",",","optional",")",":","The","window","size","of","moving","average",".","If","`","None","`",",","the","average","of","all","added","records","is","maintained",".","Example",":","..","code-block",":",":","python","#","#","Use","to","maintain","moving","average","of","training","loss","avg_rec","=","AverageRecorder","(","size=10",")","#","average","over","latest","10","records","while","training",":","loss_0",",","loss_1","=","...","avg_rec.add","(","[","loss_0",",","loss_1","]",")","#","avg_rec.avg","(",")","==","[","0.12343452",",","0.567800323","]","#","avg_rec.avg","(","0",")","==","0.12343452","#","avg_rec.to_str","(","precision=2",",",")","==","'","0.12","0.57'","#","#","Use","to","maintain","average","of","test","metrics","on","the","whole","test","set","avg_rec","=","AverageRecorder","(",")","#","average","over","ALL","records","while","test",":","metric_0",",","metric_1","=","...","avg_rec.add","(","{","'m0","'",":","metric_0",",","'m1","'",":","metric_1","}",")","#","dict","is","allowed","print","(","avg_rec.to_str","(","precision=4",",","delimiter=","'",",","'",")",")","#","'m0",":","0.1234",",","m1",":","0.5678'","#","#","avg_rec.avg","(",")","==","{","'m0","'",":","0.12343452",",","'m1","'",":","0.567800323","}","#","avg_rec.avg","(","0",")","==","0.12343452"]
code: def __init__(self, size=None):
      if size is not None and size <= 0:
          raise ValueError("`size` must be > 0 or `None`.")
      self._size = size
      self._recorders = None
      self._default_metric_name = "metric"
      self._record_type = None
  
file_path: texar/texar/tf/utils/average_recorder.py
imports: from collections import deque
label_desc: Use image node_id 1 to create a new AverageRecorder object from inherited base classes: object with example: obj = AverageRecorder(size)