git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@569 b431acfa-c32f-4a4a-93f1-934dc6c82436
100 lines
1.9 KiB
C++
100 lines
1.9 KiB
C++
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
/*
|
|
* File: Rbm.hpp
|
|
* Author: jens
|
|
*
|
|
* Created on 21. Oktober 2019, 21:28
|
|
*/
|
|
|
|
#ifndef RBM_HPP
|
|
#define RBM_HPP
|
|
|
|
#include <armadillo>
|
|
#include "noise.h"
|
|
|
|
class Rbm
|
|
{
|
|
public:
|
|
|
|
struct Params
|
|
{
|
|
Params()
|
|
: m_weightInit(0.01)
|
|
, m_weightDecay(0.001)
|
|
, m_learningRate(0.1)
|
|
, m_momentum(0.5)
|
|
, m_doRaoBlackwell(true)
|
|
, m_gibbsDoSampleVisible(false)
|
|
, m_gibbsDoSampleHidden(true)
|
|
, m_doSampleBatch(false)
|
|
, m_numGibbs(1)
|
|
{
|
|
}
|
|
|
|
double m_weightInit;
|
|
double m_weightDecay;
|
|
double m_learningRate;
|
|
double m_momentum;
|
|
bool m_doRaoBlackwell;
|
|
bool m_gibbsDoSampleVisible;
|
|
bool m_gibbsDoSampleHidden;
|
|
bool m_doSampleBatch;
|
|
size_t m_numGibbs;
|
|
};
|
|
|
|
struct Status
|
|
{
|
|
size_t epoch;
|
|
size_t trainingSizeRemain;
|
|
double progress;
|
|
double err;
|
|
double err_total;
|
|
double L1;
|
|
double L2;
|
|
};
|
|
|
|
class IListener
|
|
{
|
|
public:
|
|
|
|
IListener() {}
|
|
virtual ~IListener() {}
|
|
virtual bool onProgress(const Status &status)
|
|
{
|
|
return true;
|
|
}
|
|
};
|
|
|
|
Rbm(const Params& params, arma::mat &w, arma::mat &bv, arma::mat &bh);
|
|
Rbm(const Rbm& orig);
|
|
virtual ~Rbm();
|
|
|
|
void train(arma::mat const &batch, size_t numEpochs, size_t sizeMiniBatch, IListener *pListener);
|
|
|
|
arma::mat toHiddenState(const arma::mat &visible);
|
|
arma::mat toVisibleState(const arma::mat &hidden);
|
|
arma::mat toHiddenProbs(const arma::mat &visible);
|
|
arma::mat toVisibleProbs(const arma::mat &hidden);
|
|
arma::mat& weights();
|
|
arma::mat& bias_visible();
|
|
arma::mat& bias_hidden();
|
|
|
|
private:
|
|
noise_gen_t m_noise;
|
|
const Params &m_params;
|
|
arma::mat &m_w;
|
|
arma::mat &m_bh;
|
|
arma::mat &m_bv;
|
|
arma::mat sample(arma::mat const &src);
|
|
static arma::mat probsLogistic(arma::mat const &src);
|
|
void uniform(arma::mat &srcDst, double mu=0.0, double stdDev=1.0);
|
|
};
|
|
|
|
#endif /* RBM_HPP */
|
|
|