STK++ 0.9.13
STK_Law_Beta.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: Beta probability distribution.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_BETA_H
36#define STK_LAW_BETA_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
64class Beta: public IUnivLaw<Real>
65{
66 public:
69 inline Beta( Real const& alpha = .5, Real const& beta = .5)
70 : Base(String(_T("Beta"))), alpha_(alpha), beta_(beta)
71 {
72 if ( !isFinite(alpha) || !isFinite(beta) || alpha <= 0.0 || beta <= 0.0)
73 STKDOMAIN_ERROR_2ARG("Beta::Beta",alpha,beta,"argument error");
74 }
76 inline virtual ~Beta() {}
78 inline Real alpha() const {return alpha_;}
80 inline Real beta() const { return beta_;}
82 inline void setAlpha(Real alpha) { alpha_ = alpha;}
84 inline void setBeta(Real beta) {beta_ =beta;}
85
95 virtual Real rand() const;
97 virtual Real pdf( Real const& x) const;
99 virtual Real lpdf( Real const& x) const;
101 virtual Real cdf( Real const& t) const;
103 virtual Real icdf( Real const& p) const;
104
106 static Real rand( Real const& alpha, Real const& beta);
108 static Real pdf( Real const& x, Real const& alpha, Real const& beta);
110 static Real lpdf( Real const& x, Real const& alpha, Real const& beta);
112 static Real cdf( Real const& t, Real const& alpha, Real const& beta);
114 static Real icdf( Real const& p, Real const& alpha, Real const& beta);
115
116#ifdef IS_RTKPP_LIB
118 virtual Real lcdf( Real const& t) const;
120 virtual Real cdfc( Real const& t) const;
122 virtual Real lcdfc( Real const& t) const;
123#endif
124
125 protected:
130};
131
132#ifdef IS_RTKPP_LIB
133inline Real Beta::rand() const
134{
135#ifdef _OPENMP
136//#pragma omp critical
137#endif
138 GetRNGstate(); Real s = Rf_rbeta(alpha_, beta_); PutRNGstate(); return s;
139}
140
141inline Real Beta::pdf( Real const& x) const { return Rf_dbeta(x,alpha_, beta_, false);}
142inline Real Beta::lpdf( Real const& x) const { return Rf_dbeta(x,alpha_, beta_, true);}
143inline Real Beta::cdf( Real const& t) const { return Rf_pbeta(t, alpha_, beta_, true, false);}
144inline Real Beta::lcdf( Real const& t) const { return Rf_pbeta(t, alpha_, beta_, true, true);}
145inline Real Beta::cdfc( Real const& t) const { return Rf_pbeta(t, alpha_, beta_, false, false);}
146inline Real Beta::lcdfc( Real const& t) const { return Rf_pbeta(t, alpha_, beta_, false, true);}
147inline Real Beta::icdf( Real const& p) const { return Rf_qbeta(p , alpha_, beta_, true, false);}
148
149inline Real Beta::rand( Real const& alpha, Real const& beta)
150{
151#ifdef _OPENMP
152//#pragma omp critical
153#endif
154 GetRNGstate(); Real s = Rf_rbeta(alpha, beta); PutRNGstate(); return s;
155}
156
157inline Real Beta::pdf(const Real& x, const Real& alpha, const Real& beta)
158{ return Rf_dbeta(x,alpha, beta, (int)false);}
159inline Real Beta::lpdf(const Real& x, const Real& alpha, const Real& beta)
160{ return Rf_dbeta(x,alpha, beta, (int)true);}
161inline Real Beta::cdf(const Real& t, const Real& alpha, const Real& beta)
162{ return Rf_pbeta(t, alpha, beta, (int)true, (int)false);}
163inline Real Beta::icdf(const Real& p, const Real& alpha, const Real& beta)
164{ return Rf_qbeta(p , alpha, beta, (int)true, (int)false);}
165
166#endif
167} // namespace Law
168
169} // namespace STK
170
171#endif /*STK_LAWBETA_H*/
In this file we define the interface base class IUnivLaw for all probabilities laws.
#define STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:147
#define _T(x)
Let x unmodified.
Beta distribution law.
IUnivLaw< Real > Base
Beta(Real const &alpha=.5, Real const &beta=.5)
default constructor.
void setBeta(Real beta)
set the beta value
Real beta_
Second parameter.
virtual Real lpdf(Real const &x) const
Real beta() const
Real alpha() const
void setAlpha(Real alpha)
set the alpha value
Real alpha_
First parameter.
virtual Real icdf(Real const &p) const
virtual Real cdf(Real const &t) const
virtual Real pdf(Real const &x) const
virtual ~Beta()
Dtor.
virtual Real rand() const
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...
bool isFinite(Type const &x)
utility method allowing to know if a value is a finite value
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.