def select_variant()

in lambda/api/algorithm.py [0:0]


    def select_variant(self):
        """
        The Epsilon-Greedy algorithm balances exploitation and exploration fairly basically.
        It takes a parameter, epsilon, between 0 and 1, as the probability of exploring the variants
        as opposed to exploiting the current best variant in the test.
        """
        if random.random() > self.epsilon:
            rates = [
                1.0 * v["reward_sum"] / v["invocation_count"]
                for v in self.variant_metrics
            ]
            variant_index = AlgorithmBase.argmax(rates)
        else:
            variant_index = random.randrange(len(self.variant_metrics))
        return self.variant_metrics[variant_index]["variant_name"]