def test_ucb_select_two_arms_and_have_two_reward_priorize_first(): ucb_with_two_arms = algs.UCB1(2) ucb_with_two_arms.select() ucb_with_two_arms.reward(0) ucb_with_two_arms.select() ucb_with_two_arms.reward(1) ucb_with_two_arms.select() ucb_with_two_arms.reward(0) ucb_with_two_arms.select() ucb_with_two_arms.reward(1) assert ucb_with_two_arms.select() == 0
def test_ucb_exploration_first(): ucb_with_two_arms = algs.UCB1(2) ucb_with_two_arms.select() ucb_with_two_arms.reward(0) ucb_with_two_arms.select() ucb_with_two_arms.reward(1) ucb_with_two_arms.select() ucb_with_two_arms.reward(0) ucb_with_two_arms.select() ucb_with_two_arms.reward(1) last_arm = ucb_with_two_arms.select() assert last_arm == 0
def test_ucb_exploration_second(): ucb_with_two_arms = algs.UCB1(2) ucb_with_two_arms.select() ucb_with_two_arms.reward(0) ucb_with_two_arms.select() ucb_with_two_arms.reward(1) ucb_with_two_arms.select() ucb_with_two_arms.reward(0) ucb_with_two_arms.select() ucb_with_two_arms.reward(1) ucb_with_two_arms.select() last_arm = ucb_with_two_arms.select()[0] assert last_arm == 0
def get_algorithm(self, name, number_of_arms): """ This method instantiate the algorithm class. :param name: Name of algorithm. :param number_of_arms: Number of arms. :return: Returns the algorithm instance. """ if name == 'ths': alg = algs.ThompsomSampling(number_of_arms) elif name == 'tuned': alg = algs.UCBTuned(number_of_arms) elif name == 'ucb1': alg = algs.UCB1(number_of_arms) return alg
def test_ucb_use_all_arm_dont_usage(): ucb_with_two_arms = algs.UCB1(2) assert ucb_with_two_arms.select() == 0 assert ucb_with_two_arms.select() == 1
def test_ucb_init_return_first_arm(): ucb_with_two_arms = algs.UCB1(2) assert ucb_with_two_arms.select() == 0
def test_ucb_select_two_arms_and_success_one_return_first(): ucb_with_two_arms = algs.UCB1(2) ucb_with_two_arms.select() ucb_with_two_arms.select() ucb_with_two_arms.reward(0) assert ucb_with_two_arms.select() == 0
def test_ucb_select_two_arms_and_success_return_second(): ucb_with_two_arms = algs.UCB1(2) ucb_with_two_arms.select() ucb_with_two_arms.select() ucb_with_two_arms.reward(1) assert ucb_with_two_arms.select() == 1
def test_ucb_use_all_arm_dont_usage_after_priorize(): ucb_with_two_arms = algs.UCB1(2) assert ucb_with_two_arms.select()[0] == 0 assert ucb_with_two_arms.select()[0] == 1 assert ucb_with_two_arms.select()[0] == 1