

def generate_mask(n_samples, bagging=True, random_generator=np.random):
    'bagging: float or bool (default=True), bagging usually\n        speeds up the convergence and prevents overfitting\n        (see http://en.wikipedia.org/wiki/Bootstrap_aggregating)\n        if True, usual bootstrap aggregating is used\n           (sampling with replacement at each iteration, size=len(X))\n        if float, used sampling without replacement, the size of generated\n           set is bagging * len(X)\n        if False, returns ones for all events.'
    if (bagging is True):
        indices = random_generator.randint(0, n_samples, size=n_samples)
        mask = np.bincount(indices, minlength=n_samples)
    elif isinstance(bagging, float):
        mask = (random_generator.uniform(size=n_samples) > (1.0 - bagging))
    elif (bagging is False):
        mask = np.ones(n_samples, dtype='float')
    else:
        raise ValueError('something wrong was passed as bagging')
    return mask

dataset/ETHPy150Open anaderi/lhcb_trigger_ml/hep_ml/uboost.py generate_mask/original