Example #1
0
data_type = 'debug-four'
flag = 'four'
#full_data,Z_gen = generate_data(feature_count,data_count + held_out,T,sig,data_type)
full_data, Z_gen = construct_data(data_dim, data_count + held_out, sig,
                                  data_type)
Y = full_data[:data_count, :]
held_out = full_data[data_count:, :]
#we observe half the signal and recover the other half
observe = held_out[:, :T / 2]
trunc = 12  #truncate active features

if algorithm == 'IBP':
    iterate = 200
    alpha = 2.0
    select = 12
    Z, W, ll_set, pred_ll = ugibbs_sampler(Y, held_out, alpha, sig_test, sig_w,
                                           iterate, select, trunc, data_dim)
    Z_trunc, W_trunc = truncate(Z, W, select)
    print_posterior(Z_trunc, W_trunc, data_dim)
    recover_ll = recover_IBP(held_out, observe, Z, W, sig_test)
    print("Log Recovery")
    print(recover_ll)
    print("End Uncollapsed IBP")

if algorithm == 'paintbox':
    log_res = 10  #log of res
    hold = 100  #hold resolution for # iterations
    #feature_count = 4 #features
    #feature deviation #it was 0.3 for random #0.2 for corr
    iterate = 1000
    K = 3  #start with K features
    ext = 1  #draw one new feature per iteration
Example #2
0
trunc = 12  #truncate active features
log_res = 10  #log of res
hold = 100  #hold resolution for # iterations
initialize = True
if initialize:
    alpha = 2.0
    pre_trunc = 12
    #dummy variable
    select = 10
    Z_init, W_init, _, _, rec_ll, iter_time = ugibbs_sampler(train,
                                                             test,
                                                             alpha,
                                                             sig_test,
                                                             sig_w,
                                                             init_iter,
                                                             select,
                                                             pre_trunc,
                                                             observe,
                                                             obs_indices,
                                                             limit,
                                                             init=initialize,
                                                             display=display)
    zip_list = zip(iter_time, rec_ll)
    print('IBP')
    for z in zip_list:
        print(z)
        K = Z_init.shape[1]
else:
    K = 1  #start with K features
ext = 0  #draw one new feature per iteration
outputs = upaintbox_sample(log_res,
Example #3
0
    feature = np.zeros((runs,iterate))
    lapse_data = np.zeros((runs,iterate))
    #pred_data = np.zeros((runs,iterate))
    valid = 0
    algorithm = 'paintbox'
    truncate = 12
    #algorithm = 'var'
    #algorithm = 'uncollapsed'
    #you'll come back to this
    while valid < runs:
        #print("Trial Number: " + str(valid))
        if algorithm == 'paintbox': 
            #profile.run('upaintbox_sample(log_res,hold,Y,held_out,ext,sig_alg,sig_w,iterate,K,valid)')
            ll_list,iter_time,f_count,lapse,Z,W,prob_matrix,pred_ll,tree = upaintbox_sample(data_dim,log_res,hold,Y,held_out,ext,sig,sig_w,iterate,K,truncate)
        if algorithm == 'uncollapsed':
            Z,W,ll_set = ugibbs_sampler(Y,alpha,sig,sig_w,iterate,Z_gen)
        if algorithm == 'var':
            nu_set,phi_set,Phi_set,tau_set,pred_ll = run_vi(Y,held_out,alpha,sig_w,sig,iterate,feature_count)
        if len(ll_list) == 0:
            continue
        ll_data[valid,:] = ll_list
        ll_time[valid,:] = iter_time
        feature[valid,:] = f_count
        lapse_data[valid,:] = lapse
        #pred_data[valid,:] = pred_ll
        valid += 1
     
#    plot_feature = [num for num in range(1,int(np.max(feature[:,iterate-1])+1))]    
#    plot_lapse = [0 for i in range(len(plot_feature))]
#    all_sums = [0 for i in range(len(plot_feature))]
#    for i in range(len(plot_feature)):
Example #4
0
obs_indices = [i for i in range(int(dimension*obs))]
#print(obs_indices)
observe = test[:,obs_indices]
#print(observe.shape)

if algorithm == 'IBP':
    trunc = 12
    iterate = 800
    alpha = 2.0
    #dummy variable 
    #kept around because we may have to truncate at future date
    select = 10
    #print("test shape")
    #print(test.shape)
    Z,W,ll_set,pred_ll,rec_ll,iter_time = ugibbs_sampler(train,test,alpha,sig_test,
                                                         sig_w,iterate,select,trunc,
                                                         observe,obs_indices,limit)
    zip_list = zip(iter_time,rec_ll)
    for z in zip_list:
        print(z)
    #Z_trunc,W_trunc = truncate(Z,W,select)
    #print_posterior(Z_trunc,W_trunc,data_dim)
    #recover_ll = recover_IBP(test,observe,Z,W,sig_test,obs_indices)
    #print("Log Recovery")
    #print(recover_ll)
    #print("End Uncollapsed IBP")
    #np.savetxt("rec" + process + ".txt", rec_ll)
    #np.savetxt("time" + process + ".txt", iter_time)

if algorithm == 'paintbox':
    trunc = 12 #truncate active features