Example #1
0
    def __init__(self,
                 batch_size: int = 256,
                 epochs: int = 100,
                 activation_fn: str = 'softmax',
                 num_negative: int = 500,
                 optimizer: optimizers = optimizers.Adam(),
                 loss: losses = 'categorical_crossentropy',
                 validation_step: int = 1,
                 normalize_score: bool = False,
                 bow_feature=None,
                 vocabulary=None):

        self._model_params = InputParamTuple(num_negative=num_negative,
                                             batch_size=batch_size,
                                             epochs=epochs,
                                             validation_step=validation_step,
                                             optimizer=optimizer,
                                             loss=loss,
                                             activation_fn=activation_fn,
                                             normalize=normalize_score)  # TODO

        self._data = None
        self._model = None
        self._best_model = None
        self._normalize_score = normalize_score

        self._doubler = Doubler(embedding_node_dim=300,
                                embedding_doc_dim=64,
                                bow_feature=bow_feature,
                                vocabulary=vocabulary)
Example #2
0
def gen():

    d = {
        "RMED1_regrets": [],
        "RMED2_regrets": [],
        "IF_regrets": [],
        "BTM_regrets": [],
        "SAVAGE_regrets": [],
        "DOUBLER_regrets": []
    }

    horizon = 100000
    samples = 10

    for i in range(samples):

        print("On sample number", i)

        x = RMED('RMED1', len(pref_mat), horizon, generator_fnc, f_rmed,
                 regret_fn)
        reg_RMED = np.array(x.algo())
        #reg_BTM[0] contains the regret values, [1] contains the best arm
        print("RMED done, best arm : ", reg_RMED[1])
        d["RMED1_regrets"].append(list(np.around(reg_RMED[0], 3)))
        # json.dump(RMED1_regrets, open("RMED1_regrets.json", "w"))

        x = RMED('RMED2', len(pref_mat), horizon, generator_fnc, f_rmed,
                 regret_fn)
        reg_RMED = np.array(x.algo())
        print("RMED done, best arm : ", reg_RMED[1])
        d["RMED2_regrets"].append(list(np.around(reg_RMED[0], 3)))
        # json.dump(RMED2_regrets, open("RMED2_regrets.json", "w"))

        x = InterleavedFilter(len(pref_mat), horizon, generator_fnc, regret_fn)
        reg_IF = np.array(x.algo())
        print("IF done, best arm : ", reg_IF[1])
        d["IF_regrets"].append(list(np.around(reg_IF[0], 3)))
        # json.dump(IF_regrets, open("IF_regrets.json", "w"))

        x = BeatTheMean(len(pref_mat), horizon, generator_fnc, regret_fn)
        reg_BTM = np.array(x.algo())
        print("BTM done, best arm : ", reg_BTM[1])
        d["BTM_regrets"].append(list(np.around(reg_BTM[0], 3)))
        # json.dump(BTM_regrets, open("BTM_regrets.json", "w"))

        x = Doubler(horizon, pref_mat, regret_fn)
        reg_DOUBLER = x.run()
        print("Doubler done, best arm : ", reg_DOUBLER[1])
        d["DOUBLER_regrets"].append(reg_DOUBLER[0])
        # json.dump(DOUBLER_regrets, open("DOUBLER_regrets.json", "w"))

        x = SAVAGE(horizon, pref_mat, regret_fn)
        reg_SAVAGE = x.run()
        print("SAVAGE done, best arm : ", reg_SAVAGE[1])
        d["SAVAGE_regrets"].append(reg_SAVAGE[0])
        # json.dump(SAVAGE_regrets, open("SAVAGE_regrets.json", "w"))

        if i % 3 == 0:
            print("Dumped all")
            dump_all(d)

    dump_all(d)

    d['RUCB_regrets'] = run_rucb(samples, horizon, pref_mat)
    print("RUCB done")
    d['RCS_regrets'] = run_rcs(samples, horizon, pref_mat)
    print("RCS done")
    dump_all(d)