          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:
                      continue
                  if self.args["flatten_outliers"]:
                      loss = self.flatten_outliers(loss)
                  iterations.add(len(loss))
                  raw["raw_{}".format(loss_name)] = loss
 
</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         raw = dict()
 </s> add         self.stats.clear() </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             self.iterations = 0 if not iterations else min(iterations)
 </s> add  </s> remove                 if self.iterations == 0:
                    raw = {lossname: list() for lossname in raw}
 </s> add                 if self._iterations == 0:
                    self.stats = {lossname: np.array(list(), dtype=loss.dtype)
                                  for lossname, loss in self.stats.items()}
                if loss_name not in self._loss_keys:
          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:
                      continue
                  if self.args["flatten_outliers"]:
                      loss = self.flatten_outliers(loss)
                  iterations.add(len(loss))
                  raw["raw_{}".format(loss_name)] = loss
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