Files
Rbm/source/RnnStack.hpp
T
2022-01-19 16:05:23 +00:00

80 lines
1.5 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: RnnStack.hpp
* Author: jens
*
* Created on 17. Januar 2022, 12:43
*/
#ifndef RNNSTACK_HPP
#define RNNSTACK_HPP
#include "AStack.hpp"
class RnnStack : public AStack
{
const size_t NUM_CODES = 37;
public:
RnnStack(const std::string &name);
RnnStack(const RnnStack& orig) = delete;
virtual ~RnnStack();
void train(const arma::mat& batch, Rbm::IListener* pListener) override;
size_t getSeqLen();
arma::mat v_to_vc(const arma::mat &v, const arma::mat &c) const;
arma::mat vc_to_v(const arma::mat &vc, size_t numContext) const;
arma::mat step_forward(arma::mat &state, const arma::mat &v);
arma::mat row_one_hot(size_t len, size_t index)
{
arma::mat data = arma::zeros(1, len);
data[index] = 1;
return data;
}
arma::mat to_next(const arma::mat &v, bool clamp=false)
{
arma::mat res = v.cols(0, NUM_CODES-1);
if (clamp)
{
res = row_one_hot(res.n_cols, res.index_max());
}
return res;
}
arma::mat to_curr(const arma::mat &v, bool clamp=false)
{
arma::mat res = v.cols(NUM_CODES, 2*NUM_CODES-1);
if (clamp)
{
res = row_one_hot(res.n_cols, res.index_max());
}
return res;
}
void setParams(Rbm::Params const &param)
{
Layer *pLayer = getLayer(0);
while (pLayer)
{
pLayer->params() = param;
pLayer = pLayer->next;
}
}
private:
};
#endif /* RNNSTACK_HPP */