summaryrefslogtreecommitdiff
path: root/phrasinator
diff options
context:
space:
mode:
authorGuest_account Guest_account prguest11 <prguest11@taipan.cs>2011-10-11 16:16:53 +0100
committerGuest_account Guest_account prguest11 <prguest11@taipan.cs>2011-10-11 16:16:53 +0100
commit08c4a7fae8f0bec4f76c4e0928e357100eb7a1ca (patch)
tree44030db9ef1625ce130ab08acfd308643d568d1f /phrasinator
parentffaae62e4f1cedabbc6eb1982af129e7294d33eb (diff)
remove implicit conversion-to-double operator from LogVal<T> that caused overflow errors, clean up some pf code
Diffstat (limited to 'phrasinator')
-rw-r--r--phrasinator/ccrp_nt.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/phrasinator/ccrp_nt.h b/phrasinator/ccrp_nt.h
index 163b643a..811bce73 100644
--- a/phrasinator/ccrp_nt.h
+++ b/phrasinator/ccrp_nt.h
@@ -50,15 +50,26 @@ class CCRP_NoTable {
return it->second;
}
- void increment(const Dish& dish) {
- ++custs_[dish];
+ int increment(const Dish& dish) {
+ int table_diff = 0;
+ if (++custs_[dish] == 1)
+ table_diff = 1;
++num_customers_;
+ return table_diff;
}
- void decrement(const Dish& dish) {
- if ((--custs_[dish]) == 0)
+ int decrement(const Dish& dish) {
+ int table_diff = 0;
+ int nc = --custs_[dish];
+ if (nc == 0) {
custs_.erase(dish);
+ table_diff = -1;
+ } else if (nc < 0) {
+ std::cerr << "Dish counts dropped below zero for: " << dish << std::endl;
+ abort();
+ }
--num_customers_;
+ return table_diff;
}
double prob(const Dish& dish, const double& p0) const {
@@ -66,6 +77,11 @@ class CCRP_NoTable {
return (at_table + p0 * concentration_) / (num_customers_ + concentration_);
}
+ double logprob(const Dish& dish, const double& logp0) const {
+ const unsigned at_table = num_customers(dish);
+ return log(at_table + exp(logp0 + log(concentration_))) - log(num_customers_ + concentration_);
+ }
+
double log_crp_prob() const {
return log_crp_prob(concentration_);
}