def eye_color(person): random_variables = {x.name: x for x in tf.get_collection('_random_variable_collection_')} if person + '/' in random_variables: return random_variables[person + '/'] else: return Categorical( logits=ed.logit(tf.constant([1.0 / 3] * 3)), name=person)
def eye_color(person): random_variables = { x.name: x for x in tf.get_collection('_random_variable_collection_') } if person + '/' in random_variables: return random_variables[person + '/'] else: return Categorical(logits=ed.logit(tf.constant([1.0 / 3] * 3)), name=person)
return x N = 500 # num data points K = 2 # num components D = 2 # dimensionality of data ed.set_seed(42) # DATA x_data = build_toy_dataset(N) # MODEL pi = Dirichlet(alpha=tf.constant([1.0] * K)) mu = Normal(mu=tf.zeros([K, D]), sigma=tf.ones([K, D])) sigma = InverseGamma(alpha=tf.ones([K, D]), beta=tf.ones([K, D])) c = Categorical(logits=ed.tile(ed.logit(pi), [N, 1])) x = Normal(mu=tf.gather(mu, c), sigma=tf.gather(sigma, c)) # INFERENCE T = 5000 qpi = Empirical(params=tf.Variable(tf.ones([T, K]) / K)) qmu = Empirical(params=tf.Variable(tf.zeros([T, K, D]))) qsigma = Empirical(params=tf.Variable(tf.ones([T, K, D]))) qc = Empirical(params=tf.Variable(tf.zeros([T, N], dtype=tf.int32))) gpi = Dirichlet(alpha=tf.constant([1.4, 1.6])) gmu = Normal(mu=tf.constant([[1.0, 1.0], [-1.0, -1.0]]), sigma=tf.constant([[0.5, 0.5], [0.5, 0.5]])) gsigma = InverseGamma(alpha=tf.constant([[1.1, 1.1], [1.1, 1.1]]), beta=tf.constant([[1.0, 1.0], [1.0, 1.0]])) gc = Categorical(logits=tf.zeros([N, K]))
return x N = 500 # number of data points K = 2 # number of components D = 2 # dimensionality of data ed.set_seed(42) # DATA x_data = build_toy_dataset(N) # MODEL pi = Dirichlet(alpha=tf.constant([1.0] * K)) mu = Normal(mu=tf.zeros([K, D]), sigma=tf.ones([K, D])) sigma = InverseGamma(alpha=tf.ones([K, D]), beta=tf.ones([K, D])) c = Categorical(logits=tf.tile(tf.reshape(ed.logit(pi), [1, K]), [N, 1])) x = Normal(mu=tf.gather(mu, c), sigma=tf.gather(sigma, c)) # INFERENCE T = 5000 qpi = Empirical(params=tf.Variable(tf.ones([T, K]) / K)) qmu = Empirical(params=tf.Variable(tf.zeros([T, K, D]))) qsigma = Empirical(params=tf.Variable(tf.ones([T, K, D]))) qc = Empirical(params=tf.Variable(tf.zeros([T, N], dtype=tf.int32))) gpi = Dirichlet(alpha=tf.constant([1.4, 1.6])) gmu = Normal(mu=tf.constant([[1.0, 1.0], [-1.0, -1.0]]), sigma=tf.constant([[0.5, 0.5], [0.5, 0.5]])) gsigma = InverseGamma(alpha=tf.constant([[1.1, 1.1], [1.1, 1.1]]), beta=tf.constant([[1.0, 1.0], [1.0, 1.0]])) gc = Categorical(logits=tf.zeros([N, K]))