              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")
          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]
 
</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                 del self.stats[key]
 </s> add                 del self._stats[key] </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 </s> remove         batchsizes = self.session.total_batchsize
        total_timestamps = self.session.total_timestamps
 </s> add         batchsizes = Session.batch_sizes
        total_timestamps = Session.get_timestamps(None) </s> remove         for key in list(self.stats.keys()):
 </s> add         for key in list(self._stats.keys()):
    def _calc_rate(self):
        """ Calculate rate per iteration.

        Returns
        -------
        :class:`numpy.ndarray`
            The training rate for each iteration of the selected session
        """
              if key.startswith("raw"):
                  del self.stats[key]
          logger.debug("Removed Raw Data from output")
  
    def _calc_rate(self):
        """ Calculate rate per iteration.

        Returns
        -------
        :class:`numpy.ndarray`
            The training rate for each iteration of the selected session
        """
    def _calc_rate(self):
        """ Calculate rate per iteration.

        Returns
        -------
        :class:`numpy.ndarray`
            The training rate for each iteration of the selected session
        """
          logger.debug("Calculating rate")
          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]
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