code: def explained_variance_1d(ypred, y, valids=None):
      """Explained variation for 1D inputs.
  
      It is the proportion of the variance in one variable that is explained or
      predicted from another variable.
  
      Args:
          ypred (np.ndarray): Sample data from the first variable.
              Shape: :math:`(N, max_episode_length)`.
          y (np.ndarray): Sample data from the second variable.
              Shape: :math:`(N, max_episode_length)`.
          valids (np.ndarray): Optional argument. Array indicating valid indices.
              If None, it assumes the entire input array are valid.
              Shape: :math:`(N, max_episode_length)`.
  
      Returns:
          float: The explained variance.
  
      """
      if valids is not None:
          ypred = ypred[valids.astype(np.bool)]
          y = y[valids.astype(np.bool)]
  
      assert y.ndim == 1 and ypred.ndim == 1
  
      vary = np.var(y)
      if np.isclose(vary, 0):
          if np.var(ypred) > 0:
              return 0
  
          return 1
  
      return 1 - np.var(y - ypred) / (vary + 1e-8)
  
file_path: garage/src/garage/np/_functions.py
imports: import warnings
  import numpy
  import scipy.signal
label_desc: Use image node_id 1 for calling a global function with example usage: explained_variance_1d(ypred, y, valids) and returns: unknown, int, int