Skip to content

Commit

Permalink
fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Jul 30, 2024
1 parent 3ec6a49 commit e21511e
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 374 deletions.
399 changes: 250 additions & 149 deletions ostap/fitting/dataset.py

Large diffs are not rendered by default.

41 changes: 38 additions & 3 deletions ostap/stats/statvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
- data_moment - get the moment (with uncertainty)
- data_get_stat - get the momentt-based statistics
- data_central_moment - get the central moment (with uncertainty)
- data_mean - get the mean (with uncertainty)
- data_nEff - get the effective number of entries
- data_sum - get the (weigted) sum
- data_mean - get the mean (with uncertainty)
- data_rms - get the RMS (with uncertainty)
- data_variance - get the variance (with uncertainty)
- data_dispersion - get the dispersion (with uncertainty)
- data_rms - get the RMS (with uncertainty)
- data_skewness - get the skewness (with uncertainty)
- data_kurtosis - get the (excess) kurtosis (with uncertainty)
- data_quantile - get the quantile
Expand All @@ -38,6 +38,8 @@
- data_arithmetic_mean - get the (weighted) geometric mean
- data_power_mean - get the (weighted) power mean
- data_lehmer_mean - get the (weighted) Lehmer mean
- data_statistics - get the statistics for variables
- data_minmax - get the (min/max) for variables
"""
# =============================================================================
__version__ = "$Revision$"
Expand All @@ -51,6 +53,7 @@
'data_nEff' , ## get the effective number of entries
'data_sum' , ## get the (weigted) sum
'data_statistics' , ## get the statistics
'data_minmax' , ## get min/max values for variables
'data_covariance' , ## get the covariance
'data_covariances' , ## get the covariances
'data_statvector' , ## get the stat-vector
Expand Down Expand Up @@ -264,7 +267,7 @@ def data_statistics ( data , expressions , cuts = '' , *args ) :
with rootException() :
return StatVar.statVar ( data , var_lst[0] , cuts , *args )

## several variables are specofied
## several variables are specified
from ostap.core.core import strings
names = strings ( *var_lst )
results = StatVar.Statistics()
Expand All @@ -278,6 +281,33 @@ def data_statistics ( data , expressions , cuts = '' , *args ) :
for v,r in zip ( var_lst , results ) : result [ v ] = r
return result

# ==============================================================================
## Get the minmax from data
# @code
# data = ...
# result = data_minmax ( data , 'x+y' , 'pt>1' )
# results = data_minmax ( data , 'x;y;z' , 'pt>1' ) ## result is dictionary
# @encode
# @see Ostap::StatEntity
# @see Ostap::WStatEntity
# @see Ostap::StatVar::statVar
def data_minmax ( data , expressions , cuts = '' , *args ) :
"""Get min/max from data
>>> data = ...
>>> result = data_minmax ( data , 'x/y+z' , '0<qq' )
>>> results = data_minmax ( data , 'x/y;z' , '0<qq' ) ## result is dictionary
- see Ostap.Math.StatEntity
- see Ostap.Math.WStatEntity
- see Ostap.StatVar.statVar
"""
results = data_statistics ( data , expressions , cuts , *args )
if isinstance ( results , dictlike_types ) :
for k, r in loop_items ( results ) :
results [ k ] = r.min() , r.max()
else : results = results.min() , results.max()
##
return results


# ==============================================================================
## Get the covarince from dataxpressio
Expand Down Expand Up @@ -1110,6 +1140,8 @@ def data_decorate ( klass ) :
if hasattr ( klass , 'statCov' ) : klass.orig_statCov = klass.statCov
if hasattr ( klass , 'statCovs' ) : klass.orig_statCovs = klass.statCovs
if hasattr ( klass , 'statVct' ) : klass.orig_statVct = klass.statVct
if hasattr ( klass , 'var_minmax' ) : klass.orig_var_minmax = klass.var_minmax
if hasattr ( klass , 'var_range' ) : klass.orig_var_range = klass.var_range

klass.statVar = data_statistics
klass.statVars = data_statistics
Expand All @@ -1119,6 +1151,9 @@ def data_decorate ( klass ) :
klass.statCovs = data_covariances
klass.statVct = data_statvector

klass.var_minmax = data_minmax
klass.var_range = data_range

if hasattr ( klass , 'the_moment' ) : klass.orig_the_moment = klass.the_moment
if hasattr ( klass , 'the_mean' ) : klass.orig_the_mean = klass.the_mean
if hasattr ( klass , 'the_rms' ) : klass.orig_the_rms = klass.the_rms
Expand Down
4 changes: 2 additions & 2 deletions ostap/tools/tests/test_tools_reweight2.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def prepare_data ( ) :
plots = [
WeightingPlot ( 'x' , 'weight' , 'x-reweight' , hxdata , hmcx ) ,
WeightingPlot ( 'y' , 'weight' , 'y-reweight' , hydata , hmcy ) ,
WeightingPlot ( 'y:x' , 'weight' , '2D-reweight' , hdata , hmc ) ,
WeightingPlot ( 'x:y' , 'weight' , '2D-reweight' , hdata , hmc ) ,
]

# ============================================================================
Expand Down Expand Up @@ -371,7 +371,7 @@ def prepare_data ( ) :
## 3) make MC-histograms
mcds .project ( hmcx , 'x' , 'weight' )
mcds .project ( hmcy , 'y' , 'weight' )
mcds .project ( hmc , 'y:x' , 'weight' )
mcds .project ( hmc , 'x:y' , 'weight' )

## 3.1) compare control and signal samples
vct_i = mcds.statVct ( 'x,y' , 'weight' )
Expand Down
8 changes: 4 additions & 4 deletions ostap/tools/tests/test_tools_reweight3.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ def prepare_data ( ) :
## Configuration of reweighting plots
# =============================================================================
plots = [
WeightingPlot ( 'z:y:x' , 'weight' , '3D-reweight' , h3d_data , mc_3d ) ,
WeightingPlot ( 'z:x' , 'weight' , 'XZ-reweight' , hxz_data , mc_xz ) ,
WeightingPlot ( 'z:y' , 'weight' , 'YZ-reweight' , hyz_data , mc_yz ) ,
WeightingPlot ( 'y:x' , 'weight' , 'XY-reweight' , hxy_data , mc_xy ) ,
WeightingPlot ( 'x:y:z' , 'weight' , '3D-reweight' , h3d_data , mc_3d ) ,
WeightingPlot ( 'x:z' , 'weight' , 'XZ-reweight' , hxz_data , mc_xz ) ,
WeightingPlot ( 'y:z' , 'weight' , 'YZ-reweight' , hyz_data , mc_yz ) ,
WeightingPlot ( 'z:y' , 'weight' , 'XY-reweight' , hxy_data , mc_xy ) ,
WeightingPlot ( 'x' , 'weight' , 'x-reweight' , hx_data , mc_x ) ,
WeightingPlot ( 'z' , 'weight' , 'z-reweight' , hz_data , mc_z ) ,
WeightingPlot ( 'y' , 'weight' , 'y-reweight' , hy_data , mc_y ) ,
Expand Down
Loading

0 comments on commit e21511e

Please sign in to comment.