Skip to content

Commit

Permalink
serialize&compare counters
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Jul 31, 2024
1 parent 8ceaeca commit 1e98c42
Show file tree
Hide file tree
Showing 17 changed files with 944 additions and 325 deletions.
5 changes: 0 additions & 5 deletions ostap/fitting/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ def target_reset ( t ) :
logger.attention ("From ostap v1.10.1.9 variables are treted in natural order (no reverse!)")
_to_print -= 1

print ( 'VARIABLES/1', varlst, cuts )
nvars = len ( varlst )
assert ( 1 == dim and dim <= nvars ) or dim == nvars , \
'Mismatch between the target/histo dimension %d and input variables %s' % ( dim , varlst )
Expand Down Expand Up @@ -934,7 +933,6 @@ def target_reset ( t ) :
the_args = ( target , ) + varlst + tail
## very special case of projection several expressions into the same target
if 1 == dim and dim < nvars :
print ( 'DS_PROJECT/1' , dim , nvars, varlst , tail )
## very special case of projection several expressions into the same target
htmp = target_copy ( target ) ## prepare temporary object
for var in varlst :
Expand All @@ -947,16 +945,13 @@ def target_reset ( t ) :
target += htmp
del htmp
elif 1 == dim :
print ( 'DS_PROJECT/2' , dim , nvars, varlst , tail )
if progress : sc = Ostap.HistoProject.project ( dataset , progress_conf () , *the_args )
else : sc = Ostap.HistoProject.project ( dataset , *the_args )
if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project %s" % sc )
elif 2 == dim :
print ( 'DS_PROJECT/3' , dim , nvars, varlst , tail )
if progress : sc = Ostap.HistoProject.project2 ( dataset , progress_conf () , *the_args )
else : sc = Ostap.HistoProject.project2 ( dataset , *the_args )
if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project2 %s" % sc )
print ( 'DS_PROJECT/4' , dim , nvars, varlst , tail )
elif 3 == dim :
if progress : sc = Ostap.HistoProject.project3 ( dataset , progress_conf () , *the_args )
else : sc = Ostap.HistoProject.project3 ( dataset , *the_args )
Expand Down
3 changes: 1 addition & 2 deletions ostap/math/minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from scipy.optimize import minimize_scalar
scipy_OK = True
except ImportError :
from ostap.math.local_minimize import scalar_minimuze as minimize_scalar
from ostap.math.local_minimize import scalar_minimize as minimize_scalar
scipy_OK = False

if scipy_OK :
Expand Down Expand Up @@ -186,7 +186,6 @@ def sp_maximum_3D ( fun ,
'sp_maximum_2D' ,
'sp_maximum_3D' )


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

Expand Down
26 changes: 19 additions & 7 deletions ostap/math/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,13 @@ def _tf3_getattr_ ( self , attr ) :

raise AttributeError("Can't get attribute: %s" % attr )


from ostap.math.minimize import sp_minimum_1D, sp_maximum_1D
from ostap.math.rootfinder import sp_solve
try :
from ostap.math.minimize import sp_minimum_1D, sp_maximum_1D
from ostap.math.rootfinder import sp_solve
except ImportError :
sp_minimum_1D = None
sp_maximum_1D = None
sp_solve = None

# =============================================================================
## decorate 1D-models/functions
Expand Down Expand Up @@ -1365,7 +1369,12 @@ def _sp_print_ ( self , typ = 'BSpline' ) :
Ostap.Math.Spline2D = Ostap.Math.PositiveSpline2D
Ostap.Math.Spline2DSym = Ostap.Math.PositiveSpline2DSym

from ostap.math.minimize import sp_minimum_2D, sp_maximum_2D
try :
from ostap.math.minimize import sp_minimum_2D, sp_maximum_2D
except ImportError :
sp_minimum_2D = None
sp_maximum_2D = None


for model in ( Ostap.Math.BSpline2D ,
Ostap.Math.BSpline2DSym ,
Expand Down Expand Up @@ -1401,9 +1410,12 @@ def _sp_print_ ( self , typ = 'BSpline' ) :
if sp_minimum_2D and not hasattr ( model , 'minimum' ) : model.minimum = sp_minimum_2D
if sp_maximum_2D and not hasattr ( model , 'maximum' ) : model.maximum = sp_maximum_2D


from ostap.math.minimize import sp_minimum_3D, sp_maximum_3D

try :
from ostap.math.minimize import sp_minimum_3D, sp_maximum_3D
except ImportError :
sp_minimum_3D = None
sp_maximum_3D = None

# =============================================================================
## Decorate 3D models
# =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion ostap/math/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def root_factory ( klass , *params ) :
"""
return klass ( *params )


# =============================================================================
## Simple (basic) polynomials
# =============================================================================


# =============================================================================
## factory for deserialization of simple polynomians
# @see Ostap.Math.Chebyshev
Expand Down
56 changes: 52 additions & 4 deletions ostap/stats/counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
)
# =============================================================================
from ostap.math.ve import Ostap, VE
from ostap.math.base import isequal, isequalf
from ostap.core.ostap_types import dictlike_types, sequence_types
from ostap.math.base import isequal, isequalf, iszero
from ostap.core.ostap_types import dictlike_types, sequence_types
import ROOT, cppyy
# =============================================================================
_new_methods_ = []
Expand All @@ -51,7 +51,6 @@
_orig_mean = SE.mean
SE._orig_mean = _orig_mean


SE. sum = lambda s : VE ( s._orig_sum () , s.sum2 () )
SE. minmax = lambda s : ( s.min () , s.max () )
SE. mean = lambda s : VE ( s._orig_mean () , s.meanErr()**2 )
Expand Down Expand Up @@ -289,7 +288,56 @@ def counters_table ( counters , prefix = '' , title = '' ) :
counters_table
]



# ==============================================================================
## REDUCE
# ==============================================================================
from ostap.math.reduce import root_factory


# =============================================================================
## Reduce Ostap::StatEntity
def _se_reduce_ ( cnt ) :
"""Reduce `Ostap.StatEntity` object
"""
return root_factory , ( type ( cnt ) ,
cnt.n () ,
cnt.mu () ,
cnt.mu2 () ,
cnt.min () ,
cnt.max () )

# =============================================================================
## Reduce Ostap::WStatEntity
def _wse_reduce_ ( cnt ) :
"""Reduce `Ostap.WStatEntity` object
"""
return root_factory , ( type ( cnt ) ,
cnt.mu () ,
cnt.mu2 () ,
cnt.values () ,
cnt.weights () )
# =============================================================================
## Reduce Ostap::NStatEntity
def _nse_reduce_ ( cnt ) :
"""Reduce `Ostap.NStatEntity` object
"""
return root_factory , ( type ( cnt ) ,
cnt.N () ,
cnt.cnt1 () ,
cnt.cnt2 () )

SE .__reduce__ = _se_reduce_
WSE.__reduce__ = _wse_reduce_
NSE.__reduce__ = _nse_reduce_

_new_methods_ += [
SE .__reduce__ ,
WSE.__reduce__ ,
NSE.__reduce__ ,
]

# ==============================================================================
_new_methods_ = tuple ( _new_methods_ )

# =============================================================================
Expand Down
Loading

0 comments on commit 1e98c42

Please sign in to comment.