(embeddings, damping=1e-7, full_covariance=False)
Fits a unimodal Gaussian distribution to `embeddings`.

  Args:
    embeddings: A [batch_size, embedding_dim] tf.Tensor of embeddings.
    damping: The scale of the covariance damping coefficient.
    full_covariance: Whether to use a full or diagonal covariance.

  Returns:
    Parameter estimates (means and log variances) for a Gaussian model.
Fits a unimodal Gaussian distribution to `embeddings`.
Fits a unimodal Gaussian distribution to embeddings .
def fit_gaussian(embeddings, damping=1e-7, full_covariance=False):
  """Fits a unimodal Gaussian distribution to `embeddings`.

  Args:
    embeddings: A [batch_size, embedding_dim] tf.Tensor of embeddings.
    damping: The scale of the covariance damping coefficient.
    full_covariance: Whether to use a full or diagonal covariance.

  Returns:
    Parameter estimates (means and log variances) for a Gaussian model.
  """
  if full_covariance:
    num, dim = tf.split(tf.shape(input=embeddings), num_or_size_splits=2)
    num, dim = tf.squeeze(num), tf.squeeze(dim)
    sample_mean = tf.reduce_mean(input_tensor=embeddings, axis=0)
    centered_embeddings = embeddings - sample_mean
    sample_covariance = tf.einsum('ij,ik->kj', centered_embeddings,
                                  centered_embeddings)  # Outer product.
    sample_covariance += damping * tf.eye(dim)  # Positive definiteness.
    sample_covariance /= tf.cast(num, dtype=tf.float32)  # Scale by N.
    return sample_mean, sample_covariance
  else:
    sample_mean, sample_variances = tf.nn.moments(x=embeddings)
    log_variances = tf.math.log(sample_variances +
                                damping * tf.ones_like(sample_variances))
    return sample_mean, log_variances
def fit_gaussian ( embeddings , damping = 1e-7 , full_covariance = False ) : if full_covariance : num , dim = tf . split ( tf . shape ( input = embeddings ) , num_or_size_splits = 2 ) num , dim = tf . squeeze ( num ) , tf . squeeze ( dim ) sample_mean = tf . reduce_mean ( input_tensor = embeddings , axis = 0 ) centered_embeddings = embeddings - sample_mean sample_covariance = tf . einsum ( 'ij,ik->kj' , centered_embeddings , centered_embeddings ) # Outer product. sample_covariance += damping * tf . eye ( dim ) # Positive definiteness. sample_covariance /= tf . cast ( num , dtype = tf . float32 ) # Scale by N. return sample_mean , sample_covariance else : sample_mean , sample_variances = tf . nn . moments ( x = embeddings ) log_variances = tf . math . log ( sample_variances + damping * tf . ones_like ( sample_variances ) ) return sample_mean , log_variances