← All algorithms

Neural Network / Unsupervised Learning

Autoencoder

2023-12-27

Autoencoder can be used as a method for unsupervised learning and is very similar to PCA for dimensionality reduction. Various applications such as generative models (Variational Autoencoder, Generative Adversarial Network), denoising, and more have been developed. The basic structure of an autoencoder consists of an encoder, latent vector, and decoder. In particular, when the size of the latent vector is smaller than the input dimension, it is called an undercomplete autoencoder, which can be used for data compression, dimensionality reduction, and more. In this case, the structure and values of the output layer are set exactly the same as the input layer. All nodes are fully connected, and a linear function is used as the activation function.

​

​Just like in artificial neural networks structure, the output function Y uses the input X, the coefficients of the hidden layer (w), and the coefficients of the output layer (V) along with the biases bw and bv.

\(Y=V(Xw-b_w)-b_v\)

The cost function for the optimization w.r.t. the coefficients is

\(L=\sum _{\ }^{\ }(X-Y)^2\)

​


We are going to use the same Wine data with the PCA to implement Autoencoder. The Wine data is composed of the 13 source parameters and the sample size of 178.

The neural network structure use 13 nodes for the input layer and the output layer and 2 nodes for the hidden layer as we used two principal components for PCA.​

(Step 1) Standardize the data by using the mean and the standard deviation.

(Step 2) Allocate the Cells for the coefficients, W, V, bw, bv, and initialize them with random numbers. Note that the size of W = [no of nodes of the Input layer x no of nodes of the hidden layer], the size of V = [no of nodes of the output layer x no of nodes of the hidden layer], Be aware that the size of the thresholds, bw is the same as the number of nodes of the hidden layer, but bv is the number of nodes of the output layer.

​

(Step 3) The activation function for the output of the hidden layer is the linear function. ​

=SUMPRODUCT(X, W)-bw

(Step 4) The activation function for the output of the output layer is also the linear function.

= MMULT(H, V)-bv

(Step 5) The error, \(\epsilon\), is the sum square error between the input node and the output node, and the cost function, J, for the optimization is the total sum of the errors.

\(\epsilon = \text{SUMXMY2}(X,Y)\)

\(J = \text{SUM}(\epsilon)\)

​

(Step 6) Run the Solver with the following setting:

The plot below shows the two hidden node output, h1 and h2, so-called the latent vector.

h =SUMPRODUCT(X, W)-bw

The Autoencoder shows the very similar results with the PCA.

​