|
bpp-core
2.1.0
|
00001 // 00002 // File: UniformDiscreteDistribution.h 00003 // Created by: Laurent Guéguen 00004 // Created on: April 2010 00005 // 00006 00007 /* 00008 Copyright or © or Copr. CNRS, (2010) 00009 00010 This software is a computer program whose purpose is to provide classes 00011 for numerical calculus. 00012 00013 This software is governed by the CeCILL license under French law and 00014 abiding by the rules of distribution of free software. You can use, 00015 modify and/ or redistribute the software under the terms of the CeCILL 00016 license as circulated by CEA, CNRS and INRIA at the following URL 00017 "http://www.cecill.info". 00018 00019 As a counterpart to the access to the source code and rights to copy, 00020 modify and redistribute granted by the license, users are provided only 00021 with a limited warranty and the software's author, the holder of the 00022 economic rights, and the successive licensors have only limited 00023 liability. 00024 00025 In this respect, the user's attention is drawn to the risks associated 00026 with loading, using, modifying and/or developing or reproducing the 00027 software by the user in light of its specific status of free software, 00028 that may mean that it is complicated to manipulate, and that also 00029 therefore means that it is reserved for developers and experienced 00030 professionals having in-depth computer knowledge. Users are therefore 00031 encouraged to load and test the software's suitability as regards their 00032 requirements in conditions enabling the security of their systems and/or 00033 data to be ensured and, more generally, to use and operate it in the 00034 same conditions as regards security. 00035 00036 The fact that you are presently reading this means that you have had 00037 knowledge of the CeCILL license and that you accept its terms. 00038 */ 00039 00040 #ifndef _UNIFORMDISCRETEDISTRIBUTION_H_ 00041 #define _UNIFORMDISCRETEDISTRIBUTION_H_ 00042 00043 #include "AbstractDiscreteDistribution.h" 00044 #include "../Constraints.h" 00045 #include "../Random/RandomTools.h" 00046 00047 namespace bpp 00048 { 00049 00056 class UniformDiscreteDistribution: 00057 public AbstractDiscreteDistribution 00058 { 00059 private: 00060 double min_; 00061 double max_; 00062 00063 public: 00070 UniformDiscreteDistribution(unsigned int n, double min = 0., double max = 1.); 00071 00072 UniformDiscreteDistribution(const UniformDiscreteDistribution&); 00073 00074 UniformDiscreteDistribution& operator=(const UniformDiscreteDistribution&); 00075 00076 virtual ~UniformDiscreteDistribution(); 00077 00078 UniformDiscreteDistribution* clone() const { return new UniformDiscreteDistribution(*this); } 00079 00080 public: 00081 std::string getName() const {return("Uniform");} 00082 00083 void fireParameterChanged(const ParameterList & parameters); 00084 00085 double randC() const throw (Exception) 00086 { 00087 double x= RandomTools::giveRandomNumberBetweenZeroAndEntry(max_-min_)+min_; 00088 while (!intMinMax_.isCorrect(x)) 00089 x= RandomTools::giveRandomNumberBetweenZeroAndEntry(max_-min_)+min_; 00090 return x; 00091 } 00092 00093 double qProb(double x) const 00094 { 00095 return min_+x*(max_-min_); 00096 } 00097 00098 double pProb(double x) const 00099 { 00100 return (x<=min_)?0:(x-min_)/(max_-min_); 00101 } 00102 00103 double Expectation(double a) const 00104 { 00105 return (a<=min_)?0:((a>=max_)?(max_+min_)/2:(a*a-min_*min_)/(max_-min_)/2); 00106 } 00107 00108 }; 00109 00110 } //end of namespace bpp. 00111 00112 #endif //_UNIFORMDISCRETEDISTRIBUTION_H_ 00113