PMF.h
Go to the documentation of this file.
1 /************************************************************************
2  * Copyright (C) 2012 Eindhoven University of Technology (TU/e). *
3  * All rights reserved. *
4  ************************************************************************
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above *
10  * copyright notice, this list of conditions and the following *
11  * disclaimer. *
12  * *
13  * 2. Redistributions in binary form must reproduce the above *
14  * copyright notice, this list of conditions and the following *
15  * disclaimer in the documentation and/or other materials *
16  * provided with the distribution. *
17  * *
18  * THIS SOFTWARE IS PROVIDED BY TU/e "AS IS" AND ANY EXPRESS OR *
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
21  * ARE DISCLAIMED. IN NO EVENT SHALL TU/e OR CONTRIBUTORS BE LIABLE *
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
28  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
29  * DAMAGE. *
30  * *
31  * The views and conclusions contained in the software and *
32  * documentation are those of the authors and should not be *
33  * interpreted as representing official policies, either expressed or *
34  * implied, of TU/e. *
35  ************************************************************************/
36 
37 #ifndef PROBLIB_PMF_H_
38 #define PROBLIB_PMF_H_
39 
40 #include "PDF.h"
41 
42 namespace pbl {
43 
52 class PMF : public PDF {
53 
54 public:
55 
63  PMF(int domain_size = -1);
64 
68  PMF(const PMF& pmf);
69 
73  virtual ~PMF();
74 
80  PMF& operator=(const PMF& other);
81 
87  PMF* clone() const;
88 
93  double getProbability(const std::string& value) const;
94 
101  double getProbability(const std::string& value, int domain_size) const;
102 
106  void setProbability(const std::string& value, double p);
107 
112  void setExact(const std::string& value);
113 
117  void getValues(std::vector<std::string>& values) const;
118 
122  void getProbabilities(std::vector<double>& probabilities) const;
123 
124  double getLikelihood(const PDF& pdf) const;
125 
126  double getLikelihood(const PMF& pmf) const;
127 
133  bool getExpectedValue(std::string& v) const;
134 
135  void update(const pbl::PMF& pmf);
136 
140  void setDomainSize(int domain_size);
141 
145  int getDomainSize() const;
146 
147  void normalize();
148 
154  std::string toString(const std::string& indent = "") const;
155 
156  double getDensity(const arma::vec& v) const;
157 
158  double getMaxDensity() const;
159 
160  double getProbabilityUnknown() const;
161 
162  double getProbabilityUnknown(int domain_size) const;
163 
164  // obsolete
165 
166  std::string getMostProbableValue() const;
167 
168 
169 protected:
170 
171  struct PMFStruct {
172 
174 
175  double total_prob_;
176 
177  std::map<std::string, double> pmf_;
178 
179  int n_ptrs_;
180 
181  PMFStruct(int domain_size) : domain_size_(domain_size), total_prob_(0), n_ptrs_(1) { }
182 
183  PMFStruct(const PMFStruct& orig) : domain_size_(orig.domain_size_), total_prob_(orig.total_prob_), pmf_(orig.pmf_), n_ptrs_(1) { }
184  };
185 
187 
188  void cloneStruct();
189 
190 };
191 
192 }
193 
194 #endif /* PMF_H_ */
double getProbability(const std::string &value) const
Returns the probability of the given value.
Definition: PMF.cpp:86
std::string getMostProbableValue() const
Definition: PMF.cpp:311
eT value() const
PMF(int domain_size=-1)
Constructs a discrete probability distribution. The optional parameter domain size states the number ...
Definition: PMF.cpp:41
void cloneStruct()
Definition: PMF.cpp:79
double getLikelihood(const PDF &pdf) const
Definition: PMF.cpp:153
double total_prob_
Definition: PMF.h:175
PMFStruct(int domain_size)
Definition: PMF.h:181
double getMaxDensity() const
Definition: PMF.cpp:288
void setExact(const std::string &value)
Set the probability of the given value to 1. All other values are given a probability of 0...
Definition: PMF.cpp:113
PMF & operator=(const PMF &other)
Assignment operator. The operation is cheap since it only copies a pointer. A deep clone will only be...
Definition: PMF.cpp:58
void normalize()
Definition: PMF.cpp:267
void setDomainSize(int domain_size)
Sets the domain size of this discrete distribution.
Definition: PMF.cpp:247
int domain_size_
Definition: PMF.h:173
PMFStruct(const PMFStruct &orig)
Definition: PMF.h:183
void getValues(std::vector< std::string > &values) const
Returns a vector of values for which a probability is specified.
Definition: PMF.cpp:124
std::string toString(const std::string &indent="") const
Represents the PMF as a string for easier console output.
Definition: PMF.cpp:293
bool getExpectedValue(std::string &v) const
Returns in parameter v the expected value for this distribution, i.e., the value with the highest pro...
Definition: PMF.cpp:136
void update(const pbl::PMF &pmf)
Definition: PMF.cpp:214
std::map< std::string, double > pmf_
Definition: PMF.h:177
int getDomainSize() const
Returns the domain size of this distribution.
Definition: PMF.cpp:252
void getProbabilities(std::vector< double > &probabilities) const
Returns all probabilities of the known values.
Definition: PMF.cpp:130
double getProbabilityUnknown() const
Definition: PMF.cpp:256
Definition: PDF.h:47
void setProbability(const std::string &value, double p)
Set the probability of a given value.
Definition: PMF.cpp:100
Col< double > vec
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.
Definition: PMF.cpp:75
virtual ~PMF()
Destructor.
Definition: PMF.cpp:50
This class represents a discrete probability distribution (or probability mass function). Currently, this PMF can only take strings as values.
Definition: PMF.h:52
double getDensity(const arma::vec &v) const
Definition: PMF.cpp:283
PMFStruct * ptr_
Definition: PMF.h:186


problib
Author(s): Sjoerd van den Dries, Jos Elfring
autogenerated on Fri Apr 16 2021 02:32:19