From 41446328cf06a64e729835719d99fef33ec59941 Mon Sep 17 00:00:00 2001 From: bothameister Date: Mon, 5 Jul 2010 23:31:35 +0000 Subject: migrating away from mt19937ar to Boost.Random - separate RNG instances used in various places git-svn-id: https://ws10smt.googlecode.com/svn/trunk@146 ec762483-ff6d-05da-a07a-a48fb63a330f --- gi/pyp-topics/src/pyp-topics.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'gi/pyp-topics/src/pyp-topics.cc') diff --git a/gi/pyp-topics/src/pyp-topics.cc b/gi/pyp-topics/src/pyp-topics.cc index 2ad9d080..2b96816e 100644 --- a/gi/pyp-topics/src/pyp-topics.cc +++ b/gi/pyp-topics/src/pyp-topics.cc @@ -5,7 +5,6 @@ #endif #include "pyp-topics.hh" -//#include "mt19937ar.h" #include #include @@ -46,13 +45,13 @@ void PYPTopics::sample_corpus(const Corpus& corpus, int samples, { m_word_pyps.at(i).reserve(m_num_topics); for (int j=0; j(0.5, 1.0)); + m_word_pyps.at(i).push_back(new PYP(0.5, 1.0, m_seed)); } std::cerr << std::endl; m_document_pyps.reserve(corpus.num_documents()); for (int j=0; j(0.5, 1.0)); + m_document_pyps.push_back(new PYP(0.5, 1.0, m_seed)); m_topic_p0 = 1.0/m_num_topics; m_term_p0 = 1.0/corpus.num_types(); @@ -118,8 +117,10 @@ void PYPTopics::sample_corpus(const Corpus& corpus, int samples, int tmp; for (int i = corpus.num_documents()-1; i > 0; --i) { - int j = (int)(mt_genrand_real1() * i); - tmp = randomDocIndices[i]; + //i+1 since j \in [0,i] but rnd() \in [0,1) + int j = (int)(rnd() * (i+1)); + assert(j >= 0 && j <= i); + tmp = randomDocIndices[i]; randomDocIndices[i] = randomDocIndices[j]; randomDocIndices[j] = tmp; } @@ -258,7 +259,7 @@ int PYPTopics::sample(const DocumentId& doc, const Term& term) { sums.push_back(sum); } // Second pass: sample a topic - F cutoff = mt_genrand_res53() * sum; + F cutoff = rnd() * sum; for (int k=0; k