76 return new PMF(*
this);
126 values.push_back((*it).first);
132 probabilities.push_back((*it).second);
139 if ((*it).second > p_max) {
141 p_max = (*it).second;
156 const PMF* pmf =
static_cast<const pbl::PMF*
>(&pdf);
164 assert(my_domain_size == -1 || other_domain_size == -1 || my_domain_size == other_domain_size);
165 int domain_size =
std::max(my_domain_size, other_domain_size);
168 const PMF* small_pmf =
this;
169 const PMF* big_pmf = &other;
176 double likelihood = 0;
177 double big_p_total_match = 0;
180 double big_p_v = big_pmf->
getProbability((*it).first, domain_size);
181 likelihood += big_p_v * (*it).second;
182 big_p_total_match += big_p_v;
193 int num_unmatched_values = (domain_size - small_pmf->
ptr_->
pmf_.size());
194 assert(num_unmatched_values > 0);
198 double big_p_unknown = (1 - big_p_total_match) / num_unmatched_values;
201 double small_p_unknown = (1 - small_pmf->
ptr_->
total_prob_) / num_unmatched_values;
205 likelihood += num_unmatched_values * big_p_unknown * small_p_unknown;
228 std::set<std::string> updated_values;
232 double new_prob = (*it).second * other.
getProbability((*it).first, this->ptr_->domain_size_) / likelihood;
233 (*it).second = new_prob;
235 updated_values.insert((*it).first);
239 if (updated_values.find((*it).first) == updated_values.end()) {
240 double new_prob = p_unknown * (*it).second / likelihood;
262 assert(domain_size > 0);
263 if (domain_size == (
int)
ptr_->
pmf_.size())
return 0;
284 assert_msg(
false,
"Cannot get density of a PMF");
289 assert_msg(
false,
"Cannot get max density of a PMF");
294 std::stringstream ss;
299 ss <<
" " << (*it).first <<
" : " << (*it).second;
301 for(; it !=
ptr_->
pmf_.end(); ++it) {
302 ss <<
", " << (*it).first <<
" : " << (*it).second;
double getProbability(const std::string &value) const
Returns the probability of the given value.
std::string getMostProbableValue() const
PMF(int domain_size=-1)
Constructs a discrete probability distribution. The optional parameter domain size states the number ...
double getLikelihood(const PDF &pdf) const
#define assert_msg(_Expression, _Msg)
double getMaxDensity() const
iterator(field< oT > &in_M, const bool at_end=false)
void setExact(const std::string &value)
Set the probability of the given value to 1. All other values are given a probability of 0...
PMF & operator=(const PMF &other)
Assignment operator. The operation is cheap since it only copies a pointer. A deep clone will only be...
void setDomainSize(int domain_size)
Sets the domain size of this discrete distribution.
const_iterator(const field< oT > &in_M, const bool at_end=false)
void getValues(std::vector< std::string > &values) const
Returns a vector of values for which a probability is specified.
std::string toString(const std::string &indent="") const
Represents the PMF as a string for easier console output.
bool getExpectedValue(std::string &v) const
Returns in parameter v the expected value for this distribution, i.e., the value with the highest pro...
void update(const pbl::PMF &pmf)
arma_warn_unused eT max() const
std::map< std::string, double > pmf_
int getDomainSize() const
Returns the domain size of this distribution.
void getProbabilities(std::vector< double > &probabilities) const
Returns all probabilities of the known values.
double getProbabilityUnknown() const
void setProbability(const std::string &value, double p)
Set the probability of a given value.
PMF * clone() const
Creates a clone of the object. The clone method is cheap since it only copies a pointer. A deep clone will only be created if the original object is modified.
virtual ~PMF()
Destructor.
This class represents a discrete probability distribution (or probability mass function). Currently, this PMF can only take strings as values.
double getDensity(const arma::vec &v) const