STK++ 0.9.13
STK_Law_Poisson.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: 8 dec. 2014
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_POISSON_H
36#define STK_LAW_POISSON_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
69class Poisson: public IUnivLaw<int>
70{
71 public:
76 inline Poisson( Real const& lambda = 1.)
77 : Base(_T("Poisson")), lambda_(lambda) {}
79 inline virtual ~Poisson() {}
81 inline Real const& lambda() const { return lambda_;}
83 inline void setLambda(Real const& lambda )
84 {
85 if (lambda<0)
88 }
89
91 virtual int rand() const;
97 virtual Real pdf(int const& x) const;
103 virtual Real lpdf(int const& x) const;
110 virtual Real cdf(Real const& t) const;
117 virtual int icdf(Real const& p) const;
118
122 static int rand(Real const& lambda);
129 static Real pdf(int const& x, Real const& lambda);
136 static Real lpdf(int const& x, Real const& lambda);
144 static Real cdf(Real const& t, Real const& lambda);
152 static int icdf(Real const& p, Real const& lambda);
153
154#ifdef IS_RTKPP_LIB
156 virtual Real lcdf( Real const& t) const;
158 virtual Real cdfc( Real const& t) const;
160 virtual Real lcdfc( Real const& t) const;
161#endif
162
163 protected:
166};
167
168#ifdef IS_RTKPP_LIB
169
170inline int Poisson::rand() const
171{
172#ifdef _OPENMP
173//#pragma omp critical
174#endif
175 GetRNGstate(); int s = (int)Rf_rpois(lambda_); PutRNGstate(); return s;
176}
177
178inline Real Poisson::pdf(int const& x) const { return Rf_dpois((double)x, lambda_, false);}
179inline Real Poisson::lpdf(int const& x) const { return Rf_dpois((double)x, lambda_, true);}
180inline Real Poisson::cdf(Real const& t) const { return Rf_ppois(t, lambda_, true, false);}
181inline Real Poisson::lcdf(Real const& t) const { return Rf_ppois(t, lambda_, true, true);}
182inline Real Poisson::cdfc(Real const& t) const { return Rf_ppois(t, lambda_, false, false);}
183inline Real Poisson::lcdfc(Real const& t) const { return Rf_ppois(t, lambda_, false, true);}
184inline int Poisson::icdf(Real const& p) const { return (int)::Rf_qpois(p, lambda_, true, false);}
185
186
187inline int Poisson::rand(Real const& lambda)
188{
189#ifdef _OPENMP
190//#pragma omp critical
191#endif
192 GetRNGstate(); int s = (int)Rf_rpois(lambda); PutRNGstate(); return s;
193}
194
195inline Real Poisson::pdf(int const& x, Real const& lambda)
196{ return Rf_dpois((double)x, lambda, false);}
197inline Real Poisson::lpdf(int const& x, Real const& lambda)
198{ return Rf_dpois((double)x, lambda, true);}
199inline Real Poisson::cdf(Real const& t, Real const& lambda)
200{ return Rf_ppois(t, lambda, true, false);}
201inline int Poisson::icdf(Real const& p, Real const& lambda)
202{ return (int)Rf_qpois(p, lambda, true, false);}
203
204#endif
205
206} // namespace Law
207
208} // namespace STK
209
210#endif /* STK_LAW_POISSON_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.
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...
Poisson distribution law.
virtual Real cdf(Real const &t) const
compute the cumulative distribution function Give the probability that a Poisson random variate is le...
Real lambda_
mean of the Poisson distribution
Poisson(Real const &lambda=1.)
constructor
virtual int rand() const
void setLambda(Real const &lambda)
IUnivLaw< int > Base
Real const & lambda() const
virtual int icdf(Real const &p) const
inverse cumulative distribution function The quantile is defined as the smallest value q such that F...
virtual Real lpdf(int const &x) const
compute the log probability distribution function.
virtual Real pdf(int const &x) const
compute the probability distribution function.
virtual ~Poisson()
destructor
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.