STK++ 0.9.13
STK_Law_Beta.cpp
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 * created on: 23 janv. 2013
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
36#ifndef IS_RTKPP_LIB
37#include "../include/STK_Law_Beta.h"
38#include "../include/STK_Law_Gamma.h"
40#endif
41
42//
43namespace STK
44{
45namespace Law
46{
47
48#ifndef IS_RTKPP_LIB
49
50/* Generate a pseudo Beta random variate. */
52{
54 return g1/(g1+Law::Gamma::rand(beta_, 1.));
55}
56
57/*
58 * Give the value of the pdf at x.
59 */
60Real Beta::pdf( Real const& x) const
61{
62 // trivial cases
63 if (!Arithmetic<Real>::isFinite(x)||(x<0.)||(x>1)) return 0.0;
64 // compute result
65 return 0.;
66}
67
68/*
69 * Give the value of the log-pdf at x.
70 */
71Real Beta::lpdf( Real const& x) const
72{
73 // check NA value
74 if (isNA(x)) return Arithmetic<Real>::NA();
75 // check parameter
78 // compute result
79 return 0.;
80}
81
82/*
83 * The cumulative distribution function at t.
84 */
85Real Beta::cdf( Real const& t) const
86{
87 // check NA value
88 if (isNA(t)) return Arithmetic<Real>::NA();
89 // compute result
90 return (Arithmetic<Real>::isInfinite(t)) ? (t < 0.) ? 0.0 : 1.0
92}
93
94/*
95 * The inverse cumulative distribution function at p.
96 */
97Real Beta::icdf( Real const& p) const
98{
99 // check parameter
100 if ((p > 1.) || (p < 0.))
102 // trivial cases
103 if (p == 0.) return 0.;
104 if (p == 1.) return 1.;
105 // result
106 return 0.;
107}
108
109/* Generate a pseudo Beta random variate with the specified parameters.
110 * (static)
111 */
112Real Beta::rand( Real const& alpha, Real const& beta)
113{
115 return g1/(g1+Law::Gamma::rand(beta, 1.));
116}
117
118Real Beta::pdf(const Real& x, const Real& alpha, const Real& beta)
119{
120 // trivial cases
121 if (!Arithmetic<Real>::isFinite(x)||(x<0.)||(x>1)) return 0.0;
122 // compute result
123 return 0.;
124}
125
126Real Beta::lpdf(const Real& x, const Real& alpha, const Real& beta)
127{
128 // check NA value
129 if (isNA(x)) return Arithmetic<Real>::NA();
130 // check parameter
133 // compute result
134 return 0.;
135}
136
137Real Beta::cdf(const Real& t, const Real& alpha, const Real& beta)
138{
139 // check NA value
140 if (isNA(t)) return Arithmetic<Real>::NA();
141 // compute result
142 return (Arithmetic<Real>::isInfinite(t)) ? (t < 0.) ? 0.0 : 1.0
143 : Funct::betaRatio(alpha,beta,t, false);
144}
145
146Real Beta::icdf(const Real& p, const Real& alpha, const Real& beta)
147{
148 // check parameter
149 if ((p > 1.) || (p < 0.))
151 // trivial cases
152 if (p == 0.) return 0.;
153 if (p == 1.) return 1.;
154 // result
155 return 0.;
156}
157
158#endif /* !IS_RTKPP_LIB */
159
160} // namespace Law
161
162} // namespace STK
163
In this file we declare functions around the beta function ratio.
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
Real beta_
Second parameter.
virtual Real lpdf(Real const &x) const
Real beta() const
Real alpha() const
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 Real rand() const
virtual Real rand() const
generate a gamma random variate using the G.S algorithm of Ahrens and Dieter (1974) for 0<a_<1 and Ma...
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Real betaRatio(Real const &a, Real const &b, Real const &x, bool lower_tail=true)
Compute the incomplete beta function ratio Compute the beta ratio function.
bool isNA(Type const &x)
utility method allowing to know if a value is a NA (Not Available) value
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.
static Type NA()
Adding a Non Available (NA) special number.