ravens/models/mdn_utils.py
def sample_from_pdf(pi, mu, var, num_samples=1):
  """Prediction as a sample from the gaussian mixture.

  Args are all TF:
    pi: (batch_size, num_gaussians)
    mu: (batch_size, num_gaussians * d_out)
    var: (batch_size, num_gaussians)
  Returns:
    (batch_size, num_samples, d_out) NUMPY
  """
  pi, mu, var = pi.numpy(), mu.numpy(), var.numpy()
  # apply temperature?
  #pi = pi**4 # apply temp
  var = var**4

  pi = pi * (1/pi.sum(1)[..., None])
  batch_size, k = pi.shape

  mu = tf.reshape(mu, (tf.shape(mu)[0], tf.shape(pi)[1], -1))
  d_out = tf.shape(mu)[-1]

  samples = np.zeros((batch_size, num_samples, d_out))
  for i in range(batch_size):
    for j in range(num_samples):
      idx = np.random.choice(range(k), p=pi[i])
      draw = np.random.normal(mu[i, idx], np.sqrt(var[i, idx]))
      samples[i,j] = draw
  return samples
Prediction as a sample from the gaussian mixture.

  Args are all TF:
    pi: (batch_size, num_gaussians)
    mu: (batch_size, num_gaussians * d_out)
    var: (batch_size, num_gaussians)
  Returns:
    (batch_size, num_samples, d_out) NUMPY
  
Prediction as a sample from the gaussian mixture.
Prediction as a sample from the gaussian mixture .
def sample_from_pdf(pi, mu, var, num_samples=1):
  pi, mu, var = pi.numpy(), mu.numpy(), var.numpy()
  var = var**4
  pi = pi * (1/pi.sum(1)[..., None])
  batch_size, k = pi.shape
  mu = tf.reshape(mu, (tf.shape(mu)[0], tf.shape(pi)[1], -1))
  d_out = tf.shape(mu)[-1]
  samples = np.zeros((batch_size, num_samples, d_out))
  for i in range(batch_size):
    for j in range(num_samples):
      idx = np.random.choice(range(k), p=pi[i])
      draw = np.random.normal(mu[i, idx], np.sqrt(var[i, idx]))
      samples[i,j] = draw
  return samples
def sample_from_pdf ( pi , mu , var , num_samples = 1 ) : pi , mu , var = pi . numpy ( ) , mu . numpy ( ) , var . numpy ( ) var = var ** 4 pi = pi * ( 1 / pi . sum ( 1 ) [ ... , None ] ) batch_size , k = pi . shape mu = tf . reshape ( mu , ( tf . shape ( mu ) [ 0 ] , tf . shape ( pi ) [ 1 ] , - 1 ) ) d_out = tf . shape ( mu ) [ - 1 ] samples = np . zeros ( ( batch_size , num_samples , d_out ) ) for i in range ( batch_size ) : for j in range ( num_samples ) : idx = np . random . choice ( range ( k ) , p = pi [ i ] ) draw = np . random . normal ( mu [ i , idx ] , np . sqrt ( var [ i , idx ] ) ) samples [ i , j ] = draw return samples
Prediction as a sample from the gaussian mixture.
Prediction as a sample from the gaussian mixture .
"""Prediction as a sample from the gaussian mixture.

  Args are all TF:
    pi: (batch_size, num_gaussians)
    mu: (batch_size, num_gaussians * d_out)
    var: (batch_size, num_gaussians)
  Returns:
    (batch_size, num_samples, d_out) NUMPY
  """ # apply temperature? #pi = pi**4 # apply temp
(batch_size, num_samples, d_out) NUMPY
( batch_size num_samples d_out ) NUMPY
pi
mu
var
num_samples