Reputation: 398
I am trying to create an autoencoder network in Keras to learn the dynamics of a system I'm analyzing but am not sure how to do it. As you can see below, x
is encoded by phi
into a lower dimensional z
-space. The A
network computes the derivative of z
and then psi
decodes the derivative back up into the full dimensional space. In addition to having psi
decode z_dot
to x_dot
, I would like to add the constraint that psi
also decodes z
back into x
. You can see in the diagram below that this can be done by repeating the decoder structure.
I know you can create Keras networks with multiple input/output tensors, but I am not sure if it's possible to repeat my decoder structure like I have shown? In this sense the decoder will learn from two data sets simultaneously. Is this possible? If so, how could I implement this?
Thanks!
Upvotes: 0
Views: 55
Reputation: 375
For this, you'd want to create an architecture called psi. Then instantiate it once, and reuse that as a layer in your network. The idea is to share the weights (use the exact same layer twice). So you might have:
def create_psi():
# define your psi architecture here
return psi
def decoder():
psi = create_psi()
X_input = Input(dims) #dims are the dimensions of z
Z_dot = A(X_input) #Using whatever layer A is
X_dot = psi(Z_dot)
X = psi(X_input)
decoder = Model(inputs=X_input, outputs=[X_dot, X])
return decoder
# Instantiate decoder model here, compile with appropriate loss, etc.
Upvotes: 1