openGPMP
Open Source Mathematics Package
encoders.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <openGPMP/ml.hpp>
3 #include <vector>
4 int main() {
5  srand(time(0));
6 
7  // Vanilla AutoEncoder
8  gpmp::ml::AutoEncoder ae(3, 2, 3, 0.1);
9 
10  std::cout << "Vanilla AutoEncoder Training:\n";
11  std::vector<std::vector<double>> ae_training_data = {{1, 0, 0},
12  {0, 1, 0},
13  {0, 0, 1}};
14  ae.train(ae_training_data, 1000);
15  ae.display();
16 
17  std::cout << "\nTesting Vanilla AutoEncoder:\n";
18  std::vector<double> test_input = {1, 1, 0};
19  std::vector<double> output = ae.forward(test_input);
20  std::cout << "Autoencoder Output:\n";
21  for (double val : output) {
22  std::cout << val << " ";
23  }
24 
25  // Sparse AutoEncoder
26  gpmp::ml::SparseAutoEncoder sparse_ae(3, 2, 3, 0.1, 0.01, 0.2);
27 
28  std::cout << "\n\nSparse AutoEncoder Training:\n";
29  std::vector<std::vector<double>> ae_training_data_sparse = {{1, 0, 0},
30  {0, 1, 0},
31  {0, 0, 1}};
32  sparse_ae.train(ae_training_data_sparse, 1000);
33  sparse_ae.display();
34 
35  // Denoising AutoEncoder
36  gpmp::ml::DenoisingAutoEncoder denoise_ae(3, 2, 3, 0.1, 0.2);
37 
38  std::cout << "\nDenoising AutoEncoder Training:\n";
39  denoise_ae.train(ae_training_data, 1000);
40  denoise_ae.display();
41 
42  // Contractive AutoEncoder
43  gpmp::ml::ContractiveAutoEncoder contractive_ae(3, 2, 3, 0.1, 0.01);
44 
45  std::cout << "\nContractive AutoEncoder Training:\n";
46  contractive_ae.train(ae_training_data, 1000);
47  contractive_ae.display();
48 
49  // Recurrent AutoEncoder
50  gpmp::ml::RecurrentAutoEncoder recurrent_ae(3, 2, 3, 0.1);
51 
52  std::cout << "\nRecurrent AutoEncoder Training:\n";
53  std::vector<std::vector<double>> recurrent_ae_training_data = {{1, 0, 0},
54  {0, 1, 0},
55  {0, 0, 1}};
56  recurrent_ae.train(recurrent_ae_training_data, 1000);
57  recurrent_ae.display();
58 
59  return 0;
60 }
A simple implementation of a vanilla autoencoder.
Definition: encoder.hpp:59
virtual void train(const std::vector< std::vector< double >> &training_data, int epochs)
Train the autoencoder on a dataset.
Definition: encoder.cpp:152
std::vector< double > forward(const std::vector< double > &input)
Forward pass through the autoencoder.
Definition: encoder.cpp:126
void display()
Print the weights of the autoencoder.
Definition: encoder.cpp:203
ContractiveAutoEncoder class, a derived class from AutoEncoder.
Definition: encoder.hpp:276
virtual void train(const std::vector< std::vector< double >> &training_data, int epochs) override
Trains the contractive autoencoder on the given training data.
Definition: encoder.cpp:344
DenoisingAutoEncoder class, a derived class from AutoEncoder.
Definition: encoder.hpp:237
void train(const std::vector< std::vector< double >> &training_data, int epochs) override
Adds noise to the input data and trains the denoising autoencoder.
Definition: encoder.cpp:292
RecurrentAutoEncoder class, a derived class from AutoEncoder.
Definition: encoder.hpp:475
virtual void train(const std::vector< std::vector< double >> &training_data, int epochs) override
Trains the recurrent autoencoder on the given sequential data.
Definition: encoder.cpp:587
SparseAutoEncoder class, a derived class from AutoEncoder.
Definition: encoder.hpp:193
void train(const std::vector< std::vector< double >> &training_data, int epochs) override
Trains the sparse autoencoder on the given training data.
Definition: encoder.cpp:231
int main()
Definition: encoders.cpp:4
User API for OpenGPMP MACHINE/DEEP LEARNING MODULE.