STK++ 0.9.13
STK_Law_Weibull.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: Weibull probability distribution.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_WEIBULL_H
36#define STK_LAW_WEIBULL_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
60class Weibull: public IUnivLaw<Real>
61{
62 public:
67 inline Weibull( Real const& k = 1., Real const& lambda = 1.)
68 : Base(_T("Weibull")), k_(k), lambda_(lambda)
69 {}
71 inline virtual ~Weibull() {}
73 inline Real const& k() const { return k_;}
75 inline Real const& lambda() const { return lambda_;}
77 inline void setK( Real const& k)
78 {
79 if (k<=0) STKDOMAIN_ERROR_1ARG(Weibull::setShape,k,shape must be > 0);
80 k_ = k;
81 }
83 inline void setLambda( Real const& lambda)
84 {
85 if (lambda<=0) STKDOMAIN_ERROR_1ARG(Weibull::setScale,lambda,scale must be > 0);
87 }
89 virtual Real rand() const;
93 virtual Real pdf(Real const& x) const;
97 virtual Real lpdf(Real const& x) const;
103 virtual Real cdf(Real const& t) const;
109 virtual Real icdf(Real const& p) const;
113 static Real rand( Real const& k, Real const& lambda);
118 static Real pdf(Real const& x, Real const& k, Real const& lambda);
123 static Real lpdf(Real const& x, Real const& k, Real const& lambda);
128 static Real cdf(Real const& t, Real const& k, Real const& lambda);
136 static Real icdf(Real const& p, Real const& k, Real const& lambda);
137
138#ifdef IS_RTKPP_LIB
140 virtual Real lcdf( Real const& t) const;
142 virtual Real cdfc( Real const& t) const;
144 virtual Real lcdfc( Real const& t) const;
145#endif
146
147 protected:
152};
153
154#ifdef IS_RTKPP_LIB
155
156inline Real Weibull::rand() const
157{
158#ifdef _OPENMP
159//#pragma omp critical
160#endif
161GetRNGstate(); Real s = Rf_rweibull(k_, lambda_); PutRNGstate(); return s;
162}
163
164inline Real Weibull::pdf(Real const& x) const { return Rf_dweibull(x, k_, lambda_, false);}
165inline Real Weibull::lpdf(Real const& x) const { return Rf_dweibull(x, k_, lambda_, true);}
166inline Real Weibull::cdf(Real const& t) const { return Rf_pweibull(t, k_, lambda_, true, false);}
167inline Real Weibull::lcdf(Real const& t) const { return Rf_pweibull(t, k_, lambda_, true, true);}
168inline Real Weibull::cdfc(Real const& t) const { return Rf_pweibull(t, k_, lambda_, false, false);}
169inline Real Weibull::lcdfc(Real const& t) const { return Rf_pweibull(t, k_, lambda_, false, true);}
170inline Real Weibull::icdf(Real const& p) const { return Rf_qweibull(p, k_, lambda_, true, false);}
171
172inline Real Weibull::rand( Real const& k, Real const& lambda)
173{
174#ifdef _OPENMP
175//#pragma omp critical
176#endif
177GetRNGstate(); Real s = Rf_rweibull(k, lambda); PutRNGstate(); return s;
178}
179
180inline Real Weibull::pdf(Real const& x, Real const& k, Real const& lambda)
181{ return Rf_dweibull(x, k, lambda, false);}
182inline Real Weibull::lpdf(Real const& x, Real const& k, Real const& lambda)
183{ return Rf_dweibull(x, k, lambda, true);}
184inline Real Weibull::cdf(Real const& t, Real const& k, Real const& lambda)
185{ return Rf_pweibull(t, k, lambda, true, false);}
186inline Real Weibull::icdf( Real const& p, Real const& k, Real const& lambda)
187{ return Rf_qweibull(p, k, lambda, true, false);}
188
189#endif
190
191} // namespace Law
192
193} // namespace STK
194
195#endif /*STK_LAWWEIBULL_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...
Weibull distribution law.
virtual ~Weibull()
destructor
IUnivLaw< Real > Base
Real const & k() const
Real lambda_
The scale parameter.
virtual Real pdf(Real const &x) const
Weibull(Real const &k=1., Real const &lambda=1.)
Default constructor.
virtual Real lpdf(Real const &x) const
Real const & lambda() const
void setLambda(Real const &lambda)
void setK(Real const &k)
Real k_
The shape parameter.
virtual Real rand() const
virtual Real icdf(Real const &p) const
The quantile (inverse cumulative distribution) function for the Weibull distribution is .
virtual Real cdf(Real const &t) const
The cumulative distribution function for the Weibull distribution is .
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.