How to use the contextualbandits.utils._check_njobs function in contextualbandits

To help you get started, we’ve selected a few contextualbandits examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github david-cortes / contextualbandits / contextualbandits / online.py View on Github external
def _add_bootstrapped_inputs(self, base_algorithm, batch_sample_method, nsamples, njobs_samples, percentile):
        assert (batch_sample_method == 'gamma') or (batch_sample_method == 'poisson')
        assert isinstance(nsamples, int)
        assert nsamples >= 2
        self.batch_sample_method = batch_sample_method
        self.nsamples = nsamples
        self.njobs_samples = _check_njobs(njobs_samples)
        if "predict_proba" in dir(base_algorithm):
            self.base_algorithm = _BootstrappedClassifier_w_predict_proba(
                base_algorithm, self.nsamples, percentile,
                self.batch_train, self.batch_sample_method, njobs = self.njobs_samples
                )
        elif "decision_function" in dir(base_algorithm):
            self.base_algorithm = _BootstrappedClassifier_w_decision_function(
                base_algorithm, self.nsamples, percentile,
                self.batch_train, self.batch_sample_method, njobs = self.njobs_samples
                )
        else:
            self.base_algorithm = _BootstrappedClassifier_w_predict(
                base_algorithm, self.nsamples, percentile,
                self.batch_train, self.batch_sample_method, njobs = self.njobs_samples
                )
github david-cortes / contextualbandits / contextualbandits / online.py View on Github external
def _add_common_params(self, base_algorithm, beta_prior, smoothing, njobs, nchoices,
            batch_train, assume_unique_reward, assign_algo=True, prior_def_ucb = False):
        
        if isinstance(base_algorithm, np.ndarray) or base_algorithm.__class__.__name__ == "Series":
            base_algorithm = list(base_algorithm)

        self._add_choices(nchoices)
        _check_constructor_input(base_algorithm, self.nchoices, batch_train)
        self.smoothing = _check_smoothing(smoothing)
        self.njobs = _check_njobs(njobs)
        self.batch_train, self.assume_unique_reward = _check_bools(batch_train, assume_unique_reward)
        if prior_def_ucb and beta_prior == "auto":
            beta_prior = ( (5.0 / self.nchoices, 4.0), 2 )
        self.beta_prior = _check_beta_prior(beta_prior, self.nchoices, 2)

        if assign_algo:
            self.base_algorithm = base_algorithm

        self.is_fitted = False
github david-cortes / contextualbandits / contextualbandits / online.py View on Github external
def _add_common_lin(self, alpha, nchoices, njobs):
        if isinstance(alpha, int):
            alpha = float(alpha)
        assert isinstance(alpha, float)

        _BasePolicy._add_choices(self, nchoices)
        _check_constructor_input(_ZeroPredictor(), nchoices)
        self.njobs = _check_njobs(njobs)
        self.alpha = alpha
        self.nchoices = nchoices
        self._oracles = [_LinUCBnTSSingle(self.alpha, self._ts) for n in range(nchoices)]
        if not self._ts:
            self.v_sq = self.alpha
            del self.alpha
        self.is_fitted = False
github david-cortes / contextualbandits / contextualbandits / offpolicy.py View on Github external
def __init__(self, base_algorithm, nchoices, c = None, pmin = 1e-5, njobs = -1):
        try:
            from costsensitive import _BinTree
        except:
            raise ValueError("This functionality requires package 'costsensitive'.\nCan be installed with 'pip install costsensitive'.")
        _check_constructor_input(base_algorithm, nchoices)
        self.base_algorithm = base_algorithm
        self.nchoices = nchoices
        self.tree = _BinTree(nchoices)
        if c is not None:
            assert isinstance(c, float)
        if pmin is not None:
            assert isinstance(pmin, float)
        self.c = c
        self.pmin = pmin
        self.njobs = _check_njobs(njobs)