Skip to content

Commit

Permalink
fix ?
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Aug 7, 2024
1 parent 8e342ec commit 6af7393
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 32 deletions.
34 changes: 16 additions & 18 deletions ostap/fitting/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,6 @@ def _rda_slice_ ( dataset , variables , cuts = '' , transpose = False , cut_rang

names = strings ( names )


tab = Ostap.StatVar.Table ()
col = Ostap.StatVar.Column ()

Expand All @@ -2671,7 +2670,7 @@ def _rda_slice_ ( dataset , variables , cuts = '' , transpose = False , cut_rang
*args )
nc = len ( col )
assert ( dataset.isWeighted() and nc == n ) or ( 0 == nc and not dataset.isWeighted() ), \
'slide: invalid size of ``weights'' column! %s/%s/%s' % ( n , nc , dataset.isWeighted() )
"slice: invalid size of `weights' column! %s/%s/%s" % ( n , nc , dataset.isWeighted() )

if 0 == n :
return () , ()
Expand Down Expand Up @@ -2938,7 +2937,6 @@ def ds_equal ( ds1 , ds2 ) :
logger.debug ("compare datasets: unbinned vs binned")
return False


## both weighted or non-weighted?
w1 = ds1.isWeighted ()
w2 = ds2.isWeighted ()
Expand Down Expand Up @@ -3004,7 +3002,7 @@ def ds_equal ( ds1 , ds2 ) :
return True

# ============================================================================
## Are two datastes non-equal by content?
## Are two datasets non-equal by content?
# @code
# ds1 = ...
# ds2 = ...
Expand Down Expand Up @@ -3072,12 +3070,9 @@ def _rad_rows_ ( dataset , variables = [] , cuts = '' , cutrange = '' , first =

first, last = evt_range ( len ( dataset ) , first , last )

if isinstance ( variables , string_types ) :
variables = split_string ( variables , var_separators , strip = True , respect_groups = True )
vars = []
for v in variables :
vars += split_string ( v , var_separators , strip = True , respect_groups = True )
vars = strings ( vars )
varlst, cuts, _ = vars_and_cuts ( variables , cuts )

vars = strings ( varlst )

formulas = []
varlist = dataset.varlist ()
Expand All @@ -3088,31 +3083,34 @@ def _rad_rows_ ( dataset , variables = [] , cuts = '' , cutrange = '' , first =
fcuts = None
if cuts : fcuts = make_formula ( cuts , cuts , varlist )

weighted = dataset.isWeighted()

weighted = dataset.isWeighted ()
store_errors = weighted and daatset.store_errors ()
store_asym_errors = weighted and daatset.store_asym_errors ()
simple_weight = weighted and ( not srore_errors ) and ( not store_asym_errors )
## loop over dataset
for event in range ( first , last ) :

ww = None
if weighted : vars, ww = dataset [ event ]
else : vars = dataset [ event ]

vars = dataset.get ( event )
if not vars : break

if cutrange and not vars.allInRange ( cutrange ) : continue

wc = fcuts.getVal() if fcuts else 1.0

if not wc : continue

wd = dataset.weight() if weighted else 1.0
wd = ww if weighted and not ( ww is None ) else 1.0

w = wc * wd
if not w : continue
if simple_weight and not w : continue

weight = w if weighted else None

result = tuple ( tuple ( float(f) for f in formulas ) )
result = tuple ( tuple ( float ( f ) for f in formulas ) )
yield get_result ( result ) , weight


del fcuts
del formulas

Expand Down
31 changes: 25 additions & 6 deletions ostap/math/tests/test_math_valerrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def test_asymerr () :
assert ae1_ == ae3 , ' %s != %s ' % ( ae1_ , ae3 )
assert ae2_ == ae3 , ' %s != %s ' % ( ae2_ , ae3 )

logger.info ( 'Scale /1 : %s %s %s' % ( ae1/1 , ae2/1 , ae3/1 ) )
logger.info ( 'Scale *1 : %s %s %s' % ( ae1*1 , ae2*1 , ae3*1 ) )
logger.info ( 'Scale /2 : %s %s %s' % ( ae1/2 , ae2/2 , ae3/2 ) )
logger.info ( 'Scale *2 : %s %s %s' % ( ae1*2 , ae2*2 , ae3*2 ) )
logger.info ( 'Scale 2* : %s %s %s' % ( 2*ae1 , 2*ae2 , 2*ae3 ) )

# =============================================================================
## test asymmetric errors:
Expand All @@ -59,9 +64,9 @@ def test_valasymerr () :
logger = getLogger( 'test_valasymerr')
logger.info ( 'Test ValWithErrors' )

ae1 = VAE ( 1.0 , -0.5 , 1.0 )
ae2 = VAE ( VE ( 1.0 , 0.0 ) , -0.5 , 1.0 )
ae3 = VAE ( VE ( 1.0 , 0.0 ) , AE ( -0.5 , 1.0 ) )
ae1 = VAE ( 10.0 , -0.5 , 1.0 )
ae2 = VAE ( VE ( 10.0 , 0.0 ) , -0.5 , 1.0 )
ae3 = VAE ( VE ( 10.0 , 0.0 ) , AE ( -0.5 , 1.0 ) )

logger.info ( '%s %s %s' % ( ae1 , ae2 , ae3 ) )

Expand All @@ -76,12 +81,19 @@ def test_valasymerr () :
assert ae1_ == ae2 , ' %s != %s ' % ( ae1_ , ae2 )
assert ae1_ == ae3 , ' %s != %s ' % ( ae1_ , ae3 )
assert ae2_ == ae3 , ' %s != %s ' % ( ae2_ , ae3 )

logger.info ( 'Scale /1 : %s %s %s' % ( ae1/1 , ae2/1 , ae3/1 ) )
logger.info ( 'Scale *! : %s %s %s' % ( ae1*1 , ae2*1 , ae3*1 ) )
logger.info ( 'Scale /2 : %s %s %s' % ( ae1/2 , ae2/2 , ae3/2 ) )
logger.info ( 'Scale *2 : %s %s %s' % ( ae1*2 , ae2*2 , ae3*2 ) )
logger.info ( 'Scale 2* : %s %s %s' % ( 2*ae1 , 2*ae2 , 2*ae3 ) )

## conversion to VE without bias
ve1 = ae1.asVE ( bias = False )
ve2 = ae2.asVE ( bias = False )
ve3 = ae3.asVE ( bias = False )

logger.info ( '%s %s %s' % ( ae1 , ae2 , ae3 ) )
logger.info ( 'asVE ( bias = False ) : %s %s %s' % ( ve1.toString ( '( %+-.3f +/- %-.3f )' ) ,
ve2.toString ( '( %+-.3f +/- %-.3f )' ) ,
ve3.toString ( '( %+-.3f +/- %-.3f )' ) ) )
Expand All @@ -102,9 +114,9 @@ def test_valmulterr () :
logger = getLogger( 'test_valmulterr')
logger.info ( 'Test ValWithMultiErrors' )

me1 = VME ( 1.0 , 0.5 , 0.5 , -0.6 , 1.0 , 0.7 , -0.3 )
me2 = VME ( 1.0 , AE( 0.5 , 0.5 ) , AE ( -0.6 , 1.0 ) , AE ( 0.7 , -0.3 ) )
me3 = VME ( VE ( 1 , 0.5 **2 ) , AE ( -0.6 , 1.0 ) , AE ( 0.7 , -0.3 ) )
me1 = VME ( 10.0 , 0.5 , 0.5 , -0.6 , 1.0 , 0.7 , -0.3 )
me2 = VME ( 10.0 , AE( 0.5 , 0.5 ) , AE ( -0.6 , 1.0 ) , AE ( 0.7 , -0.3 ) )
me3 = VME ( VE ( 10 , 0.5 **2 ) , AE ( -0.6 , 1.0 ) , AE ( 0.7 , -0.3 ) )

ae1 = me1.asVAE()

Expand All @@ -122,10 +134,17 @@ def test_valmulterr () :
assert me1_ == me3 , ' %s != %s ' % ( me1_ , me3 )
assert me2_ == me3 , ' %s != %s ' % ( me2_ , me3 )

logger.info ( 'Scale /1 : %s %s %s' % ( me1/1 , me2/1 , me3/1 ) )
logger.info ( 'Scale *1 : %s %s %s' % ( me1*1 , me2*1 , me3*1 ) )
logger.info ( 'Scale /2 : %s %s %s' % ( me1/2 , me2/2 , me3/2 ) )
logger.info ( 'Scale *2 : %s %s %s' % ( me1*2 , me2*2 , me3*2 ) )
logger.info ( 'Scale 2* : %s %s %s' % ( 2*me1 , 2*me2 , 2*me3 ) )

ae1 = me1.asVAE()
ae2 = me2.asVAE()
ae3 = me3.asVAE()

logger.info ( '%s %s %s' % ( me1 , me2 , me3 ) )
logger.info ( 'as VAE : %s %s %s' % ( ae1 , ae2 , ae3 ) )

## conversion to VE without bias
Expand Down
Loading

0 comments on commit 6af7393

Please sign in to comment.