STK++ 0.9.13
STK_Law_Cauchy.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 * Purpose: Cauchy probability distribution.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_CAUCHY_H
36#define STK_LAW_CAUCHY_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
65class Cauchy: public IUnivLaw<Real>
66{
67 public:
72 inline Cauchy( Real const& mu=0, Real const& scale=1)
73 : Base(String(_T("Cauchy")))
74 , mu_(mu)
75 , scale_(scale)
76 {
77 // check parameters
80 }
81
83 inline virtual ~Cauchy() {}
85 inline Real const& mu() const { return mu_;}
87 inline Real const& scale() const { return scale_;}
89 inline void setMu( Real const& mu) { mu_ = mu;}
91 inline void setScale( Real const& scale)
92 {
94 scale_ = scale;
95 }
98 virtual Real rand() const;
102 virtual Real pdf( Real const& x) const;
106 virtual Real lpdf( Real const& x) const;
118 virtual Real cdf( Real const& t) const;
127 virtual Real icdf( Real const& p) const;
128
134 static Real rand( Real const& mu, Real const& scale);
139 static Real pdf( Real const& x, Real const& mu, Real const& scale);
145 static Real lpdf( Real const& x, Real const& mu, Real const& scale);
158 static Real cdf( Real const& t, Real const& mu, Real const& scale);
168 static Real icdf( Real const& p, Real const& mu, Real const& scale);
169
170#ifdef IS_RTKPP_LIB
172 virtual Real lcdf( Real const& t) const;
174 virtual Real cdfc( Real const& t) const;
176 virtual Real lcdfc( Real const& t) const;
177#endif
178
179 protected:
184};
185
186#ifdef IS_RTKPP_LIB
187
188/* Generate a pseudo Cauchy random variate. */
189inline Real Cauchy::rand() const
190{
191#ifdef _OPENMP
192//#pragma omp critical
193#endif
194GetRNGstate(); Real s = Rf_rcauchy(mu_, scale_); PutRNGstate(); return s;
195}
196
197inline Real Cauchy::pdf( Real const& x) const { return Rf_dcauchy(x,mu_, scale_, false);}
198inline Real Cauchy::lpdf( Real const& x) const { return Rf_dcauchy(x,mu_, scale_, true);}
199inline Real Cauchy::cdf( Real const& t) const { return Rf_pcauchy(t, mu_, scale_, true, false);}
200inline Real Cauchy::lcdf( Real const& t) const { return Rf_pcauchy(t, mu_, scale_, true, true);}
201inline Real Cauchy::cdfc( Real const& t) const { return Rf_pcauchy(t, mu_, scale_, false, false);}
202inline Real Cauchy::lcdfc( Real const& t) const { return Rf_pcauchy(t, mu_, scale_, false, true);}
203inline Real Cauchy::icdf( Real const& p) const { return Rf_qcauchy(p , mu_, scale_, true, false);}
204
205// static
206inline Real Cauchy::rand( Real const& mu, Real const& scale)
207{
208#ifdef _OPENMP
209//#pragma omp critical
210#endif
211GetRNGstate(); Real s = Rf_rcauchy(mu, scale); PutRNGstate(); return s;
212}
213
214inline Real Cauchy::pdf(Real const& x, Real const& mu, Real const& scale)
215{ return Rf_dcauchy(x,mu, scale, false);}
216inline Real Cauchy::lpdf(Real const& x, Real const& mu, Real const& scale)
217{ return Rf_dcauchy(x,mu, scale, true);}
218inline Real Cauchy::cdf(Real const& t, Real const& mu, Real const& scale)
219{ return Rf_pcauchy(t, mu, scale, true, false);}
220inline Real Cauchy::icdf(Real const& p, Real const& mu, Real const& scale)
221{ return Rf_qcauchy(p , mu, scale, true, false);}
222
223#endif
224
225} // namespace Law
226
227} // namespace STK
228
229#endif /*STK_LAWCAUCHY_H*/
In this file we define the interface base class IUnivLaw for all probabilities laws.
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:129
#define STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:147
#define _T(x)
Let x unmodified.
Cauchy distribution law.
IUnivLaw< Real > Base
virtual Real pdf(Real const &x) const
Cauchy(Real const &mu=0, Real const &scale=1)
Default constructor.
void setMu(Real const &mu)
Real scale_
The scale parameter.
virtual Real rand() const
Generate a pseudo Cauchy random variate.
virtual ~Cauchy()
Destructor.
Real const & scale() const
virtual Real lpdf(Real const &x) const
virtual Real cdf(Real const &t) const
The cumulative distribution function of the Cauchy distribution at t is.
Real const & mu() const
Real mu_
The mu parameter.
void setScale(Real const &scale)
virtual Real icdf(Real const &p) const
The inverse cumulative distribution function at p is.
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...
std::basic_string< Char > String
STK fundamental type of a String.
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.