def train_autoencoder(data): """ Train an autoencoder Args: data: A fucntion that provides the input data for the network. Returns: LCMC and MSE metric for the autoencoder that has been trained. """ # Setup layers = calculate_layer_sizes(784, 200, 0.5) # Generations is needed to correct the number of training steps to match # the number of steps used in the evolutionary algorithm generations = 10 config = NeuralNetworkConfig() # Start with a mutated config to have some variation between runs config.mutate() config.num_steps *= generations autoencoder = Autoencoder(config, layers[:2]) # Training autoencoder.train(data) for index, layer_size in enumerate(layers[2:]): autoencoder.append_layer(layer_size) autoencoder.train(data, restore_layers=index+1) # Evaluation autoencoder.save_history() print(autoencoder.config) print(autoencoder.save_path) # autoencoder.reconstruct_images(data) return lcmc_fitness(autoencoder, data, True), mse_fitness(autoencoder, data, True)