              return
          logger.debug("Removing Raw Data from output")
          for key in list(self.stats.keys()):
              if key.startswith("raw"):
                  del self.stats[key]
          logger.debug("Removed Raw Data from output")
  
      def calc_rate(self):
          """ Calculate rate per iteration """
          logger.debug("Calculating rate")
 
</s> remove         for key in list(self.stats.keys()):
 </s> add         for key in list(self._stats.keys()): </s> remove     def calc_rate(self):
        """ Calculate rate per iteration """
 </s> add     def _calc_rate(self):
        """ Calculate rate per iteration.

        Returns
        -------
        :class:`numpy.ndarray`
            The training rate for each iteration of the selected session
        """ </s> remove     def remove_raw(self):
        """ Remove raw values from stats if not requested """
        if "raw" in self.selections:
 </s> add     @classmethod
    def _flatten_outliers(cls, data):
        """ Remove the outliers from a provided list.

        Removes data more than 1 Standard Deviation from the mean.

        Parameters
        ----------
        data: :class:`numpy.ndarray`
            The data to remove the outliers from

        Returns
        -------
        :class:`numpy.ndarray`
            The data with outliers removed
        """
        logger.debug("Flattening outliers: %s", data.shape)
        mean = np.mean(data)
        limit = np.std(data)
        logger.debug("mean: %s, limit: %s", mean, limit)
        retdata = np.where(abs(data - mean) < limit, data, mean)
        logger.debug("Flattened outliers")
        return retdata

    def _remove_raw(self):
        """ Remove raw values from :attr:`stats` if they are not requested. """
        if "raw" in self._selections: </s> remove         batchsize = self.session.batchsize
        timestamps = self.session.timestamps
        iterations = range(len(timestamps) - 1)
        rate = [(batchsize * 2) / (timestamps[i + 1] - timestamps[i]) for i in iterations]
        logger.debug("Calculated rate: Item_count: %s", len(rate))
        return rate

    def calc_rate_total(self):
        """ Calculate rate per iteration
            NB: For totals, gaps between sessions can be large
            so time difference has to be reset for each session's
            rate calculation """
 </s> add         retval = (Session.batch_sizes[self._session_id] * 2) / np.diff(Session.get_timestamps(
            self._session_id))
        logger.debug("Calculated rate: Item_count: %s", len(retval))
        return retval

    @classmethod
    def _calc_rate_total(cls):
        """ Calculate rate per iteration for all sessions.

        Returns
        -------
        :class:`numpy.ndarray`
            The training rate for each iteration in all sessions

        Notes
        -----
        For totals, gaps between sessions can be large so the time difference has to be reset for
        each session's rate calculation.
        """ </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.
                del self._stats[key]
              return
          logger.debug("Removing Raw Data from output")
          for key in list(self.stats.keys()):
              if key.startswith("raw"):
                del self._stats[key]
          logger.debug("Removed Raw Data from output")
  
      def calc_rate(self):
          """ Calculate rate per iteration """
          logger.debug("Calculating rate")
keep keep keep keep 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