STK++ 0.9.13
STK_Law_Geometric.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 * Project: stkpp::STatistiK::Law
26 * created on: 23 janv. 2013
27 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
28 **/
29
34#ifndef STK_LAW_GEOMETRIC_H
35#define STK_LAW_GEOMETRIC_H
36
37#include "STK_Law_IUnivLaw.h"
38
39namespace STK
40{
41
42namespace Law
43{
44
58class Geometric: public IUnivLaw<Integer>
59{
60 public:
65 inline Geometric(Real const& prob =0.5): Base(_T("Geometric")), prob_(prob)
66 {}
68 inline virtual ~Geometric(){}
70 inline Real const& prob() const { return prob_;}
79 virtual Integer rand() const;
85 virtual Real pdf(Integer const& x) const;
91 virtual Real lpdf(Integer const& x) const;
98 virtual Real cdf(Real const& t) const;
104 virtual Integer icdf(Real const& p) const;
105
110 static Integer rand(Real const& prob);
117 static Real pdf(Integer x, Real const& prob);
124 static Real lpdf(Integer x, Real const& prob);
132 static Real cdf(Real const& t, Real const& prob);
139 static Integer icdf(Real const& p, Real const& prob);
140
141#ifdef IS_RTKPP_LIB
143 virtual Real lcdf( Real const& t) const;
145 virtual Real cdfc( Real const& t) const;
147 virtual Real lcdfc( Real const& t) const;
148#endif
149
150 protected:
153};
154
155#ifdef IS_RTKPP_LIB
156
157
158inline int Geometric::rand() const
159{
160#ifdef _OPENMP
161//#pragma omp critical
162#endif
163GetRNGstate(); int s = Rf_rgeom(prob_); PutRNGstate(); return s;
164}
165
166inline Real Geometric::pdf(Integer const& x) const { return Rf_dgeom((double)x, prob_, false);}
167inline Real Geometric::lpdf(Integer const& x) const { return Rf_dgeom((double)x, prob_, true);}
168inline Real Geometric::cdf(Real const& t) const { return Rf_pgeom(t, prob_, true, false);}
169inline Real Geometric::lcdf(Real const& t) const { return Rf_pgeom(t, prob_, true, true);}
170inline Real Geometric::cdfc(Real const& t) const { return Rf_pgeom(t, prob_, false, false);}
171inline Real Geometric::lcdfc(Real const& t) const { return Rf_pgeom(t, prob_, false, true);}
172inline int Geometric::icdf(Real const& p) const { return Rf_qgeom(p, prob_, true, false);}
173
174inline int Geometric::rand(Real const& prob)
175{
176#ifdef _OPENMP
177//#pragma omp critical
178#endif
179GetRNGstate(); int s = Rf_rgeom(prob); PutRNGstate(); return s;
180}
181
182inline Real Geometric::pdf(Integer x, Real const& prob)
183{ return Rf_dgeom((double)x, prob, false);}
184inline Real Geometric::lpdf(Integer x, Real const& prob)
185{ return Rf_dgeom((double)x, prob, true);}
186inline Real Geometric::cdf(Real const& t, Real const& prob)
187{ return Rf_pgeom(t, prob, true, false);}
188inline Integer Geometric::icdf(Real const& p, Real const& prob)
189{ return (Integer)::Rf_qgeom(p, prob, true, false);}
190
191#endif
192} // namespace Law
193
194} // namespace STK
195
196#endif /* STK_LAW_GEOMETRIC_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.
Geometric probability law.
virtual ~Geometric()
destructor
IUnivLaw< Integer > Base
virtual Real cdf(Real const &t) const
compute the cumulative distribution function Give the probability that a Geometric random variate is ...
virtual Integer rand() const
virtual Real pdf(Integer const &x) const
compute the probability distribution function (density) Give the value of the pdf at the point x.
virtual Real lpdf(Integer const &x) const
compute the log probability distribution function Give the value of the log-pdf at the point x.
virtual Integer icdf(Real const &p) const
inverse cumulative distribution function The quantile is defined as the smallest value x such that F...
Geometric(Real const &prob=0.5)
constructor
void setProb(Real const &prob)
Real const & prob() const
Real prob_
probability of success in a Bernoulli trial
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.