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"]
docstr: Returns a string of the average values of the records.
  
  Args:
      precision (int, optional): The number of decimal places to keep in
          the returned string. E.g., for an average value of `0.1234`,
          :attr:`precision = 2` leads to `'0.12'`.
      delimiter (str): The delimiter string that separates between
          fields.
  
  Returns:
      A string of the average values.
  
      If record is of type `dict`, the string is a concatenation of
      'field_name: average_value', delimited with :attr:`delimiter`.
      E.g., `'field_name_1: 0.1234 field_name_2: 0.5678 ...'`.
  
      Otherwise, the string is of a concatenation of 'average_value'.
      E.g., `'0.1234 0.5678 ...'`
docstr_tok: ["Returns","a","string","of","the","average","values","of","the","records",".","Args",":","precision","(","int",",","optional",")",":","The","number","of","decimal","places","to","keep","in","the","returned","string",".","E.g.",",","for","an","average","value","of","`","0.1234","`",",",":","attr",":","`","precision","=","2","`","leads","to","`","'","0.12","'","`",".","delimiter","(","str",")",":","The","delimiter","string","that","separates","between","fields",".","Returns",":","A","string","of","the","average","values",".","If","record","is","of","type","`","dict","`",",","the","string","is","a","concatenation","of","'field_name",":","average_value","'",",","delimited","with",":","attr",":","`","delimiter","`",".","E.g.",",","`","'field_name_1",":","0.1234","field_name_2",":","0.5678","...","'","`",".","Otherwise",",","the","string","is","of","a","concatenation","of","'average_value","'",".","E.g.",",","`","'","0.1234","0.5678","...","'","`"]
code: def to_str(self, precision=None, delimiter=" "):
      """Returns a string of the average values of the records.
  
      Args:
          precision (int, optional): The number of decimal places to keep in
              the returned string. E.g., for an average value of `0.1234`,
              :attr:`precision = 2` leads to `'0.12'`.
          delimiter (str): The delimiter string that separates between
              fields.
  
      Returns:
          A string of the average values.
  
          If record is of type `dict`, the string is a concatenation of
          'field_name: average_value', delimited with :attr:`delimiter`.
          E.g., `'field_name_1: 0.1234 field_name_2: 0.5678 ...'`.
  
          Otherwise, the string is of a concatenation of 'average_value'.
          E.g., `'0.1234 0.5678 ...'`
      """
      strs = {
          name: rec.to_str(precision=precision)
          for name, rec in self._recorders.items()
      }
      str_list = []
      if self._record_type in {list, tuple}:
          for i in range(len(strs)):
              # Enumerates the keys in order, which are the indexes
              str_list.append(strs[i])
      elif self._record_type == dict:
          str_list = list(strs.values())
      else:
          str_list = [strs[self._default_metric_name]]
  
      avg_str = delimiter.join(str_list)
  
      return avg_str
  
file_path: texar/texar/tf/utils/average_recorder.py
imports: from collections import deque
label_desc: Use image node_id 6 for calling the AverageRecorder obj's underlying member method code with example usage: obj.to_str(precision, delimiter) and returns: avg_str