Skip to content

Commit

Permalink
fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Oct 13, 2024
1 parent 6b19d32 commit d04b9f6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .aux/test_with_lcg
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ CMTCONFIG=$2
source /cvmfs/sft.cern.ch/lcg/views/${LCG}/${CMTCONFIG}/setup.sh
source build/INSTALL/thisostap.sh
cd build
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j2 --output-on-failure --test-output-size-failed 5000000
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j2 -R gof --output-on-failure --test-output-size-failed 5000000

4 changes: 1 addition & 3 deletions ostap/stats/gof_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def __call__ ( self , N , silent = True ) :
# =============================================================================
jl = None
# =============================================================================
if ( 3 , 0 ) <= python_info : # ===============================================
if False and ( 3 , 0 ) <= python_info : # ===============================================
# =========================================================================
try : # ===================================================================
# =====================================================================
Expand Down Expand Up @@ -301,8 +301,6 @@ def joblib_run ( self , NN , silent = True ) :
# =====================================================================
jl = None

# =============================================================================
jl = None
# =============================================================================
if not jl : # =================================================================
# =========================================================================
Expand Down
55 changes: 25 additions & 30 deletions ostap/stats/tests/test_stats_gof1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
gauss = M.Gauss_pdf ( 'G' , xvar = xvar , mean = 5 , sigma = 1 )
model = M.Fit1D ( signal = gauss , background = 'flat' )

ND = 200
ND = 100

# =============================================================================
## data_g: pure gaussian
Expand All @@ -37,12 +37,11 @@
data_g = gauss.generate ( ND , sample = True )
# =============================================================================
## data_b: 95% gaussian + 4% flat background
model.S = 0.95 * ND
model.B = 0.05 * ND
model.S = 0.90 * ND
model.B = 0.10 * ND
data_b = model.generate ( ND , sample = True )


fitconf = { 'draw' : True , 'nbins' : 50 , 'refit' : 5 , 'quiet' : True }
fitconf = { 'draw' : True , 'nbins' : 25 , 'refit' : 5 , 'quiet' : True }

keep = set()
# ==============================================================================
Expand All @@ -58,14 +57,14 @@ def run_PPD ( pdf , data, result , logger ) :
# =========================================================================
# - Point to Point Dissimilarity test with Gaussian distance using different "sigma"
rows = [ ( 'PPD/sigma' , 't-value' , 'x[..]', 'p-value [%]' , '#sigma') ]
Ns = 5
Ns = 3
logger.info ( 'Run Point-to-Point Dissimilarity GoF-test for %d different values of sigma' % Ns )
for sigma in vrange ( 0.01 , 2.0 , Ns ) :
for sigma in vrange ( 0.1 , 1.0 , Ns ) :

ppd = GnD.PPD ( nToys = 1000 , sigma = sigma )
ppd = GnD.PPD ( nToys = 200 , sigma = sigma )
pdf.load_params ( result , silent = True )
tvalue = ppd ( pdf , data )
tvalue, pvalue = ppd.pvalue ( pdf , data )
tvalue = ppd ( pdf , data )
tvalue, pvalue = ppd.pvalue ( pdf , data )
nsigma = significance ( pvalue )

tv , texpo = pretty_float ( tvalue )
Expand Down Expand Up @@ -94,16 +93,14 @@ def run_DNN ( pdf , data, result , logger ) :

rows = [ ( 't-value' , 'x[..]', 'p-value [%]' , '#sigma' ) ]

dnn = GnD.DNN ( nToys = 1000 , histo = 100 )
dnn = GnD.DNN ( nToys = 200 , histo = 50 )

pdf.load_params ( result , silent = True )

tvalue = dnn ( pdf , data )

tvalue, pvalue = dnn.pvalue ( pdf , data )
tvalue = dnn ( pdf , data )
tvalue, pvalue = dnn.pvalue ( pdf , data )
nsigma = significance ( pvalue )


tv , texpo = pretty_float ( tvalue )
pvalue *= 100
pvalue = '%4.1f +/- %.1f' % ( pvalue.value() , pvalue.error() )
Expand All @@ -126,7 +123,7 @@ def run_USTAT ( pdf , data, result , logger ) :

rows = [ ( 't-value' , 'x[..]', 'p-value [%]' , '#sigma' ) ]

ustat = USTAT ( nToys = 1000 , histo = 100 )
ustat = USTAT ( nToys = 200 , histo = 100 )

pdf.load_params ( result , silent = True )

Expand Down Expand Up @@ -168,7 +165,7 @@ def test_good_fit_1 ( ) :
logger.info ( 'Goodness-of-fit:\n%s' % gof )

gauss.load_params ( r , silent = True )
got = G1D.GoF1DToys ( gauss , data_g )
got = G1D.GoF1DToys ( gauss , data_g , 200 )
logger.info ( 'Goodness-of-fit with %d toys:\n%s' % ( got.nToys , got ) )

del gof
Expand All @@ -180,7 +177,7 @@ def test_good_fit_1 ( ) :
udist1 = run_DNN ( gauss , data_g , r , logger )
if udist1 :
keep.add ( udist1 )
with use_canvas ( 'test_good_fit_1: DNN' , wait = 5 ) :
with use_canvas ( 'test_good_fit_1: DNN' , wait = 1 ) :
udist1.draw()

udist2 = run_USTAT ( gauss , data_g , r , logger )
Expand Down Expand Up @@ -209,20 +206,20 @@ def test_good_fit_2 ( ) :
logger.info ( 'Goodness-of-fit:\n%s' % gof )

model.load_params ( r , silent = True )
got = G1D.GoF1DToys ( model , data_g , 500 )
got = G1D.GoF1DToys ( model , data_g , 200 )
logger.info ( 'Goodness-of-fit with %d toys:\n%s' % ( got.nToys , got ) )

## Try to use multidimensional methods
run_PPD ( model , data_g , r , logger )
udist1 = run_DNN ( model , data_g , r , logger )
if udist1 :
keep.add ( udist1 )
with use_canvas ( 'test_good_fit_2: DNN' , wait = 5 ) :
with use_canvas ( 'test_good_fit_2: DNN' , wait = 1 ) :
udist1.draw()
udist2 = run_USTAT ( model , data_g , r , logger )
if udist2 :
keep.add ( udist2 )
with use_canvas ( 'test_good_fit_2: USTAT' , wait = 5 ) :
with use_canvas ( 'test_good_fit_2: USTAT' , wait = 1 ) :
udist2.draw()


Expand All @@ -244,23 +241,22 @@ def test_good_fit_3 ( ) :
logger.info ( 'Goodness-of-fit:\n%s' % gof )

model.load_params ( r , silent = True )
got = G1D.GoF1DToys ( model , data_b , 500 )
got = G1D.GoF1DToys ( model , data_b , 200 )
logger.info ( 'Goodness-of-fit with %d toys:\n%s' % ( got.nToys , got ) )

## Try to use multidimensional methods
run_PPD ( model , data_b , r , logger )
udist1 = run_DNN ( model , data_b , r , logger )
if udist1 :
keep.add ( udist1 )
with use_canvas ( 'test_good_fit_3: DNN' , wait = 5 ) :
with use_canvas ( 'test_good_fit_3: DNN' , wait = 1 ) :
udist1.draw()
udist2 = run_USTAT ( model , data_b , r , logger )
if udist2 :
keep.add ( udist2 )
with use_canvas ( 'test_good_fit_3: USTAT' , wait = 5 ) :
with use_canvas ( 'test_good_fit_3: USTAT' , wait = 1 ) :
udist2.draw()


# =============================================================================
def test_bad_fit_1 ( ) :
""" Make a test for presumably bad fit: fit Gauss to Gauss+Bkg
Expand All @@ -282,7 +278,7 @@ def test_bad_fit_1 ( ) :
gof.draw()

gauss.load_params ( r , silent = True )
got = G1D.GoF1DToys ( gauss , data_b , 5000 )
got = G1D.GoF1DToys ( gauss , data_b , 200 )
got.run ( 1000 )
logger.info ( 'Goodness-of-fit with %d toys:\n%s' % ( got.nToys , got ) )

Expand All @@ -298,24 +294,23 @@ def test_bad_fit_1 ( ) :
dzk = got.draw('ZK')
with use_canvas ( 'test_bad_fit_1: GoF/ZA' , wait = 1 ) :
dza = got.draw('ZA')
with use_canvas ( 'test_bad_fit_1: GoF/ZC' , wait = 3 ) :
with use_canvas ( 'test_bad_fit_1: GoF/ZC' , wait = 1 ) :
dzc = got.draw('ZC')

## Try to use multidimensional methods
run_PPD ( gauss , data_b , r , logger )
udist1 = run_DNN ( gauss , data_b , r , logger )
if udist1 :
keep.add ( udist1 )
with use_canvas ( 'test_bad_fit_1: DNN' , wait = 5 ) :
with use_canvas ( 'test_bad_fit_1: DNN' , wait = 1 ) :
udist1.draw()
udist2 = run_USTAT ( gauss , data_b , r , logger )
if udist2 :
keep.add ( udist2 )
with use_canvas ( 'test_bad_fit_3: USTAT' , wait = 5 ) :
with use_canvas ( 'test_bad_fit_3: USTAT' , wait = 1 ) :
udist2.draw()



# ===============================================================================
if '__main__' == __name__ :

Expand Down
18 changes: 4 additions & 14 deletions ostap/stats/tests/test_stats_gofnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,16 @@ def test_PPD () :

sigma = ''
for conf in ( { 'psi' : 'linear' } ,
{ 'psi' : 'squared' } ,
{ 'psi' : 'logarithm' } ,
{ 'psi' : 'coulomb' } ,
{ 'psi' : 'cityblock' } ,
{ 'psi' : 'seuclidean' } ,
{ 'psi' : 'cosine' } ,
{ 'psi' : 'chebyshev' } ,
{ 'psi' : 'canberra' } ,
{ 'psi' : 'braycurtis' } ,
{ 'psi' : 'mahalanobis' } ,
{ 'psi' : 'gaussian' , 'sigma' : 2.00 } ,
{ 'psi' : 'gaussian' , 'sigma' : 1.00 } ,
{ 'psi' : 'gaussian' , 'sigma' : 0.50 } ,
{ 'psi' : 'gaussian' , 'sigma' : 0.20 } ,
{ 'psi' : 'gaussian' , 'sigma' : 0.10 } ,
{ 'psi' : 'gaussian' , 'sigma' : 0.05 } ,
{ 'psi' : 'gaussian' , 'sigma' : 0.02 } ,
{ 'psi' : 'gaussian' , 'sigma' : 0.01 } ) :

ppd = GnD.PPD ( nToys= 1000 , **conf )
ppd = GnD.PPD ( nToys = 200 , **conf )

## presumably good fit
with timing ( "Good fit PPD distance %s %s" % ( conf [ 'psi' ] , conf.get('sigma','') ) , logger = logger ) :
Expand Down Expand Up @@ -137,12 +128,11 @@ def test_DNN () :
logger.warning ('No numpy/scipy/s4u/cdist: skip the test!')
return


## 't/good', 'x[..]' ,
## 't/bad' , 'x[..]' ,
rows = [ ( 'p-value/good[%]' , 'p-value/bad[%]' , '#sigma/good' , '#sigma/bad') ]

dnn = GnD.DNN ( nToys = 1000 , histo = 50 )
dnn = GnD.DNN ( nToys = 200 , histo = 50 )

## presumably good fit
with timing ( "Good fit DNN" , logger = logger ) :
Expand Down Expand Up @@ -187,7 +177,7 @@ def test_USTAT () :
from ostap.stats.ustat import USTAT
rows = [ ( 'p-value/good[%]' , 'p-value/bad[%]' , '#sigma/good' , '#sigma/bad') ]

ust = USTAT ( nToys = 1000 , histo = 50 )
ust = USTAT ( nToys = 200 , histo = 50 )

## presumably good fit
with timing ( "Good fit USTAT" , logger = logger ) :
Expand Down

0 comments on commit d04b9f6

Please sign in to comment.