def select_variant()

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


    def select_variant(self):
        """
        Tompson sampling uses Beta distribution takes two parameters, ‘α’ (alpha) and ‘β’ (beta).
        In the simplest terms these parameters can be thought of as respectively the count of successes and failures.
        see: https://towardsdatascience.com/thompson-sampling-fc28817eacb8
        """
        probs = []
        for v in self.variant_metrics:
            success = v["reward_sum"]
            failure = v["invocation_count"] - success
            probs.append(AlgorithmBase.random_beta(1 + success, 1 + failure))
        variant_index = AlgorithmBase.argmax(probs)
        return self.variant_metrics[variant_index]["variant_name"]