#think-bayes #probability #study


이번 장에서는 여러분의 인내심을 시험하는 위험을 무릅쓰고 '확률 질량 함수'(probability mass function)를 나타내는 Pmf 를 사용해 문제를 한 번 더 풀어본다. 이것이 무엇을 의미하는지, 그리고 베이지안 통계에 왜 유용한지 설명한다

Pmf 를 사용하여 좀 더 어려운 문제를 해결하고 베이지안 통계에 한 걸음 더 다가가자.

Distributions

A distribution is simply a collection of data, or scores, on a variable. Usually, these scores are arranged in order from smallest to largest and then they can be presented graphically. (Page 6, Statistics in Plain English, Third Edition, 2010.)

pmf (probability mass functions)

>>> from empiricaldist import Pmf
>>> 
>>> coin = Pmf()
>>> coin['heads'] = 1/2
>>> coin['tails'] = 1/2
>>> coin

배열을 입력으로 하는 Pmf.from_seq 함수를 이용해 확률을 계산할 수 있다.

>>> die = Pmf.from_seq([1,2,3,4,5,6])
>>> die

특정 단어에서 문자가 출현할 확률도 구할 수 있다.

letters = Pmf.from_seq(list('Mississippi'))
letters

The Cookie Problem Revisited (with pmf)

앞서 살펴본 쿠키 문제를 pmf 를 이용해 살펴본다.

>>> prior = Pmf.from_seq(['Bowl 1', 'Bowl 2'])
>>> prior

>>> likelihood_vanilla = [0.75, 0.5]
>>> posterior = prior * likelihood_vanilla
>>> posterior

101 Bowls (with pmf)

앞서 살펴본 쿠키 문제를 확장해서 풀어본다. (2 Bowls -> 101 Bowls)

The Dice Problem (with pmf)

Updating Dice

위 문제에서 여러번 계산하던 것을 하나의 함수로 정의한다.

def update_dice(pmf, data):
    """Update pmf based on new data."""
    hypos = pmf.qs
    likelihood = 1 / hypos
    impossible = (data > hypos)
    likelihood[impossible] = 0 # 주사위 숫자보다 큰 경우 
    pmf *= likelihood
    pmf.normalize()

Summary

reference