STK++ 0.9.13
STK_Law_HyperGeometric.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23 */
24
25/*
26 * Project: stkpp::STatistiK::Law
27 * created on: 23 janv. 2013
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_HYPERGEOMETRIC_H
36#define STK_LAW_HYPERGEOMETRIC_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
45
64class HyperGeometric: public IUnivLaw<Integer>
65{
66 public:
72 : Base(_T("HyperGeometric"))
76 {}
78 inline virtual ~HyperGeometric() {}
80 inline int nbSuccesses() const { return nbSuccesses_;}
82 inline int nbFailures() const { return nbFailures_;}
84 inline int nbDraws() const { return nbDraws_;}
109 virtual Integer rand() const;
115 virtual Real pdf(Integer const& x) const;
121 virtual Real lpdf(Integer const& x) const;
128 virtual Real cdf(Real const& t) const;
134 virtual Integer icdf(Real const& p) const;
135
140 static Integer rand( int nbSuccesses, int nbFailures, int nbDraws);
147 static Real pdf(Integer x, int nbSuccesses, int nbFailures, int nbDraws);
153 static Real lpdf(Integer x, int nbSuccesses, int nbFailures, int nbDraws);
161 static Real cdf(Real const& t, int nbSuccesses, int nbFailures, int nbDraws);
168 static Integer icdf(Real const& p, int nbSuccesses, int nbFailures, int nbDraws);
169
170#ifdef IS_RTKPP_LIB
172 virtual Real lcdf( Real const& t) const;
174 virtual Real cdfc( Real const& t) const;
176 virtual Real lcdfc( Real const& t) const;
177#endif
178
179 protected:
186};
187
188#ifdef IS_RTKPP_LIB
189
190inline int HyperGeometric::rand() const
191{
192#ifdef _OPENMP
193//#pragma omp critical
194#endif
196}
197
198inline Real HyperGeometric::pdf(Integer const& x) const
199{ return Rf_dhyper((double)x, nbSuccesses_, nbFailures_, nbDraws_, false);}
200inline Real HyperGeometric::lpdf(Integer const& x) const
201{ return Rf_dhyper((double)x, nbSuccesses_, nbFailures_, nbDraws_, true);}
202inline Real HyperGeometric::cdf(Real const& t) const
203{ return Rf_phyper(t, nbSuccesses_, nbFailures_, nbDraws_, true, false);}
204inline Real HyperGeometric::lcdf(Real const& t) const
205{ return Rf_phyper(t, nbSuccesses_, nbFailures_, nbDraws_, true, true);}
206inline Real HyperGeometric::cdfc(Real const& t) const
207{ return Rf_phyper(t, nbSuccesses_, nbFailures_, nbDraws_, false, false);}
208inline Real HyperGeometric::lcdfc(Real const& t) const
209{ return Rf_phyper(t, nbSuccesses_, nbFailures_, nbDraws_, false, true);}
210inline int HyperGeometric::icdf(Real const& p) const
211{ return (int)::Rf_qhyper(p, nbSuccesses_, nbFailures_, nbDraws_, true, false);}
212
213inline Integer HyperGeometric::rand( int nbSuccesses, int nbFailures, int nbDraws)
214{
215#ifdef _OPENMP
216//#pragma omp critical
217#endif
218 GetRNGstate(); int s = Rf_rhyper(nbSuccesses, nbFailures, nbDraws); PutRNGstate(); return s;
219}
220
221inline Real HyperGeometric::pdf(Integer x, int nbSuccesses, int nbFailures, int nbDraws)
222{ return Rf_dhyper((double)x, nbSuccesses, nbFailures, nbDraws, false);}
223inline Real HyperGeometric::lpdf(Integer x, int nbSuccesses, int nbFailures, int nbDraws)
224{ return Rf_dhyper((double)x, nbSuccesses, nbFailures, nbDraws, true);}
225inline Real HyperGeometric::cdf(Real const& t, int nbSuccesses, int nbFailures, int nbDraws)
226{ return Rf_phyper(t, nbSuccesses, nbFailures, nbDraws, true, false);}
227inline int HyperGeometric::icdf(Real const& p, int nbSuccesses, int nbFailures, int nbDraws)
228{ return (int)::Rf_qhyper(p, nbSuccesses, nbFailures, nbDraws, true, false);}
229
230#endif
231
232} // namespace Law
233
234} // namespace STK
235
236#endif /* STK_LAW_HYPERGEOMETRIC_H */
In this file we define the interface base class IUnivLaw for all probabilities laws.
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
#define _T(x)
Let x unmodified.
HyperGeometric probability law.
virtual Real pdf(Integer const &x) const
compute the probability distribution function (density) Give the value of the pdf at the point x.
int nbSuccesses_
number of successes
void setNbSuccesses(int nbSuccesses)
virtual Real cdf(Real const &t) const
compute the cumulative distribution function Give the probability that a HyperGeometric random variat...
void setNbFailures(int nbFailures)
virtual ~HyperGeometric()
destructor
HyperGeometric(int nbSuccesses, int nbFailures, int nbDraws)
constructor
virtual Integer icdf(Real const &p) const
inverse cumulative distribution function The quantile is defined as the smallest value x such that F...
int nbFailures_
number of failures
virtual Real lpdf(Integer const &x) const
compute the log probability distribution function Give the value of the log-pdf at the point x.
Interface base class for all the univariate distributions.
virtual Real cdfc(Real const &t) const
calculate the complement of cumulative distribution function, called in statistics the survival funct...
virtual Real lcdfc(Real const &t) const
calculate the log-complement of cumulative distribution function Give the log-probability that a rand...
virtual Real lcdf(Real const &t) const
compute the lower tail log-cumulative distribution function Give the log-probability that a random va...
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.
int Integer
STK fundamental type of integer values.
The namespace STK is the main domain space of the Statistical ToolKit project.