- added void sample_one_hot()
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@856 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#define RNNSTACK_HPP
|
#define RNNSTACK_HPP
|
||||||
|
|
||||||
#include "AStack.hpp"
|
#include "AStack.hpp"
|
||||||
|
#include "matutils.hpp"
|
||||||
|
|
||||||
class RnnStack : public AStack
|
class RnnStack : public AStack
|
||||||
{
|
{
|
||||||
@@ -33,6 +34,27 @@ public:
|
|||||||
|
|
||||||
arma::mat step_forward(arma::mat &state, const arma::mat &v);
|
arma::mat step_forward(arma::mat &state, const arma::mat &v);
|
||||||
|
|
||||||
|
void sample_one_hot(arma::mat &srcDst)
|
||||||
|
{
|
||||||
|
double k = arma::accu(srcDst);
|
||||||
|
|
||||||
|
if (k != 0)
|
||||||
|
{
|
||||||
|
srcDst = srcDst / k;
|
||||||
|
}
|
||||||
|
|
||||||
|
arma::mat ps = Matutils::sample(srcDst);
|
||||||
|
if (arma::accu(ps) > 1)
|
||||||
|
{
|
||||||
|
arma::uvec q1 = find(ps > 0);
|
||||||
|
int winner = (q1.n_elem-1) * arma::randu(1)[0];
|
||||||
|
int wix = q1(winner);
|
||||||
|
|
||||||
|
srcDst = zeros(arma::size(srcDst));
|
||||||
|
srcDst[wix] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clamp_one_hot(arma::mat &srcDst)
|
void clamp_one_hot(arma::mat &srcDst)
|
||||||
{
|
{
|
||||||
int index = srcDst.index_max();
|
int index = srcDst.index_max();
|
||||||
|
|||||||
Reference in New Issue
Block a user