STK++ 0.9.13
STK_Law_Logistic.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: Logistic probability distribution.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_LOGISTIC_H
36#define STK_LAW_LOGISTIC_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
67class Logistic: public IUnivLaw<Real>
68{
69 public:
75 inline Logistic( Real const& mu=0., Real const& scale=1.)
76 : Base(_T("Logistic")), mu_(mu), scale_(scale) {}
78 inline virtual ~Logistic() {}
80 inline Real const& mu() const { return mu_;}
82 inline Real const& scale() const { return scale_;}
84 inline void setMu( Real const& mu) { mu_ = mu;}
86 inline void setScale( Real const& scale)
87 {
89 scale_ = scale;
90 }
97 Real rand() const;
101 virtual Real pdf( Real const& x) const;
105 virtual Real lpdf( Real const& x) const;
119 virtual Real cdf( Real const& t) const;
132 virtual Real icdf( Real const& p) const;
133
140 static Real rand( Real const& mu, Real const& scale);
145 static Real pdf( Real const& x, Real const& mu, Real const& scale);
150 static Real lpdf( Real const& x, Real const& mu, Real const& scale);
155 static Real cdf( Real const& t, Real const& mu, Real const& scale);
160 static Real icdf( Real const& p, Real const& mu, Real const& scale);
161
162#ifdef IS_RTKPP_LIB
164 virtual Real lcdf( Real const& t) const;
166 virtual Real cdfc( Real const& t) const;
168 virtual Real lcdfc( Real const& t) const;
169#endif
170
171 protected:
176};
177
178#ifdef IS_RTKPP_LIB
179
180inline Real Logistic::rand() const
181{
182#ifdef _OPENMP
183//#pragma omp critical
184#endif
185GetRNGstate(); Real s = Rf_rlogis(mu_, scale_); PutRNGstate(); return s;
186}
187
188inline Real Logistic::pdf( Real const& x) const { return Rf_dlogis(x, mu_, scale_, false);}
189inline Real Logistic::lpdf( Real const& x) const { return Rf_dlogis(x, mu_, scale_, true);}
190inline Real Logistic::cdf( Real const& t) const { return Rf_plogis(t, mu_, scale_, true, false);}
191inline Real Logistic::lcdf( Real const& t) const { return Rf_plogis(t, mu_, scale_, true, true);}
192inline Real Logistic::cdfc( Real const& t) const { return Rf_plogis(t, mu_, scale_, false, false);}
193inline Real Logistic::lcdfc( Real const& t) const { return Rf_plogis(t, mu_, scale_, false, true);}
194inline Real Logistic::icdf( Real const& p) const { return Rf_qlogis(p, mu_, scale_, true, false);}
195
196inline Real Logistic::rand( Real const& mu, Real const& scale)
197{
198#ifdef _OPENMP
199//#pragma omp critical
200#endif
201GetRNGstate(); Real s = Rf_rlogis(mu, scale); PutRNGstate(); return s;
202}
203
204inline Real Logistic::pdf( Real const& x, Real const& mu, Real const& scale)
205{ return Rf_dlogis(x, mu, scale, false);}
206inline Real Logistic::lpdf( Real const& x, Real const& mu, Real const& scale)
207{ return Rf_dlogis(x, mu, scale, true);}
208inline Real Logistic::cdf( Real const& t, Real const& mu, Real const& scale)
209{ return Rf_plogis(t, mu, scale, true, false);}
210inline Real Logistic::icdf( Real const& p, Real const& mu, Real const& scale)
211{ return Rf_qlogis(p, mu, scale, true, false);}
212
213#endif
214
215} // namespace Law
216
217} // namespace STK
218
219#endif /*STK_LAW_LOGISTIC_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...
Logistic distribution law.
virtual Real pdf(Real const &x) const
Real rand() const
Generate a pseudo Logistic random variate.
Real scale_
The scale parameter.
IUnivLaw< Real > Base
Logistic(Real const &mu=0., Real const &scale=1.)
Constructor.
Real mu_
The mu parameter.
void setScale(Real const &scale)
Real const & scale() const
Real const & mu() const
virtual Real icdf(Real const &p) const
Compute the inverse cumulative distribution function at p of the standard logistic distribution.
virtual ~Logistic()
Destructor.
void setMu(Real const &mu)
virtual Real cdf(Real const &t) const
Compute the cumulative distribution function at t of the standard logistic distribution.
virtual Real lpdf(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.