function []=seqBinomialPureBayes(p,alpha,beta,iterations)
clf
obsHold=0;

title('How a Bayesian Thinks','fontsize',14)
xlabel('p','fontsize',18)
vals=100;
for(i=1:vals+1)
    paramVal(i) = 1/vals*(i-1);
end
for(i=1:vals+1)
    prior(i)=betapdf(paramVal(i),alpha,beta);
end
axis([0,1,0,10])
hold on
xlabel('p')
plot(paramVal(2:vals),prior(2:vals)*vals/sum(prior(2:vals)),'k--','linewidth',1)
plot([p,p],[0,3],'b','linewidth',2)

for(iter=1:iterations)   
    %pause
    pause(.01)
    N=iter;

    draw=binornd(1,p)
    observed(iter)=obsHold+draw;
    obsHold=observed(iter);
    

    vals=100;
    for(i=1:vals+1)
        paramVal(i) = 1/vals*(i-1);
        like(i)=paramVal(i)^observed(iter)*(1-paramVal(i))^(N-observed(iter));
    end
    like=like*vals/sum(like);
    
    for(i=1:vals+1)
        paramVal(i) = 1/vals*(i-1);
        post(i)=betapdf(paramVal(i),alpha+observed(iter),beta+N-observed(iter));
        prior(i)=betapdf(paramVal(i),alpha,beta);
    end
    clf;
    title('How a Bayesian Thinks')
    
    axis([0,1,0,10])
    hold on
    xlabel('p','fontsize',18)
    plot(paramVal(2:vals),post(2:vals)*vals/sum(post(2:vals)),'r','linewidth',2)
    plot(paramVal,like,'r--')
    plot(paramVal(2:vals),prior(2:vals)*vals/sum(prior(2:vals)),'k--','linewidth',1)
    plot([p,p],[0,3],'b','linewidth',2)
    legend('Posterior Density','Likelihood','Prior Density','Truth')
    %pause
end
