def get_winning_arm_names(arms_sampled): r"""Compute the set of winning arm names based on the given ``arms_sampled``.. Throws an exception when arms_sampled is empty. Implementers of this interface will never override this method. :param arms_sampled: a dictionary of arm name to :class:`moe.bandit.data_containers.SampleArm` :type arms_sampled: dictionary of (str, SampleArm()) pairs :return: of set of names of the winning arms :rtype: frozenset(str) :raise: ValueError when ``arms_sampled`` are empty. """ if not arms_sampled: raise ValueError('arms_sampled is empty!') avg_payoff_arm_name_list = [] for arm_name, sampled_arm in arms_sampled.iteritems(): avg_payoff = numpy.float64( sampled_arm.win - sampled_arm.loss ) / sampled_arm.total if sampled_arm.total > 0 else 0 avg_payoff_arm_name_list.append((avg_payoff, arm_name)) return get_winning_arm_names_from_payoff_arm_name_list( avg_payoff_arm_name_list)
def get_winning_arm_names(self, arms_sampled): r"""Compute the set of winning arm names based on the given ``arms_sampled``.. Throws an exception when arms_sampled is empty. :param arms_sampled: a dictionary of arm name to :class:`moe.bandit.data_containers.SampleArm` :type arms_sampled: dictionary of (str, SampleArm()) pairs :return: set of names of the winning arms :rtype: frozenset(str) :raise: ValueError when ``arms_sampled`` are empty. """ if not arms_sampled: raise ValueError('arms_sampled is empty!') # If there exists an unsampled arm, return the names of the unsampled arms unsampled_arm_names = self.get_unsampled_arm_names(arms_sampled) if unsampled_arm_names: return unsampled_arm_names number_sampled = sum( [sampled_arm.total for sampled_arm in arms_sampled.values()]) ucb_payoff_arm_name_list = [ (self.get_ucb_payoff(sampled_arm, number_sampled), arm_name) for arm_name, sampled_arm in arms_sampled.items() ] return get_winning_arm_names_from_payoff_arm_name_list( ucb_payoff_arm_name_list)
def test_get_winning_arm_names_from_payoff_arm_name_list_two_winners(self): """Test winning arm names match the winners.""" T.assert_sets_equal( get_winning_arm_names_from_payoff_arm_name_list([(0.5, "arm1"), (0.5, "arm2"), (0.4, "arm3")]), frozenset(["arm1", "arm2"]))
def get_winning_arm_names(self, arms_sampled): r"""Compute the set of winning arm names based on the given ``arms_sampled``.. Throws an exception when arms_sampled is empty. :param arms_sampled: a dictionary of arm name to :class:`moe.bandit.data_containers.SampleArm` :type arms_sampled: dictionary of (str, SampleArm()) pairs :return: set of names of the winning arms :rtype: frozenset(str) :raise: ValueError when ``arms_sampled`` are empty. """ if not arms_sampled: raise ValueError('arms_sampled is empty!') # If there exists an unsampled arm, return the names of the unsampled arms unsampled_arm_names = self.get_unsampled_arm_names(arms_sampled) if unsampled_arm_names: return unsampled_arm_names number_sampled = sum([sampled_arm.total for sampled_arm in arms_sampled.itervalues()]) ucb_payoff_arm_name_list = [(self.get_ucb_payoff(sampled_arm, number_sampled), arm_name) for arm_name, sampled_arm in arms_sampled.iteritems()] return get_winning_arm_names_from_payoff_arm_name_list(ucb_payoff_arm_name_list)
def get_winning_arm_names(self, arms_sampled): r"""Compute the set of winning arm names based on the given ``arms_sampled``.. Throws an exception when arms_sampled is empty. :param arms_sampled: a dictionary of arm name to :class:`moe.bandit.data_containers.SampleArm` :type arms_sampled: dictionary of (str, SampleArm()) pairs :return: set of names of the winning arms :rtype: frozenset(str) :raise: ValueError when ``arms_sampled`` are empty. """ if not arms_sampled: raise ValueError('arms_sampled is empty!') bla_payoff_arm_name_list = [(self.get_bla_payoff(sampled_arm), arm_name) for arm_name, sampled_arm in arms_sampled.iteritems()] return get_winning_arm_names_from_payoff_arm_name_list(bla_payoff_arm_name_list)
def get_winning_arm_names(self, arms_sampled): r"""Compute the set of winning arm names based on the given ``arms_sampled``.. Throws an exception when arms_sampled is empty. :param arms_sampled: a dictionary of arm name to :class:`moe.bandit.data_containers.SampleArm` :type arms_sampled: dictionary of (str, SampleArm()) pairs :return: set of names of the winning arms :rtype: frozenset(str) :raise: ValueError when ``arms_sampled`` are empty. """ if not arms_sampled: raise ValueError('arms_sampled is empty!') bla_payoff_arm_name_list = [ (self.get_bla_payoff(sampled_arm), arm_name) for arm_name, sampled_arm in arms_sampled.iteritems() ] return get_winning_arm_names_from_payoff_arm_name_list( bla_payoff_arm_name_list)
def get_winning_arm_names(arms_sampled): r"""Compute the set of winning arm names based on the given ``arms_sampled``.. Throws an exception when arms_sampled is empty. Implementers of this interface will never override this method. :param arms_sampled: a dictionary of arm name to :class:`moe.bandit.data_containers.SampleArm` :type arms_sampled: dictionary of (str, SampleArm()) pairs :return: of set of names of the winning arms :rtype: frozenset(str) :raise: ValueError when ``arms_sampled`` are empty. """ if not arms_sampled: raise ValueError('arms_sampled is empty!') avg_payoff_arm_name_list = [] for arm_name, sampled_arm in arms_sampled.iteritems(): avg_payoff = numpy.float64(sampled_arm.win - sampled_arm.loss) / sampled_arm.total if sampled_arm.total > 0 else 0 avg_payoff_arm_name_list.append((avg_payoff, arm_name)) return get_winning_arm_names_from_payoff_arm_name_list(avg_payoff_arm_name_list)
def test_get_winning_arm_names_from_payoff_arm_name_list_two_winners(self): """Test winning arm names match the winners.""" T.assert_sets_equal( get_winning_arm_names_from_payoff_arm_name_list([(0.5, "arm1"), (0.5, "arm2"), (0.4, "arm3")]), frozenset(["arm1", "arm2"]), )
def test_get_winning_arm_names_from_payoff_arm_name_list_one_winner(self): """Test winning arm name matches the winner.""" T.assert_sets_equal( get_winning_arm_names_from_payoff_arm_name_list([(0.5, "arm1"), (0.0, "arm2")]), frozenset(["arm1"]) )
def test_get_winning_arm_names_from_payoff_arm_name_list_one_winner(self): """Test winning arm name matches the winner.""" T.assert_sets_equal( get_winning_arm_names_from_payoff_arm_name_list([(0.5, "arm1"), (0.0, "arm2")]), frozenset(["arm1"]))
def test_get_winning_arm_names_from_payoff_arm_name_list_empty_list_invalid(self): """Test empty ``payoff_arm_name_list`` causes an ValueError.""" with pytest.raises(ValueError): get_winning_arm_names_from_payoff_arm_name_list([])