summaryrefslogtreecommitdiff
path: root/gi/pyp-topics/src/pyp-topics.cc
diff options
context:
space:
mode:
authorbothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-05 23:31:35 +0000
committerbothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-05 23:31:35 +0000
commite939fa567a3d33029b2f1084732b7472a48a9884 (patch)
tree7b3ee62272381463bd809b5139b109eadc82fcf9 /gi/pyp-topics/src/pyp-topics.cc
parent11deae81f9c6bf8f85a29dfdf8b1531d7c563ef8 (diff)
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
Diffstat (limited to 'gi/pyp-topics/src/pyp-topics.cc')
-rw-r--r--gi/pyp-topics/src/pyp-topics.cc13
1 files changed, 7 insertions, 6 deletions
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 <boost/date_time/posix_time/posix_time_types.hpp>
#include <time.h>
@@ -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<m_num_topics; ++j)
- m_word_pyps.at(i).push_back(new PYP<int>(0.5, 1.0));
+ m_word_pyps.at(i).push_back(new PYP<int>(0.5, 1.0, m_seed));
}
std::cerr << std::endl;
m_document_pyps.reserve(corpus.num_documents());
for (int j=0; j<corpus.num_documents(); ++j)
- m_document_pyps.push_back(new PYP<int>(0.5, 1.0));
+ m_document_pyps.push_back(new PYP<int>(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<m_num_topics; ++k) {
if (cutoff <= sums[k])
return k;