16.03.2021 Views

Advanced Deep Learning with Keras

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Policy Gradient Methods

self.encoder = Model(inputs, feature, name='encoder')

self.encoder.summary()

plot_model(self.encoder, to_file='encoder.png',

show_shapes=True)

# build the decoder model

feature_inputs = Input(shape=(feature_size,),

name='decoder_input')

x = Dense(128, activation='relu')(feature_inputs)

x = Dense(256, activation='relu')(x)

outputs = Dense(self.state_dim, activation='linear')(x)

# instantiate decoder model

self.decoder = Model(feature_inputs, outputs, name='decoder')

self.decoder.summary()

plot_model(self.decoder, to_file='decoder.png',

show_shapes=True)

# autoencoder = encoder + decoder

# instantiate autoencoder model

self.autoencoder = Model(inputs,

self.decoder(self.encoder(inputs)), name='autoencoder')

self.autoencoder.summary()

plot_model(self.autoencoder, to_file='autoencoder.png',

show_shapes=True)

# Mean Square Error (MSE) loss function, Adam optimizer

self.autoencoder.compile(loss='mse', optimizer='adam')

# training the autoencoder using randomly sampled

# states from the environment

def train_autoencoder(self, x_train, x_test):

# train the autoencoder

batch_size = 32

self.autoencoder.fit(x_train,

x_train,

validation_data=(x_test, x_test),

epochs=10,

batch_size=batch_size)

[ 322 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!