The IDLmlAutoEncoder class implements an autoencoder model that can be used for clustering purposes.

Example


; Read image dataset
File = filepath('rose.jpg', subdirectory=['examples', 'data'])
imgData = read_image(file)
 
; Reform our image into a 3 by n-pixels array
Data = reform(imgData, 3, (imgData.dim)[1]*(imgData.dim)[2])
 
; Normalize data
Normalizer = IDLmlVarianceNormalizer(data)
Normalizer.Normalize, data
 
; Define autoencoder. It contains 3 attributes (pixel RGB values) and we
; want to separate it into 5 different classes, so the inner layer is 5.
Classifier = IDLmlAutoEncoder([3, 5, 3], $
  ACTIVATION_FUNCTIONS=[IDLmlafLogistic(), IDLmlafArcTan()])
 
; Train the classifier
Optimizer = IDLmloptGradientDescent(0.001)
For i=0, 200 do loss=Classifier.Train(data, OPTIMIZER=optimizer)
 
; Classify our image
Result = Classifier.Classify(data)
 
; Display result
!null = Image(imgData, title='Original Image', layout=[2,1,1])
!null = Image(reform(result, (imgData.dim)[1], (imgData.dim)[2]), $
  rgb_table=25, title='Clustered Image', layout=[2,1,2], /current)

Syntax


Result = IDLmlAutoEncoder(LayerSizes [, Keywords=Value])

Arguments


LayerSizes

Specify a 1D array of layer sizes that define the autoencoder. The first element of the array must be equal to the number of attributes. The last element must also be equal to the number of attributes.

Keywords


ACTIVATION_FUNCTIONS (optional)

Set this keyword to the activation function objects (IDLmlac*) for each layer. If specified, the number of elements of this 1D array must be equal to the number of layers defined by the LayerSizes array, minus one. The default value is to always use IDLmlafLogistic activation functions.

LAMBDA (optional)

Specify the contribution of L2 regularization in the loss function. By default, this is 0. Increasing this argument may help with model overfitting issues.

LOSS_FUNCTION (optional)

Specify the loss function object (IDLmllf*) for the model. This function determines what is the function that must be minimized during training. The default value is to always use IDLmllfMeanSquaredError.

OUTPUT_LAYER (optional)

Set this keyword to the index of the layer to use as output of the neural network. By default, the last layer will be used as output.

SEED (optional)

If repeatability is desired (such as for testing), set this keyword to the seed variable used to randomly initialize the weights.

Properties


ACTIVATION_FUNCTIONS

An array of activation functions that define the neural network.

CLASS_MAP

A hash that maps internal classification values to desired labels, if the model was defined using custom labels.

LAYER_SIZES

An array of layer sizes that define the neural network.

NATTRIBUTES

The number of input attributes the model requires.

NLAYERS

The number of layers of the neural network.

NOUTPUTS

The number of possible outputs.

OUTPUT_LAYER

The index of the layer used as output layer.

OUTPUTS

An array of possible outputs.

WEIGHTS

The current weight values that make up the neural network. Weights represent the strength of connection between the network units. Initially, they are a set of random numbers, but as the model is trained the weights will change reflecting a model that is better trained.

Methods


IDLmlAutoEncoder::Classify


The IDLmlAutoEncoder::Classify method assigns each example to an output class, returning an array of label results.

Syntax


Result = Obj->[IDLmlAutoEncoder::]Classify(Features [, Keywords=Value])

Return Value


The method returns an array of class values that correspond to the data provided.

Arguments


Features

Specify an array of features of size n x m, where n is the number of attributes and m is the number of examples.

Keywords


LOSS (optional)

Set this keyword to a variable that will contain the loss result, which is a unitless number that indicates how closely the model fits the training data. Loss is defined as the total error computed by the loss function specified in the LOSS_FUNCTION parameter when creating the model, which defaults to Mean Squared Error if not specified.

IDLmlAutoEncoder::Restore


The IDLmlAutoEncoder::Restore static method restores the model from a file.

Syntax


Result = IDLmlAutoEncoder.Restore(Filename)

Return Value


A reference to the object instance restored from the file.

Arguments


Filename

Specify the name of file to restore.

Keywords


None

IDLmlAutoEncoder::Save


The IDLmlAutoEncoder::Save method saves the model to a file.

Syntax


Obj->[IDLmlAutoEncoder::]Save, Filename

Arguments


Filename

Specify the name of the file to save.

Keywords


None

IDLmlAutoEncoder::Train


The IDLmlAutoEncoder::Train method performs training on the model and the loss, which is a unitless number that indicates how closely the model fits the training data. Training is an iterative process and it can take tens or hundreds of calls to the Train method until the model becomes fully trained. Check the loss returned by this method on each iteration. Once it converges to a low and stable value, you will know that the model has been trained.

Syntax


Result = Obj->[IDLmlAutoEncoder::]Train(Features [, Keywords=Value])

Return Value


This method returns the loss, which is a unitless number that indicates how closely the model fits the training data. Loss is defined as the total error computed by the loss function specified in the LOSS_FUNCTION parameter when creating the model, which defaults to Mean Squared Error if not specified.

Arguments


Features

Specify an array of features of size n x m, where n is the number of attributes and m is the number of examples.

Keywords


CALLBACK_FUNCTION (optional)

An optional string with the name of an IDL function to be called on each training iteration. The callback function must accept two arguments: loss and state. The callback function must return 1 (!true) if the training should perform another iteration, or 0 (!false) if it should stop training.

OPTIMIZER (optional)

Specify the optimizer object (IDLmlopt*) used in training. The optimizer will adjust the learning process to try to converge to a solution.

TRAIN_STATE (optional)

Specify optional user data to provide for the callback function.

Version History


8.7.1

Introduced

See Also


IDLmlFeedForwardNeuralNetwork, IDLmlKMeans, IDLmlSoftmax, IDLmlSupportVectorMachineClassification, IDLmlSupportVectorMachineRegression