def _create_algorithm(self, base_algorithm, batch_train: bool, **kwargs):
     if self._algorithm_name == 'egreedy':
         self._algorithm = EpsilonGreedy(
             base_algorithm,
             nchoices=self._K,
             random_state=self._rnd.randint(1000),
             explore_prob=kwargs.get('epsilon', 0.1),
             batch_train=batch_train
         )
     elif self._algorithm_name == 'bootstrapped_ucb':
         self._algorithm = BootstrappedUCB(
             base_algorithm,
             nchoices=self._K,
             random_state=self._rnd.randint(1000),
             batch_train=batch_train
         )
     else:
         sys.exit("no such algorithm: %s" % algorithm)
Esempio n. 2
0
        AdaptiveGreedy(deepcopy(base_algorithm),
                       nchoices=nchoices,
                       beta_prior=beta_prior,
                       decay_type='percentile',
                       decay=0.9997),
        AdaptiveGreedy(deepcopy(base_algorithm),
                       nchoices=nchoices,
                       beta_prior=beta_prior,
                       active_choice='weighted',
                       decay_type='percentile',
                       decay=0.9997),
        BootstrappedTS(deepcopy(base_algorithm),
                       nchoices=nchoices,
                       beta_prior=beta_prior),
        BootstrappedUCB(deepcopy(base_algorithm),
                        nchoices=nchoices,
                        beta_prior=beta_prior),
        SoftmaxExplorer(deepcopy(base_algorithm),
                        nchoices=nchoices,
                        beta_prior=beta_prior)
    ]

    model_names_opts = [
        "adaptive_greedy_thres", "adaptive_greedy_perc",
        "adaptive_active_greedy", "bootstrapped_ts", "bootstrapped_ucb",
        "softmax"
    ]
    '''
    models = [AdaptiveGreedy(deepcopy(base_algorithm), nchoices=nchoices, decay_type='threshold')]
    models = [AdaptiveGreedy(deepcopy(base_algorithm), nchoices = nchoices, beta_prior=beta_prior, decay_type='percentile', decay=0.9997)]
    models = [AdaptiveGreedy(deepcopy(base_algorithm), nchoices = nchoices, beta_prior=beta_prior, active_choice='weighted', decay_type='percentile', decay=0.9997)]
Esempio n. 3
0
    mlb = MultiLabelBinarizer()
    y = mlb.fit_transform(labels)
    return features, y


X, y = parse_data("loc_9.txt")

nchoices = y.shape[1]
base_algorithm = SGDClassifier(random_state=123, loss='log')
beta_prior = (
    (3, 7), 2
)  # until there are at least 2 observations of each class, will use prior Beta(3, 7)

## The base algorithm is embedded in different metaheuristics
bootstrapped_ucb = BootstrappedUCB(deepcopy(base_algorithm),
                                   nchoices=nchoices,
                                   beta_prior=beta_prior,
                                   batch_train=True)
bootstrapped_ts = BootstrappedTS(deepcopy(base_algorithm),
                                 nchoices=nchoices,
                                 beta_prior=beta_prior,
                                 batch_train=True)
one_vs_rest = SeparateClassifiers(deepcopy(base_algorithm),
                                  nchoices=nchoices,
                                  beta_prior=beta_prior,
                                  batch_train=True)
epsilon_greedy = EpsilonGreedy(deepcopy(base_algorithm),
                               nchoices=nchoices,
                               beta_prior=beta_prior,
                               batch_train=True)
epsilon_greedy_nodecay = EpsilonGreedy(deepcopy(base_algorithm),
                                       nchoices=nchoices,