- added one hot gen

git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@841 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2022-01-19 11:02:11 +00:00
parent 963ee3cd9d
commit 7232870123
3 changed files with 43 additions and 26 deletions
+20 -21
View File
@@ -36,21 +36,11 @@ class RbmListener : public Rbm::IListener
#define CREATE_TRAINING 0
#define DO_TRAINING 0
#define DO_TRAINING 1
#define DO_FORWARD 1
int main()
{
arma::mat sm = arma::zeros(8, 4);
for (int i=0; i < sm.n_rows; i++)
{
sm = arma::shift(sm, 1, 0);
//sm(0,0) = i;
sm.row(0) = i*arma::eye(1,4);
sm.print("sm");
}
#if CREATE_TRAINING
arma::mat batch = RnnTextHelper::createTraining("moby_ch1.txt", RnnTextHelper::SEQ_LENGTH);
batch.save("poet2.training.dat", arma::arma_ascii);
@@ -58,7 +48,7 @@ int main()
#endif
// Load project
RnnStack *stack = reinterpret_cast<RnnStack*>(StackCreator::fromFile(".", "poet2"));
RnnStack *stack = reinterpret_cast<RnnStack*>(StackCreator::fromFile(".", "poet_2v_5s"));
// Load weights
stack->loadWeights(".");
@@ -98,22 +88,31 @@ int main()
#if DO_FORWARD
arma::mat state;
arma::mat curr;
arma::mat next;
std::string curr_str;
std::string next_str;
for (int i=0; i < t_vc.n_rows; i++)
{
curr = stack->to_curr(t_vc.row(i));
curr_str.append(1,RnnTextHelper::idx2ch(curr.index_max()));
arma::mat r = stack->step_forward(state, curr);
arma::mat next = stack->to_next(r);
char c = RnnTextHelper::idx2ch(next.index_max());
putchar(c);
next = stack->to_next(r, true);
next_str.append(1,RnnTextHelper::idx2ch(next.index_max()));
}
printf("\n");
for (int i=0; i < 40; i++)
cout << "Curr: " << curr_str << std::endl;
cout << "Next: " << next_str << std::endl;
for (int i=0; i < 430; i++)
{
curr = stack->to_next(stack->step_forward(state, curr));
char c = RnnTextHelper::idx2ch(curr.index_max());
putchar(c);
curr = next;
curr_str.append(1,RnnTextHelper::idx2ch(curr.index_max()));
arma::mat r = stack->step_forward(state, curr);
next = stack->to_next(r, true);
curr = stack->to_curr(r);
next_str.append(1,RnnTextHelper::idx2ch(next.index_max()));
}
printf("\n");
cout << "Curr: " << curr_str << std::endl;
cout << "Next: " << next_str << std::endl;
#endif
printf("\nEnd of program\n");