Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow.keras as keras
- import tensorflow_probability as tfp
- # Number of components in the Gaussian Mixture
- num_components = 16
- # Shape of the distribution
- event_shape = [1]
- # Utility function to compute how many parameters this distribution requires
- params_size = tfp.layers.MixtureNormal.params_size(num_components, event_shape)
- model = keras.Sequential([
- keras.layers.Dense(units=128, activation='relu', input_shape=(1,)),
- keras.layers.Dense(units=128, activation='tanh'),
- keras.layers.Dense(params_size),
- tfp.layers.MixtureNormal(num_components, event_shape)])
- negative_log_likelihood = lambda y, q: -q.log_prob(y)
- model.compile(loss=negative_log_likelihood, optimizer='adam')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement