%PIMA
% random numbers to default start
s = RandStream('mt19937ar','Seed',0);
RandStream.setGlobalStream(s);
%
ih =1; %hard evidence
ps=[]; as=[]; os=[]; ds =[]; gs=[]; is=[]; bs=[];%place holders for p,a,o,g,i,b
for i = 1:100000
    p = rand < 0.55;
    a = rand < 0.50;
    o = rand < 0.50;
    if p
        if a    if o    d = rand < 0.59;   else  d = rand < 0.37;   end;   %111 and 110
        else  if o    d = rand < 0.34;   else  d = rand < 0.27;   end;   %101 and 100
        end;
     else                 
        if  a  if o    d = rand < 0.60;    else  d = rand < 0.41;   end;   %011 and 010 
        else if o    d = rand < 0.33;    else  d = rand < 0.05;   end;    %001 and 000
        end;
    end;
    %
    if d    g = rand < 0.79;    else  g = rand < 0.36;  end;
    if d     i = rand < 0.48;    else    i = rand < 0.51;  end;
     
  if o    if d   b=rand < 0.51; else b = rand < 0.60; end;
  else   if d   b=rand < 0.42; else b = rand < 0.51; end;
  end

%
if i == ih
    ps=[ps p]; as=[as a]; os=[os o]; ds =[ds d]; gs=[gs g]; is =[is i]; bs=[bs b];
end
end
pogiveni = mean(os)
         
                 
                    
    
