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
commit0af7d663194beddcde420349bbd91430e0b2e423 (patch)
treef79558499f3756757b94267285ccd1418e55b8ea /phrasinator
parent4671d578bd6d97105ac75b02e0144fe0df3abcb0 (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_);
}