          dict
              The loss name as key with list of loss values as value
          """
          logger.debug("Getting Raw Data")
          raw = dict()
          iterations = set()
          if self.display.lower() == "loss":
              loss_dict = self.session.total_loss if self.is_totals else self.session.loss
              for loss_name, loss in loss_dict.items():
                  if loss_name not in self.loss_keys:
 
</s> remove         if self.display.lower() == "loss":
            loss_dict = self.session.total_loss if self.is_totals else self.session.loss
 </s> add         if self._display.lower() == "loss":
            loss_dict = Session.get_loss(self._session_id) </s> remove                 if loss_name not in self.loss_keys:
 </s> add                 if loss_name not in self._loss_keys: </s> remove                 if self.args["flatten_outliers"]:
                    loss = self.flatten_outliers(loss)
                iterations.add(len(loss))
                raw["raw_{}".format(loss_name)] = loss
 </s> add                 iterations.add(loss.shape[0])

                if self._limit > 0:
                    loss = loss[-self._limit:]

                if self._args["flatten_outliers"]:
                    loss = self._flatten_outliers(loss)

                self.stats["raw_{}".format(loss_name)] = loss

            self._iterations = 0 if not iterations else min(iterations)
            if self._limit > 1:
                self._start_iteration = max(0, self._iterations - self._limit)
                self._iterations = min(self._iterations, self._limit)
            else:
                self._start_iteration = 0 </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 </s> remove             A list of loss values for each step for the requested session
 </s> add             The session id(s) as key, with a further dictionary as value containing the loss name
            and list of loss values for each step
        self.stats.clear()
          dict
              The loss name as key with list of loss values as value
          """
          logger.debug("Getting Raw Data")
        self.stats.clear()
          iterations = set()
          if self.display.lower() == "loss":
              loss_dict = self.session.total_loss if self.is_totals else self.session.loss
              for loss_name, loss in loss_dict.items():
                  if loss_name not in self.loss_keys:
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