Exemple #1
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)

        BNMTF = bnmtf_gibbs(R, M_train, K, L, priors)
        BNMTF.initialise(init_FG=init_FG, init_S=init_S)
        BNMTF.run(iterations)

        # Measure the performances
        performances = BNMTF.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)

Exemple #2
0
R, M = R_ccle_ic, M_ccle_ic
''' Settings BNMTF '''
iterations = 500
init_S = 'random'
init_FG = 'kmeans'
K, L = 10, 10

alpha, beta = 1., 1.
lambdaF = 1.
lambdaS = 1.
lambdaG = 1.
priors = {
    'alpha': alpha,
    'beta': beta,
    'lambdaF': lambdaF,
    'lambdaS': lambdaS,
    'lambdaG': lambdaG
}
''' Run the method and time it. '''
time_start = time.time()

BNMTF = bnmtf_gibbs(R, M, K, L, priors)
BNMTF.initialise(init_FG=init_FG, init_S=init_S)
BNMTF.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)
Exemple #3
0
    'lambdaF': lambdaF,
    'lambdaS': lambdaS,
    'lambdaG': lambdaG
}

no_folds = 10
file_performance = 'results/bnmtf.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. '''
    BNMTF = bnmtf_gibbs(R=R_gdsc, M=train, K=K, L=L, priors=priors)
    BNMTF.initialise(init_S=init_S, init_FG=init_FG)
    BNMTF.run(iterations=iterations)
    R_pred = BNMTF.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)