- refactored
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@853 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+7
-31
@@ -61,7 +61,8 @@ class RbmListener : public Rbm::IListener
|
||||
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);
|
||||
next = stack->to_next(r, true);
|
||||
next = stack->to_next(r);
|
||||
stack->clamp_one_hot(next);
|
||||
next_str.append(1,RnnTextHelper::idx2ch(next.index_max()));
|
||||
}
|
||||
cout << "Curr: " << curr_str << std::endl;
|
||||
@@ -72,7 +73,8 @@ class RbmListener : public Rbm::IListener
|
||||
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);
|
||||
next = stack->to_next(r);
|
||||
stack->clamp_one_hot(next);
|
||||
curr = stack->to_curr(r);
|
||||
next_str.append(1,RnnTextHelper::idx2ch(next.index_max()));
|
||||
}
|
||||
@@ -127,6 +129,8 @@ int main(int argc, char *argv[])
|
||||
stack->loadTrainingBatch(".");
|
||||
arma::mat t_vc = stack->trainingBatch();
|
||||
|
||||
RbmListener listener(*stack);
|
||||
|
||||
if (command == Command::Reset)
|
||||
{
|
||||
for (int i=0; i < stack->numLayers(); i++)
|
||||
@@ -138,8 +142,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (command == Command::Train)
|
||||
{
|
||||
RbmListener listener(*stack);
|
||||
|
||||
// Phase 10
|
||||
stack->train(t_vc, &listener);
|
||||
|
||||
@@ -168,33 +170,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (command == Command::Forward)
|
||||
{
|
||||
arma::mat state;
|
||||
arma::mat curr;
|
||||
arma::mat next;
|
||||
std::string curr_str;
|
||||
std::string next_str;
|
||||
for (int i=0; i < stack->getSeqLen(); 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);
|
||||
next = stack->to_next(r, true);
|
||||
next_str.append(1,RnnTextHelper::idx2ch(next.index_max()));
|
||||
}
|
||||
cout << "Curr: " << curr_str << std::endl;
|
||||
cout << "Next: " << next_str << std::endl;
|
||||
|
||||
for (int i=stack->getSeqLen(); i < t_vc.n_rows; i++)
|
||||
{
|
||||
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()));
|
||||
}
|
||||
cout << "Curr: " << curr_str << std::endl;
|
||||
cout << "Next: " << next_str << std::endl;
|
||||
listener.forward();
|
||||
}
|
||||
printf("\nEnd of program\n");
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user