Rabindra Nath Nandi
Rabindra Nath Nandi

Reputation: 1461

Reconstruct Original Data using Denoising AutoEncoder

Sometimes , the raw data doesn't contains sufficient information like biological experimental data.I have a gene expression dataset with size 100*1000. I want to use Denoising AutoEncoder to get an reconstructed output with the same size(100*1000). How it would be possible?

Upvotes: 3

Views: 691

Answers (2)

T.A. Anderson
T.A. Anderson

Reputation: 47

Just if anyone ever stumbles over this post and wonders how to code a denoising autoencoder. Here is a simple example:

import numpy as np
import tensorflow as tf

# Generate a 100x1000 dataset
x_train = np.random.rand(100, 1000)

# Add noise to the data
noise_factor = 0.5
x_train_noisy = x_train + noise_factor * np.random.normal(loc=0.0, scale=1.0, size=x_train.shape)

# Clip the values to [0, 1]
x_train_noisy = np.clip(x_train_noisy, 0., 1.)

# Define the input layer
inputs = tf.keras.layers.Input(shape=(1000,))

# Define the encoder
encoded = tf.keras.layers.Dense(100, activation='relu')(inputs)

# Define the decoder
decoded = tf.keras.layers.Dense(1000, activation='sigmoid')(encoded)

# Define the autoencoder model
autoencoder = tf.keras.models.Model(inputs, decoded)

# Compile the model
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')

# Train the model
autoencoder.fit(x_train_noisy, x_train, epochs=100, batch_size=32)

Note:

  • You have to replace x_train with your data
  • x_train has to be noise free (otherwise the denoising autoencoder won't work, since it has no reference)
  • you can add additional layers for your encoder and decoder part
  • you should play around with hyperparameters (number of neurons in the individual layers, loss function, (optimizer,) epochs, batch_size) to see what works best for you -> preferably, you run an optimisier to find the best values for them (like grid search and the like)

And here are a couple of links to other sources on autoencoders:

Machine Learning Mastery

Keras Blog

Upvotes: 0

Marcin Możejko
Marcin Możejko

Reputation: 40516

Here you can find an interesting article about autoencoders. The denosing case is also mentioned - I hope that it will answer your question :

https://medium.com/a-year-of-artificial-intelligence/lenny-2-autoencoders-and-word-embeddings-oh-my-576403b0113a#.2jdcn3ctk

Upvotes: 1

Related Questions