Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:20

0001 // @(#)root/mathcore:$Id$
0002 // Authors: L. Moneta, A. Zsenei   08/2005
0003 
0004 
0005 // Authors: Andras Zsenei & Lorenzo Moneta   08/2005
0006 
0007 
0008 /**********************************************************************
0009  *                                                                    *
0010  * Copyright (c) 2005 , LCG ROOT MathLib Team                         *
0011  *                                                                    *
0012  *                                                                    *
0013  **********************************************************************/
0014 
0015 
0016 #ifndef ROOT_Math_QuantFuncMathCore
0017 #define ROOT_Math_QuantFuncMathCore
0018 
0019 
0020 namespace ROOT {
0021 namespace Math {
0022 
0023 
0024 
0025   /** @defgroup QuantFunc Quantile Functions
0026    *  @ingroup StatFunc
0027    *
0028    *  Inverse functions of the cumulative distribution functions
0029    *  and the inverse of the complement of the cumulative distribution functions
0030    *  for various distributions.
0031    *  The functions with the extension <em>_quantile</em> calculate the
0032    *  inverse of the <em>_cdf</em> function, the
0033    *  lower tail integral of the probability density function
0034    *  \f$D^{-1}(z)\f$ where
0035    *
0036    *  \f[ D(x) = \int_{-\infty}^{x} p(x') dx' \f]
0037    *
0038    *  while those with the <em>_quantile_c</em> extension calculate the
0039    *  inverse of the <em>_cdf_c</em> functions, the upper tail integral of the probability
0040    *  density function \f$D^{-1}(z) \f$ where
0041    *
0042    *  \f[ D(x) = \int_{x}^{+\infty} p(x') dx' \f]
0043    *
0044    *  These functions are defined in the header file <em>Math/ProbFunc.h</em> or in the global one
0045    *  including all statistical functions <em>Math/DistFunc.h</em>
0046    *
0047    *
0048    * <strong>NOTE:</strong> In the old releases (< 5.14) the <em>_quantile</em> functions were called
0049    * <em>_quant_inv</em> and the <em>_quantile_c</em> functions were called
0050    * <em>_prob_inv</em>.
0051    * These names are currently kept for backward compatibility, but
0052    * their usage is deprecated.
0053    *
0054    */
0055 
0056    /** @name Quantile Functions from MathCore
0057    * The implementation is provided in MathCore and for the majority of the function comes from
0058    * <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0059 
0060    */
0061 
0062   //@{
0063 
0064 
0065 
0066   /**
0067 
0068      Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0069      function of the upper tail of the beta distribution
0070      (#beta_cdf_c).
0071      It is implemented using the function incbi from <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0072 
0073 
0074      @ingroup QuantFunc
0075 
0076   */
0077    double beta_quantile(double x, double a, double b);
0078 
0079    /**
0080 
0081       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0082       function of the lower tail of the beta distribution
0083       (#beta_cdf).
0084       It is implemented using
0085       the function incbi from <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0086 
0087       @ingroup QuantFunc
0088 
0089    */
0090    double beta_quantile_c(double x, double a, double b);
0091 
0092 
0093 
0094    /**
0095 
0096       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0097       function of the upper tail of the Cauchy distribution (#cauchy_cdf_c)
0098       which is also called Lorentzian distribution. For
0099       detailed description see
0100       <A HREF="http://mathworld.wolfram.com/CauchyDistribution.html">
0101       Mathworld</A>.
0102 
0103       @ingroup QuantFunc
0104 
0105    */
0106 
0107    double cauchy_quantile_c(double z, double b);
0108 
0109 
0110 
0111 
0112    /**
0113 
0114       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0115       function of the lower tail of the Cauchy distribution (#cauchy_cdf)
0116       which is also called Breit-Wigner or Lorentzian distribution. For
0117       detailed description see
0118       <A HREF="http://mathworld.wolfram.com/CauchyDistribution.html">
0119       Mathworld</A>. The implementation used is that of
0120       <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_19.html#SEC294">GSL</A>.
0121 
0122       @ingroup QuantFunc
0123 
0124    */
0125 
0126    double cauchy_quantile(double z, double b);
0127 
0128 
0129 
0130 
0131    /**
0132 
0133       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0134       function of the upper tail of the Breit-Wigner distribution (#breitwigner_cdf_c)
0135       which is similar to the Cauchy distribution. For
0136       detailed description see
0137       <A HREF="http://mathworld.wolfram.com/CauchyDistribution.html">
0138       Mathworld</A>. It is evaluated using the same implementation of
0139       #cauchy_quantile_c.
0140 
0141       @ingroup QuantFunc
0142 
0143    */
0144 
0145    inline double breitwigner_quantile_c(double z, double gamma) {
0146       return cauchy_quantile_c(z, gamma/2.0);
0147    }
0148 
0149 
0150 
0151 
0152    /**
0153 
0154       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0155       function of the lower tail of the Breit_Wigner distribution (#breitwigner_cdf)
0156       which is similar to the Cauchy distribution. For
0157       detailed description see
0158       <A HREF="http://mathworld.wolfram.com/CauchyDistribution.html">
0159       Mathworld</A>. It is evaluated using the same implementation of
0160       #cauchy_quantile.
0161 
0162 
0163       @ingroup QuantFunc
0164 
0165    */
0166 
0167    inline double breitwigner_quantile(double z, double gamma) {
0168       return cauchy_quantile(z, gamma/2.0);
0169    }
0170 
0171 
0172 
0173 
0174 
0175 
0176    /**
0177 
0178       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0179       function of the upper tail of the \f$\chi^2\f$ distribution
0180       with \f$r\f$ degrees of freedom (#chisquared_cdf_c). For detailed description see
0181       <A HREF="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">
0182       Mathworld</A>. It is implemented using the inverse of the incomplete complement gamma function, using
0183       the function igami from <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0184 
0185       @ingroup QuantFunc
0186 
0187    */
0188 
0189    double chisquared_quantile_c(double z, double r);
0190 
0191 
0192 
0193    /**
0194 
0195       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0196       function of the lower tail of the \f$\chi^2\f$ distribution
0197       with \f$r\f$ degrees of freedom (#chisquared_cdf). For detailed description see
0198       <A HREF="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">
0199       Mathworld</A>.
0200       It is implemented using  chisquared_quantile_c, therefore is not very precise for small z.
0201       It is recommended to use the MathMore function (ROOT::MathMore::chisquared_quantile )implemented using GSL
0202 
0203       @ingroup QuantFunc
0204 
0205    */
0206 
0207    double chisquared_quantile(double z, double r);
0208 
0209 
0210 
0211    /**
0212 
0213       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0214       function of the upper tail of the exponential distribution
0215       (#exponential_cdf_c). For detailed description see
0216       <A HREF="http://mathworld.wolfram.com/ExponentialDistribution.html">
0217       Mathworld</A>.
0218 
0219       @ingroup QuantFunc
0220 
0221    */
0222 
0223    double exponential_quantile_c(double z, double lambda);
0224 
0225 
0226 
0227 
0228    /**
0229 
0230       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0231       function of the lower tail of the exponential distribution
0232       (#exponential_cdf). For detailed description see
0233       <A HREF="http://mathworld.wolfram.com/ExponentialDistribution.html">
0234       Mathworld</A>.
0235 
0236       @ingroup QuantFunc
0237 
0238    */
0239 
0240    double exponential_quantile(double z, double lambda);
0241 
0242 
0243 
0244    /**
0245 
0246       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0247       function of the lower tail of the f distribution
0248       (#fdistribution_cdf). For detailed description see
0249       <A HREF="http://mathworld.wolfram.com/F-Distribution.html">
0250       Mathworld</A>.
0251       It is implemented using the inverse of the incomplete beta function,
0252       function incbi from <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0253 
0254       @ingroup QuantFunc
0255 
0256    */
0257    double fdistribution_quantile(double z, double n, double m);
0258 
0259    /**
0260 
0261       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0262       function of the upper tail of the f distribution
0263       (#fdistribution_cdf_c). For detailed description see
0264       <A HREF="http://mathworld.wolfram.com/F-Distribution.html">
0265       Mathworld</A>.
0266       It is implemented using the inverse of the incomplete beta function,
0267       function incbi from <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0268 
0269       @ingroup QuantFunc
0270    */
0271 
0272    double fdistribution_quantile_c(double z, double n, double m);
0273 
0274 
0275    /**
0276 
0277       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0278       function of the upper tail of the gamma distribution
0279       (#gamma_cdf_c). For detailed description see
0280       <A HREF="http://mathworld.wolfram.com/GammaDistribution.html">
0281       Mathworld</A>. The implementation used is that of
0282       <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_19.html#SEC300">GSL</A>.
0283       It is implemented using the function igami taken
0284       from <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0285 
0286       @ingroup QuantFunc
0287 
0288    */
0289 
0290    double gamma_quantile_c(double z, double alpha, double theta);
0291 
0292 
0293 
0294 
0295    /**
0296 
0297       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0298       function of the lower tail of the gamma distribution
0299       (#gamma_cdf). For detailed description see
0300       <A HREF="http://mathworld.wolfram.com/GammaDistribution.html">
0301       Mathworld</A>.
0302       It is implemented using  chisquared_quantile_c, therefore is not very precise for small z.
0303       For this special cases it is recommended to use the MathMore function ROOT::MathMore::gamma_quantile
0304       implemented using GSL
0305 
0306 
0307       @ingroup QuantFunc
0308 
0309    */
0310 
0311    double gamma_quantile(double z, double alpha, double theta);
0312 
0313 
0314 
0315    /**
0316 
0317       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0318       function of the upper tail of the normal (Gaussian) distribution
0319       (#gaussian_cdf_c). For detailed description see
0320       <A HREF="http://mathworld.wolfram.com/NormalDistribution.html">
0321       Mathworld</A>. It can also be evaluated using #normal_quantile_c which will
0322       call the same implementation.
0323 
0324       @ingroup QuantFunc
0325 
0326    */
0327 
0328    double gaussian_quantile_c(double z, double sigma);
0329 
0330 
0331 
0332 
0333    /**
0334 
0335       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0336       function of the lower tail of the normal (Gaussian) distribution
0337       (#gaussian_cdf). For detailed description see
0338       <A HREF="http://mathworld.wolfram.com/NormalDistribution.html">
0339       Mathworld</A>. It can also be evaluated using #normal_quantile which will
0340       call the same implementation.
0341       It is implemented using the function  ROOT::Math::Cephes::ndtri taken from
0342       <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0343 
0344       @ingroup QuantFunc
0345 
0346    */
0347 
0348    double gaussian_quantile(double z, double sigma);
0349 
0350 
0351 
0352 
0353    /**
0354 
0355       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0356       function of the upper tail of the lognormal distribution
0357       (#lognormal_cdf_c). For detailed description see
0358       <A HREF="http://mathworld.wolfram.com/LogNormalDistribution.html">
0359       Mathworld</A>. The implementation used is that of
0360       <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_19.html#SEC302">GSL</A>.
0361 
0362       @ingroup QuantFunc
0363 
0364    */
0365 
0366    double lognormal_quantile_c(double x, double m, double s);
0367 
0368 
0369 
0370 
0371    /**
0372 
0373       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0374       function of the lower tail of the lognormal distribution
0375       (#lognormal_cdf). For detailed description see
0376       <A HREF="http://mathworld.wolfram.com/LogNormalDistribution.html">
0377       Mathworld</A>. The implementation used is that of
0378       <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_19.html#SEC302">GSL</A>.
0379 
0380       @ingroup QuantFunc
0381 
0382    */
0383 
0384    double lognormal_quantile(double x, double m, double s);
0385 
0386 
0387 
0388 
0389    /**
0390 
0391       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0392       function of the upper tail of the normal (Gaussian) distribution
0393       (#normal_cdf_c). For detailed description see
0394       <A HREF="http://mathworld.wolfram.com/NormalDistribution.html">
0395       Mathworld</A>. It can also be evaluated using #gaussian_quantile_c which will
0396       call the same implementation.
0397       It is implemented using the function  ROOT::Math::Cephes::ndtri taken from
0398       <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0399 
0400       @ingroup QuantFunc
0401 
0402    */
0403 
0404    double normal_quantile_c(double z, double sigma);
0405    /// alternative name for same function
0406    inline double gaussian_quantile_c(double z, double sigma) {
0407       return normal_quantile_c(z,sigma);
0408    }
0409 
0410 
0411 
0412 
0413    /**
0414 
0415       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0416       function of the lower tail of the normal (Gaussian) distribution
0417       (#normal_cdf). For detailed description see
0418       <A HREF="http://mathworld.wolfram.com/NormalDistribution.html">
0419       Mathworld</A>. It can also be evaluated using #gaussian_quantile which will
0420       call the same implementation.
0421       It is implemented using the function  ROOT::Math::Cephes::ndtri taken from
0422       <A HREF="http://www.netlib.org/cephes">Cephes</A>.
0423 
0424 
0425       @ingroup QuantFunc
0426 
0427    */
0428 
0429    double normal_quantile(double z, double sigma);
0430    /// alternative name for same function
0431    inline double gaussian_quantile(double z, double sigma) {
0432       return normal_quantile(z,sigma);
0433    }
0434 
0435 
0436 
0437 #ifdef LATER // t quantiles are still in MathMore
0438 
0439    /**
0440 
0441       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0442       function of the upper tail of Student's t-distribution
0443       (#tdistribution_cdf_c). For detailed description see
0444       <A HREF="http://mathworld.wolfram.com/Studentst-Distribution.html">
0445       Mathworld</A>. The implementation used is that of
0446       <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_19.html#SEC305">GSL</A>.
0447 
0448       @ingroup QuantFunc
0449 
0450    */
0451 
0452    double tdistribution_quantile_c(double z, double r);
0453 
0454 
0455 
0456 
0457    /**
0458 
0459       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0460       function of the lower tail of Student's t-distribution
0461       (#tdistribution_cdf). For detailed description see
0462       <A HREF="http://mathworld.wolfram.com/Studentst-Distribution.html">
0463       Mathworld</A>. The implementation used is that of
0464       <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_19.html#SEC305">GSL</A>.
0465 
0466       @ingroup QuantFunc
0467 
0468    */
0469 
0470    double tdistribution_quantile(double z, double r);
0471 
0472 #endif
0473 
0474 
0475    /**
0476 
0477       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0478       function of the upper tail of the uniform (flat) distribution
0479       (#uniform_cdf_c). For detailed description see
0480       <A HREF="http://mathworld.wolfram.com/UniformDistribution.html">
0481       Mathworld</A>.
0482 
0483       @ingroup QuantFunc
0484 
0485    */
0486 
0487    double uniform_quantile_c(double z, double a, double b);
0488 
0489 
0490 
0491 
0492    /**
0493 
0494       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0495       function of the lower tail of the uniform (flat) distribution
0496       (#uniform_cdf). For detailed description see
0497       <A HREF="http://mathworld.wolfram.com/UniformDistribution.html">
0498       Mathworld</A>.
0499 
0500       @ingroup QuantFunc
0501 
0502    */
0503 
0504    double uniform_quantile(double z, double a, double b);
0505 
0506 
0507 
0508 
0509    /**
0510 
0511       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0512       function of the lower tail of the Landau distribution
0513       (#landau_cdf).
0514 
0515    For detailed description see
0516    K.S. K&ouml;lbig and B. Schorr, A program package for the Landau distribution,
0517    <A HREF="http://dx.doi.org/10.1016/0010-4655(84)90085-7">Computer Phys. Comm. 31 (1984) 97-111</A>
0518    <A HREF="http://dx.doi.org/10.1016/j.cpc.2008.03.002">[Erratum-ibid. 178 (2008) 972]</A>.
0519    The same algorithms as in
0520    <A HREF="https://cern-tex.web.cern.ch/cern-tex/shortwrupsdir/g110/top.html">
0521    CERNLIB</A> (RANLAN) is used.
0522 
0523    @param z The argument \f$z\f$
0524    @param xi The width parameter \f$\xi\f$
0525 
0526       @ingroup QuantFunc
0527 
0528    */
0529 
0530    double landau_quantile(double z, double xi = 1);
0531 
0532 
0533    /**
0534 
0535       Inverse (\f$D^{-1}(z)\f$) of the cumulative distribution
0536       function of the upper tail of the landau distribution
0537       (#landau_cdf_c).
0538       Implemented using #landau_quantile
0539 
0540    @param z The argument \f$z\f$
0541    @param xi The width parameter \f$\xi\f$
0542 
0543       @ingroup QuantFunc
0544 
0545    */
0546 
0547    double landau_quantile_c(double z, double xi = 1);
0548 
0549 
0550 #ifdef HAVE_OLD_STAT_FUNC
0551 
0552    //@}
0553    /** @name Backward compatible functions */
0554 
0555 
0556    inline double breitwigner_prob_inv(double x, double gamma) {
0557       return  breitwigner_quantile_c(x,gamma);
0558    }
0559    inline double breitwigner_quant_inv(double x, double gamma) {
0560       return  breitwigner_quantile(x,gamma);
0561    }
0562 
0563    inline double cauchy_prob_inv(double x, double b) {
0564       return cauchy_quantile_c(x,b);
0565    }
0566    inline double cauchy_quant_inv(double x, double b) {
0567       return cauchy_quantile  (x,b);
0568    }
0569 
0570    inline double exponential_prob_inv(double x, double lambda) {
0571       return exponential_quantile_c(x, lambda );
0572    }
0573    inline double exponential_quant_inv(double x, double lambda) {
0574       return exponential_quantile  (x, lambda );
0575    }
0576 
0577    inline double gaussian_prob_inv(double x, double sigma) {
0578       return  gaussian_quantile_c( x, sigma );
0579    }
0580    inline double gaussian_quant_inv(double x, double sigma) {
0581       return  gaussian_quantile  ( x, sigma );
0582    }
0583 
0584    inline double lognormal_prob_inv(double x, double m, double s) {
0585       return lognormal_quantile_c( x, m, s );
0586    }
0587    inline double lognormal_quant_inv(double x, double m, double s) {
0588       return lognormal_quantile  ( x, m, s );
0589    }
0590 
0591    inline double normal_prob_inv(double x, double sigma) {
0592       return  normal_quantile_c( x, sigma );
0593    }
0594    inline double normal_quant_inv(double x, double sigma) {
0595       return  normal_quantile  ( x, sigma );
0596    }
0597 
0598    inline double uniform_prob_inv(double x, double a, double b) {
0599       return uniform_quantile_c( x, a, b );
0600    }
0601    inline double uniform_quant_inv(double x, double a, double b) {
0602       return uniform_quantile  ( x, a, b );
0603    }
0604 
0605    inline double chisquared_prob_inv(double x, double r) {
0606       return chisquared_quantile_c(x, r );
0607    }
0608 
0609    inline double gamma_prob_inv(double x, double alpha, double theta) {
0610       return gamma_quantile_c (x, alpha, theta );
0611    }
0612 
0613 
0614 #endif
0615 
0616 
0617 } // namespace Math
0618 } // namespace ROOT
0619 
0620 
0621 
0622 #endif // ROOT_Math_QuantFuncMathCore