STK++ 0.9.13
STK_Law_Normal.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff
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 * Purpose: Normal probability distribution.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_NORMAL_H
36#define STK_LAW_NORMAL_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
45class Normal;
48
71class Normal: public IUnivLaw<Real>
72{
73 public:
87 inline virtual ~Normal() {}
89 inline Real const& mu() const { return mu_;}
91 inline Real const& sigma() const { return sigma_;}
93 inline void setMu( Real const& mu) { mu_ = mu;}
95 inline void setSigma( Real const& sigma)
96 {
98 sigma_ = sigma;
99 }
105 Real rand() const;
109 virtual Real pdf( Real const& x) const;
113 virtual Real lpdf( Real const& x) const;
126 virtual Real cdf( Real const& t) const;
138 virtual Real icdf( Real const& p) const;
139
148 static Real rand( Real const& mu, Real const& sigma);
153 static Real pdf( Real const& x, Real const& mu, Real const& sigma);
158 static Real lpdf( Real const& x, Real const& mu, Real const& sigma);
165 static Real cdf( Real const& t, Real const& mu, Real const& sigma);
172 static Real icdf( Real const& p, Real const& mu, Real const& sigma);
173
174#ifdef IS_RTKPP_LIB
176 virtual Real lcdf( Real const& t) const;
178 virtual Real cdfc( Real const& t) const;
180 virtual Real lcdfc( Real const& t) const;
181#endif
182
183 protected:
188};
189
190#ifdef IS_RTKPP_LIB
191
192/* Generate a pseudo Normal random variate. */
193inline Real Normal::rand() const
194{
195#ifdef _OPENMP
196//#pragma omp critical
197#endif
198GetRNGstate(); Real s = Rf_rnorm(mu_, sigma_); PutRNGstate(); return s;
199}
200
201inline Real Normal::pdf( Real const& x) const { return Rf_dnorm4(x, mu_, sigma_, false);}
202inline Real Normal::lpdf( Real const& x) const { return Rf_dnorm4(x, mu_, sigma_, true);}
203inline Real Normal::cdf( Real const& t) const { return Rf_pnorm5(t, mu_, sigma_, true, false);}
204inline Real Normal::lcdf( Real const& t) const { return Rf_pnorm5(t, mu_, sigma_, true, true);}
205inline Real Normal::cdfc( Real const& t) const { return Rf_pnorm5(t, mu_, sigma_, false, false);}
206inline Real Normal::lcdfc( Real const& t) const { return Rf_pnorm5(t, mu_, sigma_, false, true);}
207inline Real Normal::icdf( Real const& p) const { return Rf_qnorm5(p , mu_, sigma_, true, false);}
208
209
210inline Real Normal::rand( Real const& mu, Real const& scale)
211{
212#ifdef _OPENMP
213//#pragma omp critical
214#endif
215GetRNGstate(); Real s = Rf_rnorm(mu, scale); PutRNGstate(); return s;
216}
217
218inline Real Normal::pdf(Real const& x, Real const& mu, Real const& scale)
219{ return Rf_dnorm4(x,mu, scale, false);}
220inline Real Normal::lpdf(Real const& x, Real const& mu, Real const& scale)
221{ return Rf_dnorm4(x,mu, scale, true);}
222inline Real Normal::cdf(Real const& t, Real const& mu, Real const& scale)
223{ return Rf_pnorm5(t, mu, scale, true, false);}
224inline Real Normal::icdf(Real const& p, Real const& mu, Real const& scale)
225{ return Rf_qnorm5(p , mu, scale, true, false);}
226
227#endif
228
229} // namespace Law
230
231} // namespace STK
232
233#endif /*STK_LAW_NORMAL_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 STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:147
#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...
Normal distribution law.
virtual Real lpdf(Real const &x) const
virtual Real icdf(Real const &p) const
Compute the inverse cumulative distribution function at p of the standard normal distribution.
Real sigma_
The sigma parameter.
virtual Real pdf(Real const &x) const
virtual Real cdf(Real const &t) const
Compute the cumulative distribution function at t of the standard normal distribution.
void setMu(Real const &mu)
IUnivLaw< Real > Base
Normal(Real const &mu=0., Real const &sigma=1.)
Constructor.
Real const & mu() const
Real const & sigma() const
Real mu_
The mu parameter.
Real rand() const
Generate a pseudo Normal random variate.
virtual ~Normal()
Destructor.
void setSigma(Real const &sigma)
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
std::basic_string< Char > String
STK fundamental type of a String.
double Real
STK fundamental type of Real values.
Normal Gaussian
A synonymous for the normal law.
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.