Exemplo n.º 1
0
def test_utils_data():
    # Load ENZYMES because we use it also in datasets tests
    A_list, X_list, y = tud.load_data('ENZYMES', clean=True)

    # Test numpy to batch
    X_batch, A_batch = numpy_to_batch(X_list, A_list)
    assert X_batch.ndim == 3
    assert A_batch.ndim == 3
    assert X_batch.shape[0] == A_batch.shape[0]
    assert X_batch.shape[1] == A_batch.shape[1] == A_batch.shape[2]

    # Test numpy to disjoint
    X_disj, A_disj, I_disj = numpy_to_disjoint(X_list, A_list)
    assert X_disj.ndim == 2
    assert A_disj.ndim == 2
    assert X_disj.shape[0] == A_disj.shape[0] == A_disj.shape[1]
Exemplo n.º 2
0
    return loss


################################################################################
# FIT MODEL
################################################################################
current_batch = 0
model_loss = 0
batches_in_epoch = np.ceil(len(A_tr) / batch_size)

print('Fitting model')
batches_train = batch_iterator([X_tr, A_tr, E_tr, y_tr],
                               batch_size=batch_size,
                               epochs=epochs)
for b in batches_train:
    X_, A_, E_, I_ = numpy_to_disjoint(*b[:-1])
    A_ = ops.sp_matrix_to_sp_tensor(A_)
    y_ = b[-1]
    outs = train_step(X_, A_, E_, I_, y_)

    model_loss += outs.numpy()
    current_batch += 1
    if current_batch == batches_in_epoch:
        print('Loss: {}'.format(model_loss / batches_in_epoch))
        model_loss = 0
        current_batch = 0

################################################################################
# EVALUATE MODEL
################################################################################
print('Testing model')
Exemplo n.º 3
0
    acc = acc_fn(y_, predictions)
    return loss, acc


################################################################################
# FIT MODEL
################################################################################
current_batch = 0
model_lss = model_acc = 0
batches_in_epoch = np.ceil(len(a_train) / batch_size)

print('Fitting model')
batches_train = batch_iterator([x_train, a_train, y_train],
                               batch_size=batch_size, epochs=epochs)
for b in batches_train:
    x_, a_, i_ = numpy_to_disjoint(*b[:-1])
    a_ = ops.sp_matrix_to_sp_tensor(a_)
    y_ = b[-1]
    lss, acc = train_step(x_, a_, i_, y_)

    model_lss += lss.numpy()
    model_acc += acc.numpy()
    current_batch += 1
    if current_batch == batches_in_epoch:
        model_lss /= batches_in_epoch
        model_acc /= batches_in_epoch
        print('Loss: {}. Acc: {}'.format(model_lss, model_acc))
        model_lss = model_acc = 0
        current_batch = 0

################################################################################