          for selection in self.selections:
              if selection == "raw":
                  continue
              logger.debug("Calculating: %s", selection)
              method = getattr(self, "calc_{}".format(selection))
              raw_keys = [key for key in self.stats.keys() if key.startswith("raw_")]
              for key in raw_keys:
                  selected_key = "{}_{}".format(selection, key.replace("raw_", ""))
                  self.stats[selected_key] = method(self.stats[key])
  
      def calc_avg(self, data):
 
</s> remove                 self.stats[selected_key] = method(self.stats[key])
 </s> add                 self._stats[selected_key] = method(self._stats[key])

    def _calc_avg(self, data):
        """ Calculate moving average. </s> remove     def get_calculations(self):
        """ Perform the required calculations """
        for selection in self.selections:
 </s> add     def _get_calculations(self):
        """ Perform the required calculations and populate :attr:`stats`. """
        for selection in self._selections: </s> remove     def calc_avg(self, data):
        """ Calculate rolling average """
 </s> add         Parameters
        ----------
        data: :class:`numpy.ndarray`
            The data to calculate the moving average for

        Returns
        -------
        :class:`numpy.ndarray`
            The moving average for the given data
        """ </s> remove         loss_keys = [key for key in self.display_item.loss_keys if key != "total"]
 </s> add         loss_keys = [key
                     for key in self.display_item.get_loss_keys(Session.session_ids[-1])
                     if key != "total"] </s> remove             iterations = range(len(timestamps) - 1)
            rate.extend([(batchsize * 2) / (timestamps[i + 1] - timestamps[i])
                         for i in iterations])
        logger.debug("Calculated totals rate: Item_count: %s", len(rate))
        return rate

    @staticmethod
    def flatten_outliers(data):
        """ Remove the outliers from a provided list """
        logger.debug("Flattening outliers")
        retdata = list()
        samples = len(data)
        mean = (sum(data) / samples)
        limit = sqrt(sum([(item - mean)**2 for item in data]) / samples)
        logger.debug("samples: %s, mean: %s, limit: %s", samples, mean, limit)

        for idx, item in enumerate(data):
            if (mean - limit) <= item <= (mean + limit):
                retdata.append(item)
            else:
                logger.trace("Item idx: %s, value: %s flattened to %s", idx, item, mean)
                retdata.append(mean)
        logger.debug("Flattened outliers")
        return retdata
 </s> add             rate.extend((batchsize * 2) / np.diff(timestamps))
        retval = np.array(rate)
        logger.debug("Calculated totals rate: Item_count: %s", len(retval))
        return retval
            method = getattr(self, "_calc_{}".format(selection))
            raw_keys = [key for key in self._stats if key.startswith("raw_")]
          for selection in self.selections:
              if selection == "raw":
                  continue
              logger.debug("Calculating: %s", selection)
            method = getattr(self, "_calc_{}".format(selection))
            raw_keys = [key for key in self._stats if key.startswith("raw_")]
            method = getattr(self, "_calc_{}".format(selection))
            raw_keys = [key for key in self._stats if key.startswith("raw_")]
              for key in raw_keys:
                  selected_key = "{}_{}".format(selection, key.replace("raw_", ""))
                  self.stats[selected_key] = method(self.stats[key])
  
      def calc_avg(self, data):
keep keep keep keep replace replace keep keep keep keep keep
 GUI - Stats optimization (#1067)

* Faster stat loading + caching

* Compress data in cache

* Optimize some calculations

* Vectorize smoothing

* stats.Calculations optimized

* Load latest training data from live iterator

* Add options to training graph 
lib/gui/stats.py