Files
Rbm/source/Layer.hpp
T
2022-01-19 11:01:37 +00:00

77 lines
1.7 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: Layer.hpp
* Author: jens
*
* Created on 25. Oktober 2019, 08:13
*/
#ifndef RBMLAYER_HPP
#define RBMLAYER_HPP
#include <string>
#include <armadillo>
#include <jsoncpp/json/json.h>
#include "Rbm.hpp"
class Layer : public Rbm
{
public:
Layer *next;
Layer *prev;
Layer(const std::string &name, size_t id, size_t numVisibleX, size_t numVisibleY, size_t numHidden, size_t numContext=0);
Layer(const Layer& orig);
virtual ~Layer();
Json::Value toJson() const;
size_t id();
bool isEnable();
void setEnable(bool enable);
std::string& name();
int numVisibleX();
int numVisibleY();
const arma::mat& context() const;
Layer *root();
arma::mat vc_to_v(const arma::mat &vc) const;
arma::mat vc_to_c(const arma::mat &vc) const;
bool weightsLoad(std::string const &dir, std::string const &prj);
bool weightsSave(std::string const &dir, std::string const &prj);
void calcContextBatch(arma::mat &batch);
void train(arma::mat const &batch, IListener *pListener=nullptr);
arma::mat to_h_gibbs(const arma::mat& v_probs);
arma::mat to_v_gibbs(const arma::mat& h_probs);
private:
std::string m_name;
size_t m_id;
bool m_isEnabled;
size_t m_numVisibleX;
size_t m_numVisibleY;
size_t m_numContext;
// Compatibility
std::string filePrefix(const std::string &dir, const std::string &prjname) const;
protected:
virtual void onUpPass(const arma::mat& v) {}
virtual void onDownPass(const arma::mat& h) {}
};
#endif /* RBMLAYER_HPP */