示例#1
0
init_UV = 'random'
alpha, beta = 1., 1.
lambdaU, lambdaV = 1., 1.
priors = {'alpha': alpha, 'beta': beta, 'lambdaU': lambdaU, 'lambdaV': lambdaV}

no_folds = 10
file_performance = 'results/bnmf.txt'
''' Split the folds. For each, obtain a list for the test set of (i,j,real,pred) values. '''
i_j_real_pred = []
folds_test = mask.compute_folds_attempts(I=I,
                                         J=J,
                                         no_folds=no_folds,
                                         attempts=1000,
                                         M=M_gdsc)
folds_training = mask.compute_Ms(folds_test)

for i, (train, test) in enumerate(zip(folds_training, folds_test)):
    print "Fold %s." % (i + 1)
    ''' Predict values. '''
    BNMF = bnmf_gibbs(R=R_gdsc, M=train, K=K, priors=priors)
    BNMF.initialise(init=init_UV)
    BNMF.run(iterations=iterations)
    R_pred = BNMF.return_R_predicted(burn_in=burn_in, thinning=thinning)
    ''' Add predictions to list. '''
    indices_test = [(i, j) for (i, j) in itertools.product(range(I), range(J))
                    if test[i, j]]
    for i, j in indices_test:
        i_j_real_pred.append((i, j, R_gdsc[i, j], R_pred[i, j]))
''' Store the performances. '''
with open(file_performance, 'w') as fout:
    fout.write('%s' % i_j_real_pred)
示例#2
0
R_gdsc,     M_gdsc,     _, _ = load_data_without_empty(location_data+"gdsc_ic50_row_01.txt")
R_ctrp,     M_ctrp,     _, _ = load_data_without_empty(location_data+"ctrp_ec50_row_01.txt")
R_ccle_ec,  M_ccle_ec,  _, _ = load_data_without_empty(location_data+"ccle_ec50_row_01.txt")
R_ccle_ic,  M_ccle_ic,  _, _ = load_data_without_empty(location_data+"ccle_ic50_row_01.txt")

R, M = R_ccle_ec, M_ccle_ec


''' Settings BNMF '''
iterations = 1000
init_UV = 'random'
K = 10

alpha, beta = 1., 1.
lambdaU = 1.
lambdaV = 1.
priors = { 'alpha':alpha, 'beta':beta, 'lambdaU':lambdaU, 'lambdaV':lambdaV }


''' Run the method and time it. '''
time_start = time.time()

BNMF = bnmf_gibbs(R,M,K,priors)
BNMF.initialise(init_UV)
BNMF.run(iterations)
    
time_end = time.time()
time_taken = time_end - time_start
time_average = time_taken / iterations
print "Time taken: %s seconds. Average per iteration: %s." % (time_taken, time_average)
示例#3
0
    for (M_train, M_test) in Ms_train_test:
        check_empty_rows_columns(M_train, fraction)
''' Run the method on each of the M's for each fraction '''
all_performances = {metric: [] for metric in metrics}
average_performances = {metric: []
                        for metric in metrics}  # averaged over repeats
for (fraction, Ms_train_test) in zip(fractions_unknown, all_Ms_train_test):
    print "Trying fraction %s." % fraction

    # Run the algorithm <repeats> times and store all the performances
    for metric in metrics:
        all_performances[metric].append([])
    for repeat, (M_train, M_test) in zip(range(0, repeats), Ms_train_test):
        print "Repeat %s of fraction %s." % (repeat + 1, fraction)

        BNMF = bnmf_gibbs(R, M_train, K, priors)
        BNMF.initialise(init_UV)
        BNMF.run(iterations)

        # Measure the performances
        performances = BNMF.predict(M_test, burn_in, thinning)
        for metric in metrics:
            # Add this metric's performance to the list of <repeat> performances for this fraction
            all_performances[metric][-1].append(performances[metric])

    # Compute the average across attempts
    for metric in metrics:
        average_performances[metric].append(
            sum(all_performances[metric][-1]) / repeats)