  
      def refresh(self):
          """ Refresh the stats """
          logger.debug("Refreshing")
          if not self.session.initialized:
              logger.warning("Session data is not initialized. Not refreshing")
              return None
          self.iterations = 0
          self.stats = self._get_raw()
          self.get_calculations()
 
</s> remove         self.iterations = 0
        self.stats = self._get_raw()
        self.get_calculations()
        self.remove_raw()
 </s> add         self._iterations = 0
        self._get_raw()
        self._get_calculations()
        self._remove_raw() </s> remove         self.session = session
        self.display = display
        self.loss_keys = loss_keys
        self.selections = selections
        self.is_totals = is_totals
        self.args = {"avg_samples": avg_samples,
                     "smooth_amount": smooth_amount,
                     "flatten_outliers": flatten_outliers}
        self.iterations = 0
        self.stats = None
 </s> add         self._session_id = session_id

        self._display = display
        self._loss_keys = loss_keys if isinstance(loss_keys, list) else [loss_keys]
        self._selections = selections if isinstance(selections, list) else [selections]
        self._is_totals = session_id is None
        self._args = dict(avg_samples=avg_samples,
                          smooth_amount=smooth_amount,
                          flatten_outliers=flatten_outliers)
        self._iterations = 0
        self._limit = 0
        self._start_iteration = 0
        self._stats = dict() </s> remove         if self._session is None:
 </s> add         if not Session.is_loaded: </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 not Session.is_loaded:
  
      def refresh(self):
          """ Refresh the stats """
          logger.debug("Refreshing")
        if not Session.is_loaded:
              logger.warning("Session data is not initialized. Not refreshing")
              return None
          self.iterations = 0
          self.stats = self._get_raw()
          self.get_calculations()
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