add a train function to autoencoder