- gibbsDoSampleHidden and gibbsDoSampleVisible onl used only training
- very good results git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@852 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+57
-11
@@ -19,19 +19,69 @@ using namespace arma;
|
||||
class RbmListener : public Rbm::IListener
|
||||
{
|
||||
public:
|
||||
RbmListener() {}
|
||||
RbmListener(AStack &stack)
|
||||
: m_stack(stack)
|
||||
, m_last_progress(0)
|
||||
{
|
||||
}
|
||||
virtual ~RbmListener() {}
|
||||
|
||||
bool onProgress(Rbm *pRbm, const Rbm::Status &status)
|
||||
{
|
||||
std::cout << "Progress : " << status.progress << " %" << std::endl;
|
||||
std::cout << "error (per mini batch) = " << status.err << std::endl;
|
||||
std::cout << "error (total) = " << status.err_total << std::endl;
|
||||
std::cout << "L1 = " << status.L1 << std::endl;
|
||||
std::cout << "L2 = " << status.L2 << std::endl;
|
||||
if (status.progress == 0)
|
||||
{
|
||||
m_last_progress = -10;
|
||||
}
|
||||
if ((status.progress - m_last_progress) == 10)
|
||||
{
|
||||
std::cout << "Progress : " << status.progress << " %" << std::endl;
|
||||
std::cout << "error (per mini batch) = " << status.err << std::endl;
|
||||
std::cout << "error (total) = " << status.err_total << std::endl;
|
||||
std::cout << "L1 = " << status.L1 << std::endl;
|
||||
std::cout << "L2 = " << status.L2 << std::endl;
|
||||
m_last_progress = status.progress;
|
||||
forward();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void forward()
|
||||
{
|
||||
RnnStack *stack = reinterpret_cast<RnnStack*>(&m_stack);
|
||||
arma::mat state;
|
||||
arma::mat curr;
|
||||
arma::mat next;
|
||||
std::string curr_str;
|
||||
std::string next_str;
|
||||
arma::mat t_vc = stack->trainingBatch();
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
AStack &m_stack;
|
||||
int m_last_progress;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -88,11 +138,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (command == Command::Train)
|
||||
{
|
||||
for (int i=0; i < stack->numLayers(); i++)
|
||||
{
|
||||
stack->getLayer(i)->params().gibbsDoSampleHidden = true;
|
||||
}
|
||||
RbmListener listener;
|
||||
RbmListener listener(*stack);
|
||||
|
||||
// Phase 10
|
||||
stack->train(t_vc, &listener);
|
||||
|
||||
Reference in New Issue
Block a user