STK++ 0.9.13
STK_Law_LogNormal.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: LogNormal probability distribution.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_LOGNORMAL_H
36#define STK_LAW_LOGNORMAL_H
37
38#include <Sdk.h>
39
40#include "STK_Law_IUnivLaw.h"
41
42namespace STK
43{
44namespace Law
45{
70class LogNormal: public IUnivLaw<Real>
71{
72 public:
78 inline LogNormal( Real const& mu=0., Real const& sigma=1.)
79 : Base(_T("LogNormal")), mu_(mu), sigma_(sigma) {}
80
82 inline virtual ~LogNormal() {}
84 inline Real const& mu() const { return mu_;}
86 inline Real const& sigma() const { return sigma_;}
88 inline void setMu( Real const& mu) { mu_ = mu;}
90 inline void setSigma( Real const& sigma)
91 {
93 sigma_ = sigma;
94 }
101 Real rand() const;
105 virtual Real pdf( Real const& x) const;
109 virtual Real lpdf( Real const& x) const;
115 virtual Real cdf( Real const& t) const;
122 virtual Real icdf( Real const& p) const;
123
132 static Real rand( Real const& mu, Real const& sigma);
137 static Real pdf( Real const& x, Real const& mu, Real const& sigma);
142 static Real lpdf( Real const& x, Real const& mu, Real const& sigma);
149 static Real cdf( Real const& t, Real const& mu, Real const& sigma);
157 static Real icdf( Real const& p, Real const& mu, Real const& sigma);
158
159#ifdef IS_RTKPP_LIB
161 virtual Real lcdf( Real const& t) const;
163 virtual Real cdfc( Real const& t) const;
165 virtual Real lcdfc( Real const& t) const;
166#endif
167
168 protected:
173};
174
175#ifdef IS_RTKPP_LIB
176
177inline Real LogNormal::rand() const
178{
179#ifdef _OPENMP
180//#pragma omp critical
181#endif
182GetRNGstate(); Real s = Rf_rlnorm(mu_, sigma_); PutRNGstate(); return s;
183}
184
185inline Real LogNormal::pdf( Real const& x) const { return Rf_dlnorm(x, mu_, sigma_, false);}
186inline Real LogNormal::lpdf( Real const& x) const { return Rf_dlnorm(x, mu_, sigma_, true);}
187inline Real LogNormal::cdf( Real const& t) const { return Rf_plnorm(t, mu_, sigma_, true, false);}
188inline Real LogNormal::lcdf( Real const& t) const { return Rf_plnorm(t, mu_, sigma_, true, true);}
189inline Real LogNormal::cdfc( Real const& t) const { return Rf_plnorm(t, mu_, sigma_, false, false);}
190inline Real LogNormal::lcdfc( Real const& t) const { return Rf_plnorm(t, mu_, sigma_, false, true);}
191inline Real LogNormal::icdf( Real const& p) const { return Rf_qlnorm(p, mu_, sigma_, true, false);}
192
193inline Real LogNormal::rand( Real const& mu, Real const& sigma)
194{
195#ifdef _OPENMP
196//#pragma omp critical
197#endif
198GetRNGstate(); Real s = Rf_rlnorm(mu, sigma); PutRNGstate(); return s;
199}
200
201inline Real LogNormal::pdf( Real const& x, Real const& mu, Real const& sigma)
202{ return Rf_dlnorm(x, mu, sigma, false);}
203inline Real LogNormal::lpdf( Real const& x, Real const& mu, Real const& sigma)
204{ return Rf_dlnorm(x, mu, sigma, true);}
205inline Real LogNormal::cdf( Real const& t, Real const& mu, Real const& sigma)
206{ return Rf_plnorm(t, mu, sigma, true, false);}
207inline Real LogNormal::icdf( Real const& p, Real const& mu, Real const& sigma)
208{ return Rf_qlnorm(p, mu, sigma, true, false);}
209
210#endif
211
212} // namespace Law
213
214} // namespace STK
215
216#endif /*STK_LAW_LOGNORMAL_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.
This file include all the other header files of the project Sdk.
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...
LogNormal distribution law.
Real const & mu() const
Real const & sigma() const
virtual Real cdf(Real const &t) const
Compute the cumulative distribution function at t of the standard log-normal distribution.
virtual ~LogNormal()
Destructor.
void setMu(Real const &mu)
IUnivLaw< Real > Base
Real mu_
The location parameter.
Real sigma_
The scale parameter.
virtual Real lpdf(Real const &x) const
void setSigma(Real const &sigma)
virtual Real icdf(Real const &p) const
Compute the inverse cumulative distribution function at p of the standard log-normal distribution.
LogNormal(Real const &mu=0., Real const &sigma=1.)
Constructor.
Real rand() const
Generate a pseudo log-normalized LogNormal random variate.
virtual Real pdf(Real const &x) const
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.