/Segment29

From Computational Statistics (CSE383M and CS395T)
Jump to navigation Jump to search

Teamed up with Travis and Sean Trettel

=On class


x=[5, 9, 8, 4, 7]     # the number of heads out of ten tosses in each of the the 5 sets 
theta=[0.6, 0.5]    # probability of getting head for coin A and B

def estep(x,theta):
    xah=0
    xat=0
    xbh=0
    xbt=0

    for i in range(5):
        pza=theta[0]**x[i]*(1-theta[0])**(10-x[i])/(theta[0]**x[i]*(1-theta[0])**(10-x[i])+theta[1]**x[i]*(1-theta[1])**(10-x[i]))
        pzb=1-pza
        xah+=pza*x[i]
        xat+=pza*(10-x[i])
        xbh+=pzb*x[i]
        xbt+=pzb*(10-x[i])
        print(pza)
    theta=[xah/(xah+xat), xbh/(xbh+xbt)]


    return theta

for i in range(10):
    theta=estep(x, theta)
    print(theta)