Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14f00dd

Browse files
author
Jonathan Chang
committed
Get some posteriors in there as well
1 parent 7449a3a commit 14f00dd

6 files changed

+41
-1
lines changed

DirichletPosterior.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class DirichletPosterior {
2+
Rcpp::Matrix<INTSXP> document_topic_counts_;
3+
double alpha_;
4+
public:
5+
#error initialize matrix objects
6+
DirichletPosterior(const int K, double alpha) : topics(K), alpha_(alpha_) {
7+
}
8+
9+
virtual double evaluate(const int topic, const Position& position) const {
10+
return document_topic_counts_(topic, position.getDocument()) + alpha;
11+
}
12+
13+
virtual void update(const int topic, const Position& position, const int count) {
14+
document_topic_counts_(topic, position.getDocument()) += count;
15+
}
16+
};

MatrixBackedTopicCounts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MatrixBackedTopicCounts : public TopicCounts {
1111
}
1212

1313
virtual void update(const int topic, const int word, const int count) {
14-
14+
topic_word_counts_(topic, word) += count;
15+
topic_word_counts_(topic) += count;
1516
}
1617
};

MultinomialPosterior.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class MultinomialPosterior {
2+
MatrixBackedTopicCounts topics;
3+
public:
4+
MultinomialPosterior(const int K_) : topics(K_) {
5+
}
6+
7+
virtual double evaluate(const Position& position, const int topic) const {
8+
position.getDocument()
9+
}
10+
};

Position.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Position {
2+
public:
3+
virtual int getDocument() const = 0;
4+
};

Posterior.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Posterior {
2+
public:
3+
virtual double evaluate(const Position& position, const int topic) const = 0;
4+
virtual void update(const Position& position, const int topic, const int count) = 0;
5+
};

TopicCounts.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class TopicCounts {
2+
int K_;
23
public:
4+
TopicCounts(const int K) : K_(K) {
5+
}
6+
37
virtual int getTopicWordCount(const int topic, const int word) const = 0;
48
virtual int getTopicCount(const int topic) const = 0;
59
virtual void update(const int topic, const int word, const int count) = 0;

0 commit comments

Comments
 (0)