📚 The CoCalc Library - books, templates and other resources
License: OTHER
"""This file contains code for use with "Think Bayes",1by Allen B. Downey, available from greenteapress.com23Copyright 2012 Allen B. Downey4License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html5"""67from thinkbayes import Suite8910class M_and_M(Suite):11"""Map from hypothesis (A or B) to probability."""1213mix94 = dict(brown=30,14yellow=20,15red=20,16green=10,17orange=10,18tan=10,19blue=0)2021mix96 = dict(blue=24,22green=20,23orange=16,24yellow=14,25red=13,26brown=13,27tan=0)2829hypoA = dict(bag1=mix94, bag2=mix96)30hypoB = dict(bag1=mix96, bag2=mix94)3132hypotheses = dict(A=hypoA, B=hypoB)3334def Likelihood(self, data, hypo):35"""Computes the likelihood of the data under the hypothesis.3637hypo: string hypothesis (A or B)38data: tuple of string bag, string color39"""40bag, color = data41mix = self.hypotheses[hypo][bag]42like = mix[color]43return like444546def main():47suite = M_and_M('AB')4849suite.Update(('bag1', 'yellow'))50suite.Update(('bag2', 'green'))5152suite.Print()535455if __name__ == '__main__':56main()575859