openGPMP
Open Source Mathematics Package
|
A simple implementation of a vanilla autoencoder. More...
#include <encoder.hpp>
Public Member Functions | |
AutoEncoder (int input_size, int hidden_size, int output_size, double learning_rate) | |
Constructor for the AutoEncoder class. More... | |
std::vector< double > | sigmoid (const std::vector< double > &x) |
Sigmoid activation function. More... | |
std::vector< double > | forward (const std::vector< double > &input) |
Forward pass through the autoencoder. More... | |
virtual void | train (const std::vector< std::vector< double >> &training_data, int epochs) |
Train the autoencoder on a dataset. More... | |
void | lrate_set (double initial_rate) |
Set the initial learning rate. More... | |
virtual void | lrate_update (int epoch) |
Update the learning rate based on a schedule. More... | |
void | display () |
Print the weights of the autoencoder. More... | |
virtual void | save (const std::string &filename) const |
Save the model weights to a file. More... | |
virtual void | load (const std::string &filename) |
Load model weights from a file. More... | |
Public Attributes | |
int | input_size |
Size of the input layer. More... | |
int | hidden_size |
Size of the hidden layer. More... | |
int | output_size |
Size of the output layer. More... | |
double | learning_rate |
Learning rate for training the autoencoder. More... | |
std::vector< std::vector< double > > | weights_input_hidden |
Weights from the input layer to the hidden layer. More... | |
std::vector< std::vector< double > > | weights_hidden_output |
Weights from the hidden layer to the output layer. More... | |
A simple implementation of a vanilla autoencoder.
This class represents a basic autoencoder with one hidden layer. It can be used for dimensionality reduction and feature learning
Definition at line 59 of file encoder.hpp.
gpmp::ml::AutoEncoder::AutoEncoder | ( | int | input_size, |
int | hidden_size, | ||
int | output_size, | ||
double | learning_rate | ||
) |
Constructor for the AutoEncoder class.
input_size | Size of the input layer |
hidden_size | Size of the hidden layer |
output_size | Size of the output layer |
learning_rate | Learning rate for training the autoencoder |
Definition at line 92 of file encoder.cpp.
References hidden_size, input_size, output_size, weights_hidden_output, and weights_input_hidden.
void gpmp::ml::AutoEncoder::display | ( | ) |
Print the weights of the autoencoder.
Prints the weights from the input layer to the hidden layer and from the hidden layer to the output layer
Definition at line 203 of file encoder.cpp.
Referenced by main().
std::vector< double > gpmp::ml::AutoEncoder::forward | ( | const std::vector< double > & | input | ) |
Forward pass through the autoencoder.
Computes the output of the autoencoder given an input vector
input | Input vector |
Definition at line 126 of file encoder.cpp.
Referenced by main().
|
virtual |
Load model weights from a file.
filename | The name of the file to load the weights from |
Definition at line 59 of file encoder.cpp.
void gpmp::ml::AutoEncoder::lrate_set | ( | double | initial_rate | ) |
Set the initial learning rate.
initial_rate | The initial learning rate |
Definition at line 77 of file encoder.cpp.
|
virtual |
Update the learning rate based on a schedule.
epoch | The current training epoch |
Definition at line 81 of file encoder.cpp.
|
virtual |
Save the model weights to a file.
filename | The name of the file to save the weights to |
Definition at line 41 of file encoder.cpp.
References weights_hidden_output, and weights_input_hidden.
std::vector< double > gpmp::ml::AutoEncoder::sigmoid | ( | const std::vector< double > & | x | ) |
Sigmoid activation function.
Applies the sigmoid activation function element-wise to the input vector
x | Input vector |
Definition at line 117 of file encoder.cpp.
|
virtual |
Train the autoencoder on a dataset.
Uses gradient descent to train the autoencoder on the provided training data
training_data | Matrix containing training data |
epochs | Number of training epochs |
Reimplemented in gpmp::ml::FullAutoEncoder, gpmp::ml::RecurrentAutoEncoder, gpmp::ml::VariationalAutoEncoder, gpmp::ml::ConcreteAutoEncoder, gpmp::ml::MDLAutoEncoder, gpmp::ml::ContractiveAutoEncoder, gpmp::ml::DenoisingAutoEncoder, and gpmp::ml::SparseAutoEncoder.
Definition at line 152 of file encoder.cpp.
Referenced by main().
int gpmp::ml::AutoEncoder::hidden_size |
Size of the hidden layer.
The number of nodes in the hidden layer, which forms the compressed representation
Definition at line 74 of file encoder.hpp.
Referenced by AutoEncoder().
int gpmp::ml::AutoEncoder::input_size |
Size of the input layer.
The number of input nodes in the autoencoder
Definition at line 66 of file encoder.hpp.
Referenced by AutoEncoder().
double gpmp::ml::AutoEncoder::learning_rate |
Learning rate for training the autoencoder.
The rate at which the weights are updated during the training process
Definition at line 89 of file encoder.hpp.
int gpmp::ml::AutoEncoder::output_size |
Size of the output layer.
The number of output nodes in the autoencoder, which should match the input size
Definition at line 82 of file encoder.hpp.
Referenced by AutoEncoder().
std::vector<std::vector<double> > gpmp::ml::AutoEncoder::weights_hidden_output |
Weights from the hidden layer to the output layer.
A matrix representing the weights connecting the hidden layer to the output layer
Definition at line 105 of file encoder.hpp.
Referenced by AutoEncoder(), and save().
std::vector<std::vector<double> > gpmp::ml::AutoEncoder::weights_input_hidden |
Weights from the input layer to the hidden layer.
A matrix representing the weights connecting the input layer to the hidden layer
Definition at line 97 of file encoder.hpp.
Referenced by AutoEncoder(), and save().