Files
Rbm/source/main.cpp
T
2019-10-22 06:30:21 +00:00

68 lines
1.9 KiB
C++

#include <streambuf>
#include <cstdio>
#include <cmath>
#include <armadillo>
#include "Rbm.hpp"
class RbmListener : public Rbm::IListener
{
public:
RbmListener() {}
virtual ~RbmListener() {}
bool onProgress(const Rbm::Status &status)
{
std::cout << "Progress : " << 100*status.progress << " %" << std::endl;
std::cout << "epoch : " << status.epoch << std::endl;
std::cout << "trainingSizeRemain: " << status.trainingSizeRemain << std::endl;
std::cout << "error (per mini batch) = " << status.err << std::endl;
std::cout << "L1 = " << status.L1 << std::endl;
std::cout << "L2 = " << status.L2 << std::endl;
return true;
}
};
int main()
{
printf("Hallo, Welt!\n");
// Position of a particle // |
arma::vec Pos = {{0}, // | (0,1)
{1}}; // +---x-->
// Rotation matrix
double phi = -3.1416/2;
arma::mat RotM = {{+cos(phi), -sin(phi)},
{+sin(phi), +cos(phi)}};
Pos.print("Current position of the particle:");
std::cout << "Rotating the point " << phi*180/3.1416 << " deg" << std::endl;
Pos = RotM*Pos;
Pos.print("New position of the particle:"); // ^
// x (1,0)
// |
arma::mat Z = arma::eye<arma::mat>(4000,4000);
// Z.print("Z:");
printf("Z.n_rows = %d\n", (int)Z.n_rows);
printf("Z.n_cols = %d\n", (int)Z.n_cols);
printf("Z.n_elem = %d\n", (int)Z.n_elem);
// +------>
RbmListener statusDisplay;
Rbm::Params params;
arma::mat w = arma::zeros(28*28, 64);
arma::mat bv = arma::zeros(1, 28*28);
arma::mat bh = arma::zeros(1, 64);
Rbm rbm(w, bv, bh);
arma::mat batch = arma::randu(100, 28*28);
rbm.train(batch, 10, 10, params, &statusDisplay);
arma::mat v = arma::randu(100, 28*28);
arma::mat h = rbm.toHidden(v);
arma::mat r = rbm.toVisible(h);
return 0;
}