Beispiel #1
0
def gibbs_sample(Y,sig,sig_w,iterate,D,F,N,T):
    W = np.eye(F)
    pb = pb_init(D,F)
    Z = draw_Z(pb,D,F,N,T)
    if Z_vec(Z,vectorize(pb),D) == 0:
        print("draw Z is wrong")
        
    ll_list = []
    W_list = []
    print("gibbs sample")
    for it in range(iterate):
        print(it)
        #sample Z
        print("SAMPLE Z")
        Z = sample_Z(Y,Z,sig,sig_w,pb,D,F,N,T)
        #sample paintbox
        print("SAMPLE PB")
        pb = sample_pb(Y,Z,pb,D,F,N,T,res)        
        W = mean_w(Y,Z)
        vec = vectorize(pb)
        print("COULD BE SMALL")
        print(log_w_sig(W,sig)) 
        ll_list.append(log_data_zw(Y,Z,W,sig) + np.log(Z_vec(Z,vec,D)) + log_w_sig(W,sig))
    
    return (ll_list,Z,W,pb)
Beispiel #2
0
def cgibbs_sample(Y,sig,sig_w,iterate,D,F,N,T):
    pb = pb_init(D,F)
    Z = draw_Z(pb,D,F,N,T)
        
    ll_list = []
    #print("gibbs sample")
    for it in range(iterate):
        #sample Z
        Z = sample_Z(Y,Z,sig,sig_w,pb,D,F,N,T)
        #sample paintbox
        pb = sample_pb(Z,pb,D,F,N,T,res)        
        W = mean_w(Y,Z)
        vec = vectorize(pb)
        ll_list.append(log_data_zw(Y,Z,W,sig) + Z_vec(Z,vec,D) + log_w_sig(W,sig))
    
    return (ll_list,Z,W,pb)