Documentation

encode

Class: Autoencoder

Encode input data

Description

example

Z = encode(autoenc,Xnew) returns the encoded data, Z, for the input data Xnew, using the autoencoder, autoenc.

Input Arguments

expand all

Trained autoencoder, returned as an object of the Autoencoder class.

Input data, specified as a matrix of samples, a cell array of image data, or an array of single image data.

If the autoencoder autoenc was trained on a matrix, where each column represents a single sample, then Xnew must be a matrix, where each column represents a single sample.

If the autoencoder autoenc was trained on a cell array of images, then Xnew must either be a cell array of image data or an array of single image data.

Data Types: single | double | cell

Output Arguments

expand all

Data encoded by autoenc, specified as a matrix. Each column of Z represents an encoded sample (observation).

Data Types: single | double

Examples

expand all

Load the sample data.

X = digitTrainCellArrayData;

X is a 1-by-5000 cell array, where each cell contains a 28-by-28 matrix representing a synthetic image of a handwritten digit.

Train an autoencoder with a hidden size of 50 using the training data.

autoenc = trainAutoencoder(X,50);

Encode decoded data for new image data.

Xnew = digitTestCellArrayData;
Z = encode(autoenc,Xnew);

Xnew is a 1-by-5000 cell array. Z is a 50-by-5000 matrix, where each column represents the image data of one handwritten digit in the new data Xnew.

Algorithms

If the input to an autoencoder is a vector $x\in {ℝ}^{{D}_{x}}$, then the encoder maps the vector x to another vector $z\in {ℝ}^{{D}^{\left(1\right)}}$ as follows:

$z={h}^{{}^{\left(1\right)}}\left({W}^{\left(1\right)}x+{b}^{\left(1\right)}\right),$

where the superscript (1) indicates the first layer. ${h}^{\left(1\right)}:{ℝ}^{{D}^{\left(1\right)}}\to {ℝ}^{{D}^{\left(1\right)}}$ is a transfer function for the encoder, ${W}^{\left(1\right)}\in {ℝ}^{{D}^{\left(1\right)}×{D}_{{}^{x}}}$ is a weight matrix, and ${b}^{\left(1\right)}\in {ℝ}^{{D}^{\left(1\right)}}$ is a bias vector.