                  retdata.append(mean)
          logger.debug("Flattened outliers")
          return retdata
  
      def get_calculations(self):
          """ Perform the required calculations """
          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_")]
 
</s> remove             method = getattr(self, "calc_{}".format(selection))
            raw_keys = [key for key in self.stats.keys() if key.startswith("raw_")]
 </s> add             method = getattr(self, "_calc_{}".format(selection))
            raw_keys = [key for key in self._stats if key.startswith("raw_")] </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                 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 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         Returns
        -------
        dict
            The loss name as key with list of loss values as value
 </s> add         Parameters
        ----------
        amount: float
            The amount of smoothing to apply to smoothed graph
        """
        update = max(min(amount, 0.999), 0.001)
        logger.debug("Setting smooth amount to: %s (provided value: %s)", update, amount)
        self._args["smooth_amount"] = update

    def update_selections(self, selection, option):
        """ Update the type of selected data.

        Parameters
        ----------
        selection: str
            The selection to update (as can exist in :attr:`_selections`)
        option: bool
            ``True`` if the selection should be included, ``False`` if it should be removed
        """
        # TODO Somewhat hacky, to ensure values are inserted in the correct order. Fine for
        # now as this is only called from Live Graph and selections can only be "raw" and
        # smoothed.
        if option:
            if selection not in self._selections:
                if selection == "raw":
                    self._selections.insert(0, selection)
                else:
                    self._selections.append(selection)
        else:
            if selection in self._selections:
                self._selections.remove(selection)

    def set_iterations_limit(self, limit):
        """ Set the number of iterations to display in the calculations.

        If a value greater than 0 is passed, then the latest iterations up to the given
        limit will be calculated.

        Parameters
        ----------
        limit: int
            The number of iterations to calculate data for. `0` to calculate for all data
    def _get_calculations(self):
        """ Perform the required calculations and populate :attr:`stats`. """
        for selection in self._selections:
                  retdata.append(mean)
          logger.debug("Flattened outliers")
          return retdata
  
    def _get_calculations(self):
        """ Perform the required calculations and populate :attr:`stats`. """
        for selection in self._selections:
    def _get_calculations(self):
        """ Perform the required calculations and populate :attr:`stats`. """
        for selection in self._selections:
    def _get_calculations(self):
        """ Perform the required calculations and populate :attr:`stats`. """
        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_")]
keep keep keep keep replace 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