Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import tensorflow.keras as keras
  2. import tensorflow_probability as tfp
  3.  
  4. # Number of components in the Gaussian Mixture
  5. num_components = 16
  6. # Shape of the distribution
  7. event_shape = [1]
  8. # Utility function to compute how many parameters this distribution requires
  9. params_size = tfp.layers.MixtureNormal.params_size(num_components, event_shape)
  10.  
  11. model = keras.Sequential([
  12. keras.layers.Dense(units=128, activation='relu', input_shape=(1,)),
  13. keras.layers.Dense(units=128, activation='tanh'),
  14. keras.layers.Dense(params_size),
  15. tfp.layers.MixtureNormal(num_components, event_shape)])
  16.  
  17. negative_log_likelihood = lambda y, q: -q.log_prob(y)
  18.  
  19. model.compile(loss=negative_log_likelihood, optimizer='adam')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement