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
commit41446328cf06a64e729835719d99fef33ec59941 (patch)
tree967881e3e967d65a620d060ece9f8b6e6bc99cca /gi/pyp-topics/src/pyp-topics.cc
parentf417aa33ee1e1ff2a301128ed08aa9dba7c2ff6b (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;