User:Trettels:Session 39 - 24APR

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

In Class

Worked with Dan, in the "brute force" group.

testinit_urn=[7 3 5];
w=[6 4 3]; %ratio of probabilities for the three ball types

p=@(u) ( (w.*u)/(sum(w.*u)));

nreps=1e6;
ndraw=6;
countSucc=0;
nprods=zeros(1,nreps);

for aa=1:nreps
    urn=init_urn;
    pocket=[0 0 0];
    for bb=1:ndraw
        test=rand(1);
        prvals=p(urn);
        if test < prvals(1)
            urn(1)=urn(1)-1;
            pocket(1)=pocket(1)+1;
        elseif test< prvals(1)+prvals(2)
            urn(2)=urn(2)-1;
            pocket(2)=pocket(2)+1;
        else
            urn(3)=urn(3)-1;
            pocket(3)=pocket(3)+1;
        end
    end
    if pocket(1)==4
        if pocket(2)==2 || pocket(3)==2
            countSucc=countSucc+1;
        end
    end
    nprods(aa) = pocket(2)*pocket(3);
end
countSucc
fracSucc = countSucc/nreps
meanProduct = mean(nprods)

Back to TrettelS Index