Skip to content

Instantly share code, notes, and snippets.

@oborchers
Last active February 12, 2019 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oborchers/b19599862e6ad93a3631640cb92b828d to your computer and use it in GitHub Desktop.
Save oborchers/b19599862e6ad93a3631640cb92b828d to your computer and use it in GitHub Desktop.
Create the parameter vectors for the MDN
from tensorflow.keras.layers import Input, Dense, Concatenate
neurons = 500 # Neurons of the DNN hidden layers
components = 2 # Number of components in the mixture
no_parameters = 3 # Paramters of the mixture (alpha, mu, sigma)
inputs = Input(shape=(x_train.shape[1],))
h1 = Dense(neurons, activation="relu")(inputs)
h2 = Dense(neurons, activation="relu")(h1)
alphas = Dense(components, activation="softmax", name="alphas")(h2) # Create vector for alpha (softmax constrained)
mus = Dense(components, name="mus")(h2) # Create vector for mus
sigmas = Dense(components, activation="nnelu", name="sigmas")(h2) # Create vector sigmas (nnelu constrained)
pvector = Concatenate(name="output")([alphas, mus, sigmas]) # Concatenate (required for model compilation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment