Skip to content

Commit

Permalink
1. add generalized Beta' distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Nov 5, 2024
1 parent 9fcbd1f commit 1f7ae62
Show file tree
Hide file tree
Showing 9 changed files with 640 additions and 21 deletions.
3 changes: 2 additions & 1 deletion ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## New features

1. add `RooDataSet` -> `TTree` transformation

1. add generalized Beta' distribution

## Backward incompatible

## Bug fixes
Expand Down
90 changes: 88 additions & 2 deletions ostap/fitting/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# @author Vanya BELYAEV [email protected]
# @date 2011-07-25
# =============================================================================
"""A set of various smooth shapes and PDFs
""" A set of various smooth shapes and PDFs
- GammaDist_pdf : Gamma-distributuon in shape/scale parameterization
- GenGammaDist_pdf : Generalized Gamma-distribution
Expand All @@ -15,6 +15,7 @@
- Log10GammaDist_pdf : Gamma-distributuon in shape/scale parameterization
- LogGamma_pdf : Log-Gamma distribution
- BetaPrime_pdf : Beta-prime distribution
- GenBetaPrime_pdf : generalized Beta-prime distribution
- Landau_pdf : Landau distribution
- Argus_pdf : ARGUS distribution
- GenArgus_pdf : Generalized ARGUS distribution
Expand Down Expand Up @@ -45,6 +46,7 @@
'Log10GammaDist_pdf' , ## Gamma-distributuon in shape/scale parameterization
'LogGamma_pdf' , ## Log-Gamma distribution
'BetaPrime_pdf' , ## Beta-prime distribution
'GenBetaPrime_pdf' , ## generalized Beta-prime distribution
'Landau_pdf' , ## Landau distribution
'Argus_pdf' , ## ARGUS distribution
'GenArgus_pdf' , ## Generalized ARGUS distribution
Expand All @@ -58,7 +60,7 @@
'Hagedorn_pdf' , ## Hagedorn PDF
'Tsallis2_pdf' , ## 2D Tsallis PDF
'GenPareto_pdf' , ## Generalised Pareto distribution
'ExGenPareto_pdf' , ## Exponentiatd Generalised Pareto distribution
'ExGenPareto_pdf' , ## Exponentiated Generalised Pareto distribution
'Benini_pdf' , ## Benini distribution
'GEV_pdf' , ## Generalised Extreme Value distribution
'MPERT_pdf' , ## Modified PERT distribution
Expand Down Expand Up @@ -693,6 +695,90 @@ def delta ( self , value ) :
self.set_value ( self.__delta , value )

models.append ( BetaPrime_pdf )

# =============================================================================
## @class GenBetaPrime_pdf
# Generalized beta'-distribution
# http://en.wikipedia.org/wiki/Beta_prime_distribution
# @author Vanya BELYAEV [email protected]
# @date 2013-05-11
# @see Ostap::Models::GenBetaPrime
# @see Ostap::Math::GenBetaPrime
# @see Ostap::Models::BetaPrime
# @see Ostap::Math::BetaPrime
class GenBetaPrime_pdf(BetaPrime_pdf) :
"""Beta-prime disribution
- http://en.wikipedia.org/wiki/Beta_prime_distribution
"""
## constructor
def __init__ ( self ,
name , ## the name
xvar , ## the variable
alpha = None , ## alpha-parameter
beta = None , ## beta-parameter
p = 1 , ## p-parameter, p>0
q = 1 , ## q-parameter, q>0
scale = 1 , ## scale-parameter
delta = 0 ) : ## shift-parameter

## inialize the base
BetaPrime_pdf.__init__ ( self ,
name ,
alpha = alpha ,
beta = beta ,
scale = scale ,
delta = delta )

self.__p = self.make_var ( p ,
'p_%s' % name ,
'p_{#beta#prime}(%s)' % name ,
None , 1 , 1.e-3 , 1000 )
self.__q = self.make_var ( q ,
'q_%s' % name ,
'q_{#beta#prime}(%s)' % name ,
None , 1 , 1.e-3 , 1000 )

self.pdf = Ostap.Models.GenBetaPrime (
self.roo_name ( 'genbetap_' ) ,
'gen-Beta-prime %s' % self.name ,
self.x ,
self.alpha ,
self.beta ,
self.p ,
self.q ,
self.scale ,
self.delta )

## save the configuration:
self.config = {
'name' : self.name ,
'xvar' : self.xvar ,
'alpha' : self.alpha ,
'beta' : self.beta ,
'p' : self.p ,
'q' : self.q ,
'scale' : self.scale ,
'delta' : self.delta ,
}

@property
def p ( self ) :
"""`p'-parameter of gen-Beta' distribution (p>0)"""
return self.__p
@p.setter
def p ( self , value ) :
self.set_value ( self.__p , value )

@property
def q ( self ) :
"""`q'-parameter of gen-Beta' distribution (q>0)"""
return self.__p
@p.setter
def q ( self , value ) :
self.set_value ( self.__q , value )

models.append ( GenBetaPrime_pdf )

# =============================================================================
## @class Landau_pdf
# http://en.wikipedia.org/wiki/Landau_distribution
Expand Down
17 changes: 17 additions & 0 deletions ostap/fitting/rooreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,23 @@ def _rbetap_reduce_ ( pdf ):

Ostap.Models.BetaPrime.__reduce__ = _rbetap_reduce_

# =============================================================================
## reduce GenBetaPrime
def _rgenbetap_reduce_ ( pdf ):
""" Reduce GenBetaPrime"""
return root_store_factory , ( type ( pdf ) ,
pdf.name ,
pdf.title ,
pdf.x () ,
pdf.alpha () ,
pdf.beta () ,
pdf.p () ,
pdf.q () ,
pdf.scale () ,
pdf.shift () )

Ostap.Models.GenBetaPrime.__reduce__ = _rgenbetap_reduce_

# =============================================================================
## reduce Landau
def _rlandau_reduce_ ( pdf ):
Expand Down
4 changes: 4 additions & 0 deletions ostap/math/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ def _tf3_getattr_ ( self , attr ) :
Ostap.Math.Log10GammaDist ,
Ostap.Math.LogGamma ,
Ostap.Math.BetaPrime ,
Ostap.Math.GenBetaPrime ,
Ostap.Math.Landau ,
Ostap.Math.JohnsonSU ,
Ostap.Math.Atlas ,
Expand Down Expand Up @@ -1574,6 +1575,7 @@ def sp_maximum_1D_ ( pdf , xmin , xmax , x0 , *args ) :
Ostap.Models.Log10GammaDist ,
Ostap.Models.LogGamma ,
Ostap.Models.BetaPrime ,
Ostap.Models.GenBetaPrime ,
Ostap.Models.Landau ,
Ostap.Models.SinhAsinh ,
Ostap.Models.JohnsonSU ,
Expand Down Expand Up @@ -2489,6 +2491,7 @@ def _g3d_random_ ( g3d , N , xmin , xmax , ymin , ymax , zmin , zmax ) :
Ostap.Math.Log10GammaDist ,
Ostap.Math.LogGamma ,
Ostap.Math.BetaPrime ,
Ostap.Math.GenBetaPrime ,
Ostap.Math.Landau ,
Ostap.Math.JohnsonSU ,
Ostap.Math.Atlas ,
Expand Down Expand Up @@ -2627,6 +2630,7 @@ def _g3d_random_ ( g3d , N , xmin , xmax , ymin , ymax , zmin , zmax ) :
## Ostap.Models.Log10GammaDist ,
## Ostap.Models.LogGamma ,
## Ostap.Models.BetaPrime ,
## Ostap.Models.GenBetaPrime ,
## Ostap.Models.Landau ,
## Ostap.Models.SinhAsinh ,
## Ostap.Models.JohnsonSU ,
Expand Down
11 changes: 11 additions & 0 deletions ostap/math/more_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ def _ombprim_reduce_ ( s ) :

Ostap.Math.BetaPrime. __reduce__ = _ombprim_reduce_

# =============================================================================
## Reduce Ostap::Math::GenBetaPrime
# @see Ostap::Math::GenBetaPrime
def _omgenbprim_reduce_ ( s ) :
"""Reduce `Ostap.Math.GenBetaPrime`
- see `Ostap.Math.GenBetaPrime`
"""
return root_factory , ( type ( s ) , s.alpha () , s.beta() , s.p () , s.q() , s.scale() , s.shift () )

Ostap.Math.GenBetaPrime. __reduce__ = _omgenbprim_reduce_

# =============================================================================
## Reduce Ostap::Math::Landau
# @see Ostap::Math::Landau
Expand Down
104 changes: 97 additions & 7 deletions source/include/Ostap/Models.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,8 @@ namespace Ostap
* @param shift shift-parameter
*/
BetaPrime
( const double alpha = 3 ,
const double beta = 3 ,
( const double alpha = 1 ,
const double beta = 5 ,
const double scale = 1 ,
const double shift = 0 ) ;
/// destructor
Expand Down Expand Up @@ -1058,17 +1058,107 @@ namespace Ostap
// ======================================================================
private:
// ======================================================================
double m_alpha ;
double m_beta ;
double m_scale ;
double m_shift ;
double m_alpha { 1 } ;
double m_beta { 5 } ;
double m_scale { 1 } ;
double m_shift { 0 } ;
// ======================================================================
private:
// ======================================================================
/// auxillary intermediate parameter
double m_aux { 1 } ; // auxillary intermediate parameter
// ======================================================================
} ;
// ========================================================================
/** @class GenBetaPrime
* Generalized BetaPrime distribution
* http://en.wikipedia.org/wiki/Beta_prime_distribution
* @author Vanya BELYAEV [email protected]
* @date 2013-05-11
*/
class GenBetaPrime
{
public:
// ======================================================================
/** constructor with all parameters
* @param alpha \f$\alpha\f$-parameter
* @param beta \f$\beta\f$-parameter
* @param scale scale-parameter
* @param shift shift-parameter
*/
GenBetaPrime
( const double alpha = 1 ,
const double beta = 5 ,
const double p = 1 ,
const double q = 1 ,
const double scale = 1 ,
const double shift = 0 ) ;
/// destructor
~GenBetaPrime () ;
// ======================================================================
public:
// ======================================================================
/// evaluate beta'-distributions
double pdf ( const double x ) const ;
/// evaluate beta'-distributions
double operator() ( const double x ) const { return pdf ( x ) ; }
// ======================================================================
public: // direct getters
// ======================================================================
double alpha () const { return m_alpha ; }
double beta () const { return m_beta ; }
double p () const { return m_p ; }
double q () const { return m_q ; }
double scale () const { return m_scale ; }
double shift () const { return m_shift ; }
// ======================================================================
public: // general properties
// ======================================================================
double mean () const ;
double mode () const ;
// ======================================================================
public: // direct setters
// ======================================================================
bool setAlpha ( const double value ) ;
bool setBeta ( const double value ) ;
bool setP ( const double value ) ;
bool setQ ( const double value ) ;
bool setScale ( const double value ) ;
bool setShift ( const double value ) ;
// ======================================================================
public: // integrals
// ======================================================================
double integral () const ;
double cdf ( const double x ) const ;
double integral
( const double low ,
const double high ) const ;
// ======================================================================
public:
// ======================================================================
// get the tag
std::size_t tag () const ;
// ======================================================================
private:
// ======================================================================
double m_alpha { 1 } ;
double m_beta { 5 } ;
double m_p { 1 } ;
double m_q { 1 } ;
double m_scale { 1 } ;
double m_shift { 0 } ;
// ======================================================================
private:
// ======================================================================
/// auxillary intermediate parameter
double m_aux ; // auxillary intermediate parameter
double m_aux { 1 } ; // auxillary intermediate parameter
/// integration workspace
Ostap::Math::WorkSpace m_workspace {} ; // integration workspace
// ======================================================================
} ;



// ========================================================================
/** @class Landau
* http://en.wikipedia.org/wiki/Landau_distribution
Expand Down
Loading

0 comments on commit 1f7ae62

Please sign in to comment.