Skip to content

Commit 2b90e92

Browse files
committed
fix&tweaks
1 parent f5201b4 commit 2b90e92

3 files changed

Lines changed: 37 additions & 26 deletions

File tree

‎ostap/tools/reweighters.py‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,14 @@ def __init__( self , * ,
244244
self.__norm_factor = numpy.float32( 1.0 )
245245
self.__mode = None
246246
self.__scale_factors = {}
247-
248247

249-
n_features = num_features ( targer )
248+
n_features = num_features ( target )
249+
n_rows = num_samples ( target ) + num_samples ( original )
250+
data_size = n_rows * n_features
251+
K = 200000
252+
250253
n_jobs = num_jobs ( params )
251-
252-
##
253-
if 100 < n_features : n_jobs = min ( 16 , n_jobs )
254-
elif 20 < n_features : n_jobs = min ( 8 , n_jobs )
255-
elif 10 < n_features : n_jobs = min ( 4 , n_jobs )
256-
else : n_jobs = min ( 2 , n_jobs )
254+
n_jobs = min ( n_jobs , max ( 1 , math.floor ( data_size / K ) ) )
257255
##
258256
params [ 'n_jobs' ] = n_jobs
259257

@@ -1216,7 +1214,7 @@ def _train_single_model ( self,
12161214

12171215
# Destroy heavy training DMatrix objects and training C++ booster instance
12181216
del dtrain, dval, model,
1219-
del X_tr, y_tr , w_tr, X_v , Y_v, w_v
1217+
del X_tr, y_tr , w_tr, X_v , y_v, w_v
12201218

12211219
# Re-instantiate clean C++ booster dedicated strictly to inference
12221220
model = XGBoost.Booster()
@@ -1402,7 +1400,7 @@ def _train_single_model ( self ,
14021400
verbose_level = params.get ('verbose' , False)
14031401
model.fit ( trn_pool , verbose = verbose_level, **fit_kwargs)
14041402

1405-
import gc, pickle
1403+
import pickle
14061404
from ostap.utils.memory import memory
14071405

14081406
with memory ( 'MEMORY CATBOOST' , logger = logger ) :
@@ -1411,7 +1409,7 @@ def _train_single_model ( self ,
14111409
model_bytes = pickle.dumps ( model )
14121410

14131411
# Destroy training pools and heavy training model instance
1414-
del trn_pool, val_pool, model, X_tr, y_tr, w_tr, X_va, y_va, w_va
1412+
del trn_pool, val_pool, model, X_tr, y_tr, w_tr, X_v, y_v, w_v
14151413

14161414
# Re-instantiate clean, standalone inference engine
14171415
model = pickle.loads ( model_bytes )

‎ostap/tools/tests/test_tools_reweight5.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def make_datasets2 ( n_samples = 5000 ,
156156
COMPARATOR2 ( parallel = True , nToys = 100 ) ,
157157
COMPARATOR3 ( parallel = True , nToys = 100 ) )
158158

159+
if hasCatBoost () :
160+
from ostap.stats.adval import ADVAL_CATB as COMPARATOR7
161+
comparators += ( COMPARATOR7 ( parallel = True , nToys = 25 ) , )
162+
159163
if hasLightGBM () :
160164
from ostap.stats.adval import ADVAL_LGBM as COMPARATOR5
161165
comparators += ( COMPARATOR5 ( parallel = True , nToys = 25 ) , )
@@ -164,10 +168,6 @@ def make_datasets2 ( n_samples = 5000 ,
164168
from ostap.stats.adval import ADVAL_XGB as COMPARATOR6
165169
comparators += ( COMPARATOR6 ( parallel = False , nToys = 25 , n_jobs = 1) , )
166170

167-
if False and hasCatBoost () :
168-
from ostap.stats.adval import ADVAL_CATB as COMPARATOR7
169-
comparators += ( COMPARATOR7 ( parallel = True , nToys = 25 ) , )
170-
171171
if hasSkLearn ():
172172
from ostap.stats.adval import ADVAL_HGBC as COMPARATOR8
173173
comparators += ( COMPARATOR8 ( parallel = True , nToys = 25 ) , )
@@ -266,7 +266,7 @@ def run_reweight ( n_dim = 3 ,
266266
# =============================================================================
267267
if '__main__' == __name__ :
268268

269-
run_reweight ( 3 , 3000 )
269+
run_reweight ( 3 , 4000 )
270270

271271
# =============================================================================
272272

‎ostap/utils/basic.py‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,33 @@ def wm_print ( wm , with_category = True ) :
333333

334334
# ==============================================================================
335335
## key-word arguments related to number of cores/threads to be used
336-
njobs_kwords = ( 'numthreads' , 'numthread' ,
337-
'nthreads' , 'nthread' ,
338-
'numjobs' , 'numjob' ,
339-
'njobs' , 'njob' ,
340-
'threadcounts' , 'threadcount' )
336+
njobs_kwords = frozenset( [ 'numthreads' , 'numthread' ,
337+
'nthreads' , 'nthread' ,
338+
'numjobs' , 'numjob' ,
339+
'njobs' , 'njob' ,
340+
'threadcounts' , 'threadcount' ] )
341341
# ==============================================================================
342342
## get the value of "n_jobs/num_threads/thread_count" parameter
343-
def num_jobs ( params , defval = -1 ) :
343+
def num_jobs ( params = {} , defval = -1 , **kwargs ) :
344344
""" Get the value of "n_jobs/num_threads/thread_count" parameter
345345
"""
346-
nj = defval
347-
for kw in njobs_kwords :
348-
key = kw.lower().strip().replace('_','')
349-
nj = params.pop ( kkey , nj )
346+
nj = defval
347+
found = set()
348+
for k, v in params.items () :
349+
kw = k.lower().strip().replace('_','').replace(' ','').replace('-','' )
350+
if kw in njobs_kwords :
351+
found.add ( k )
352+
if isinstance ( v , int ) : nj = v
353+
354+
## remove the keys
355+
for k in found : params.pop ( k , None )
356+
357+
## loop over keyword arguments
358+
for k , v in kwargs :
359+
kw = k.lower().strip().replace('_','').replace(' ','').replace('-','' )
360+
if kw in njobs_kwords :
361+
if isinstance ( v , int ) : nj = v
362+
350363
##
351364
if not nj : return 1
352365
##

0 commit comments

Comments
 (0)