<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_average_summary(self, var, tag=None, decay=0.999, ignore_nan=True):
 """Add a summary with the moving average of var. Adds a variable to keep track of the exponential moving average and adds an update operation to the bookkeeper. The name of the variable is '%s_average' % name prefixed with the current variable scope. Args: var: The variable for which a moving average should be computed. tag: The tag of the summary. If None var.name[:-2] is used to strip off the ':0' that is added by TF. decay: How much history to use in the moving average. Higher, means more history values [0.9, 1) accepted. ignore_nan: If the value is NaN or Inf, skip it. Note that this default is different than the exponential_moving_average one. Returns: The averaged variable. Raises: ValueError: if decay is not in [0.9, 1). """

    if not self.summary_collections:
      return
    with self.g.as_default():
      if decay < 0.9 or decay >= 1.0:
        raise ValueError('Decay is %5.2f, but has to be in [0, 1).' % decay)
      avg_var = self.exponential_moving_average(var,
                                                decay=decay,
                                                ignore_nan=ignore_nan)
      if tag is None:
        tag = _bare_var_name(avg_var)
        tag = self.g.unique_name(tag)
      self.add_scalar_summary(avg_var, tag)
      return avg_var