PMF.h
Go to the documentation of this file.
00001 /************************************************************************
00002  *  Copyright (C) 2012 Eindhoven University of Technology (TU/e).       *
00003  *  All rights reserved.                                                *
00004  ************************************************************************
00005  *  Redistribution and use in source and binary forms, with or without  *
00006  *  modification, are permitted provided that the following conditions  *
00007  *  are met:                                                            *
00008  *                                                                      *
00009  *      1.  Redistributions of source code must retain the above        *
00010  *          copyright notice, this list of conditions and the following *
00011  *          disclaimer.                                                 *
00012  *                                                                      *
00013  *      2.  Redistributions in binary form must reproduce the above     *
00014  *          copyright notice, this list of conditions and the following *
00015  *          disclaimer in the documentation and/or other materials      *
00016  *          provided with the distribution.                             *
00017  *                                                                      *
00018  *  THIS SOFTWARE IS PROVIDED BY TU/e "AS IS" AND ANY EXPRESS OR        *
00019  *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED      *
00020  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  *
00021  *  ARE DISCLAIMED. IN NO EVENT SHALL TU/e OR CONTRIBUTORS BE LIABLE    *
00022  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR        *
00023  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   *
00024  *  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;     *
00025  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF       *
00026  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           *
00027  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE   *
00028  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH    *
00029  *  DAMAGE.                                                             *
00030  *                                                                      *
00031  *  The views and conclusions contained in the software and             *
00032  *  documentation are those of the authors and should not be            *
00033  *  interpreted as representing official policies, either expressed or  *
00034  *  implied, of TU/e.                                                   *
00035  ************************************************************************/
00036 
00037 #ifndef PROBLIB_PMF_H_
00038 #define PROBLIB_PMF_H_
00039 
00040 #include "PDF.h"
00041 
00042 namespace pbl {
00043 
00052 class PMF : public PDF {
00053 
00054 public:
00055 
00063         PMF(int domain_size = -1);
00064 
00068         PMF(const PMF& pmf);
00069 
00073         virtual ~PMF();
00074 
00080         PMF& operator=(const PMF& other);
00081 
00087         PMF* clone() const;
00088 
00093         double getProbability(const std::string& value) const;
00094 
00101         double getProbability(const std::string& value, int domain_size) const;
00102 
00106         void setProbability(const std::string& value, double p);
00107 
00112         void setExact(const std::string& value);
00113 
00117         void getValues(std::vector<std::string>& values) const;
00118 
00122         void getProbabilities(std::vector<double>& probabilities) const;
00123 
00124         double getLikelihood(const PDF& pdf) const;
00125 
00126         double getLikelihood(const PMF& pmf) const;
00127 
00133         bool getExpectedValue(std::string& v) const;
00134 
00135         void update(const pbl::PMF& pmf);
00136 
00140         void setDomainSize(int domain_size);
00141 
00145         int getDomainSize() const;
00146 
00147         void normalize();
00148 
00154         std::string toString(const std::string& indent = "") const;
00155 
00156         double getDensity(const arma::vec& v) const;
00157 
00158         double getMaxDensity() const;
00159 
00160         double getProbabilityUnknown() const;
00161 
00162         double getProbabilityUnknown(int domain_size) const;
00163 
00164         // obsolete
00165 
00166         std::string getMostProbableValue() const;
00167 
00168 
00169 protected:
00170 
00171         struct PMFStruct {
00172 
00173                 int domain_size_;
00174 
00175                 double total_prob_;
00176 
00177                 std::map<std::string, double> pmf_;
00178 
00179                 int n_ptrs_;
00180 
00181                 PMFStruct(int domain_size) : domain_size_(domain_size), total_prob_(0), n_ptrs_(1) { }
00182 
00183                 PMFStruct(const PMFStruct& orig) : domain_size_(orig.domain_size_), total_prob_(orig.total_prob_), pmf_(orig.pmf_), n_ptrs_(1) { }
00184         };
00185 
00186         PMFStruct* ptr_;
00187 
00188         void cloneStruct();
00189 
00190 };
00191 
00192 }
00193 
00194 #endif /* PMF_H_ */


problib
Author(s): Sjoerd van den Dries
autogenerated on Tue Jan 7 2014 11:42:42