Skip to content

Commit

Permalink
format & re-enalbe the test with FrequentisCalculator
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Dec 4, 2024
1 parent 98e84bc commit c09aac9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
25 changes: 11 additions & 14 deletions ostap/fitting/roostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ def __del__ ( self ) :

@property
def cloned_dataset ( self ) :
"""'cloned_dataset' : get the CLONED dataset (actually used in calcualtor)"""
"""'cloned_dataset' : get the CLONED dataset (actually used in calculator)"""
return self.__cloned_dataset

# ==============================================================================================
Expand Down Expand Up @@ -1487,15 +1487,12 @@ def scan_with_progress ( self , *values ) :
2 <= values and \
isinstance ( values [ 1 ] , num_types ) and \
isinstance ( values [ 2 ] , num_types ) :
return self.scan_with_progress ( vrange ( values[1] , vales[2] , values[0] ) )
return self.scan_with_progress ( vrange ( values[1] , values [2] , values[0] ) )

elif 1 == len ( values ) and isinstance ( values [ 0 ] , sequence_types ) :

for v in progress_bar ( values [ 0 ] , description = 'Scan:' ) :
self.__inverter.RunOnePoint ( v )

else :

self.__inverter.RunOnePoint ( v )
else :
for v in progress_bar ( values , description = 'Scan:' ) :
self.__inverter.RunOnePoint ( v )

Expand Down Expand Up @@ -1553,7 +1550,7 @@ def plot ( self ) :
# =========================================================================
## Reset/clear current interval & plot
def reset ( self ) :
"""Reset/clear current interval & plot
""" Reset/clear current interval & plot
"""
if self.__interval : self.__interval = None
if self.__plot : self.__plot = None
Expand All @@ -1577,7 +1574,7 @@ def reset ( self ) :
# p.draw('a')
# @endcode
class BrasilBand(object) :
"""Helper class to create and keep the 'Brasil-band' plot
""" Helper class to create and keep the 'Brasil-band' plot
>>> bp = BrasilBand( sigmas = (1,2,3) ) ## draw 1,2&3-sigma bands
>>> for value in [ ... ] :
>>> ...
Expand Down Expand Up @@ -1621,7 +1618,7 @@ def __init__ ( self ,
# =========================================================================
## Add the point to the Brasil-plot
def fill ( self , x , observed , hti_result ) :
"""Add the point to the Brasil-plot
""" Add the point to the Brasil-plot
"""
expected = tuple ( hti_result.GetExpectedUpperLimit ( s ) for s in self.__nsigmas )
self.__data [ x ] = observed, expected
Expand Down Expand Up @@ -1740,7 +1737,7 @@ def legend ( self ) :
# ===========================================================================
## number of points in the graph
def __len__ ( self ) :
"""Number of points in the graph
""" Number of points in the graph
"""
return len ( self.__data )

Expand All @@ -1763,7 +1760,7 @@ def __len__ ( self ) :
# @endcode
# @thanks Dima Golubkov
class P0Plot(object) :
"""Helper class to create graphs(s) for p0-scan plot
""" Helper class to create graphs(s) for p0-scan plot
>>> plot = P0Plot()
>>> for ,,, :
... value = ...
Expand All @@ -1774,7 +1771,7 @@ class P0Plot(object) :
>>> plot.p0 .draw ( 'ac') ## plot p-values
>>> plot.p0_expected.draw ( 'c' ) ## plot expected p-values
>>> plot.sigmas .draw ( 'ac') ## plot #sigmas
- thanks to Dima Golubkov
- thanks to Dima Golubkov!
"""
def __init__ ( self ) :

Expand Down Expand Up @@ -1809,7 +1806,7 @@ def __init__ ( self ) :
# plot.fill ( value , calculator )
# @endcode
def fill ( self , value , *what ) :
"""Add the point to TGraph(s
""" Add the point to TGraph(s
- Full version
>>> plot = P0Plot()
Expand Down
4 changes: 0 additions & 4 deletions ostap/fitting/tests/test_fitting_roostats1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
else :
logger = getLogger ( __name__ )
# =============================================================================



# ============================================================================
## Test the confidence intervals for the width of low-statistic gaussian ssignal
#
# - Profile likelihood confidence interval
Expand Down
18 changes: 9 additions & 9 deletions ostap/fitting/tests/test_fitting_roostats3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@

graphs = []
# ============================================================================-
## Scan the positon of the peak and get the limit for each peak posiiton peak
## Scan the position of the peak and get the limit for each peak posiiton peak
# - resolution is known with some finite precision
# - efficiency is known with some finite precision
def test_scan_limit1 () :
"""Scan the positon of the peak and get the limit for each peak posiiton peak
"""Scan the position of the peak and get the limit for each peak posiiton peak
- resolution is known with some finite precision
- efficiency is known with some finite precision
"""
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_scan_limit1 () :

graphs.append ( bplot )
# ============================================================================-
## Scan the positon of the peak and get the limit for each peak posiiton peak
## Scan the position of the peak and get the limit for each peak posiiton peak
# - mass-dependent resolution is known with some finite precision
# - mass-dependent efficiency is known with some finite precision
def test_scan_limit2 () :
Expand Down Expand Up @@ -314,19 +314,19 @@ def test_scan_limit2 () :
bplot.plot .draw ( 'a' )
bplot.legend.draw ( )

title = '90% Upper limits'
title = '90% Upper limit'
table = T.table ( rows , title = title , prefix = '# ' , alignment = 'lr' )
logger.info ( '%s:\n%s' % ( title , table ) )

graphs.append ( bplot )

# ============================================================================-
## Scan the positon of the peak and get the p0
## Scan the position of the peak and get the p0
# - resolution is known with some finite precision
# - efficiency is known with some finite precision
# @thanks to Dima Golubkov
def test_scan_p0_1 () :
"""Scan the positon of the peak and get p0 for each peak position peak
""" Scan the position of the peak and get p0 for each peak position peak
- resolution is known with some finite precision
- efficiency is known with some finite precision
- thanks to Dima Golubkov
Expand Down Expand Up @@ -444,10 +444,10 @@ def test_scan_p0_1 () :

with rooSilent ( ) :

## test_scan_limit1 ()
## test_scan_limit2 ()
test_scan_limit1 ()
test_scan_limit2 ()

test_scan_p0_1 ()
## test_scan_p0_1 ()

# =============================================================================
## The END
Expand Down
13 changes: 6 additions & 7 deletions ostap/fitting/tests/test_fitting_roostats4.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
## Get the upper limit limit for small signal at fixed mass
# - Asymptotic Calculator is used
def test_limit_ac_1 () :
"""Get the upper limit at given point for small signal at fixed mass
""" Get the upper limit at given point for small signal at fixed mass
- Asymptotic Calculator is used
"""

Expand Down Expand Up @@ -278,7 +278,7 @@ def test_limit_ac_2 () :
## Get the upper limit limit for small signal at fixed mass
# - Frequentists Calculator is used
def test_limit_fc_1 () :
"""Get the upper limit at given point for small signal at fixed mass
""" Get the upper limit at given point for small signal at fixed mass
- Friquentists Calculator is used
"""

Expand All @@ -297,7 +297,7 @@ def test_limit_fc_1 () :
constraints = constraint , eff_constraint

logger.info ( 'Dataset is\n%s' % the_data.table ( prefix = '# ' ) )
rr , frame = the_model.fitTo ( the_data , nbins = 100 , constraints = constraints )
rr , frame = the_model.fitTo ( the_data , nbins = 100 , constraints = constraints , silent = True )
with use_canvas ( 'test_limit_ac_2:data' ) : the_model.draw ( the_data , nbins = 100 )
title = 'Results of the fit'
logger.info ( '%s\n%s' % ( title , rr.table ( title = title , prefix = '# ' ) ) )
Expand Down Expand Up @@ -335,14 +335,13 @@ def test_limit_fc_1 () :
model_sb ,
dataset = the_data ,
ntoys_null = 100 ,
ntoys_alt = 100 ,
)
ntoys_alt = 100 )

## create Hypo Test inverter
hti = HypoTestInverter ( fc , 0.90 , use_CLs = True , verbose = False )

## make a scan
hti .scan_with_progress ( vrange ( 1.e-3 , 0.5 , 25 ) ) ## scan it!
hti .scan_with_progress ( vrange ( 1.e-3 , 0.4 , 20 ) ) ## scan it!

## visualize the scan results
with use_canvas ( 'test_limit_fc_1: HypoTestInverter plot (frequentist)' , wait = 2 ) :
Expand All @@ -355,7 +354,7 @@ def test_limit_fc_1 () :

test_limit_ac_1 ()
test_limit_ac_2 ()
## test_limit_fc_1 ()
test_limit_fc_1 ()

# =============================================================================
## The END
Expand Down

0 comments on commit c09aac9

Please sign in to comment.