Esempio n. 1
0
def test_EFN_masking(mask_val):
    n, m1, m2 = (50, 10, 20)
    input_dim = 3

    X_train = [np.random.rand(n, m1), np.random.rand(n, m1, input_dim)]
    y_train = np.random.rand(n, 2)

    efn = archs.EFN(input_dim=input_dim,
                    Phi_sizes=[10],
                    F_sizes=[10],
                    mask_val=mask_val)
    efn.fit(X_train, y_train, epochs=1)

    X_test = [np.random.rand(n, m2), np.random.rand(n, m2, input_dim)]
    X_test_mask = [
        np.concatenate((X_test[0], mask_val * np.ones((n, 5))), axis=1),
        np.concatenate((X_test[1], mask_val * np.ones((n, 5, input_dim))),
                       axis=1)
    ]

    assert epsilon_diff(efn.predict(X_test), efn.predict(X_test_mask), 10**-15)

    kf = K.function(inputs=efn.inputs, outputs=efn.latent)
    pure_mask = kf([0 * X_test[0] + mask_val, 0 * X_test[1] + mask_val])[0]
    assert epsilon_diff(pure_mask, 0, 10**-15)
Esempio n. 2
0
def test_EFN_global_features(nglobal):
    n, m = 50, 10
    X_train = [
        np.random.rand(n, m),
        np.random.rand(n, m, 2),
        np.random.rand(n, nglobal)
    ]
    Y_train = np.random.rand(n, 2)
    X_val = [
        np.random.rand(n // 10, m),
        np.random.rand(n // 10, m, 2),
        np.random.rand(n // 10, nglobal)
    ]
    Y_val = np.random.rand(n // 10, 2)
    efn = archs.EFN(input_dim=2,
                    Phi_sizes=[10],
                    F_sizes=[10],
                    num_global_features=nglobal,
                    summary=False)
    hist = efn.fit(X_train,
                   Y_train,
                   epochs=1,
                   batch_size=5,
                   validation_data=(X_val, Y_val))
    efn._global_feature_tensor
Esempio n. 3
0
def test_EFN_required(input_dim, Phi_sizes, F_sizes):
    n, m = 50, 10
    X_train = [np.random.rand(n, m), np.random.rand(n, m, input_dim)]
    Y_train = np.random.rand(n, 2)
    efn = archs.EFN(input_dim=input_dim,
                    Phi_sizes=Phi_sizes,
                    F_sizes=F_sizes,
                    summary=False)
    efn.fit(X_train, Y_train, epochs=1, batch_size=10)
    efn.inputs, efn.latent, efn.weights, efn.outputs, efn.Phi, efn.F
Esempio n. 4
0
def test_EFN_modelcheck(model_path, save_while_training, save_weights_only,
                        modelcheck_opts):
    n, m = 50, 10
    X_train = [np.random.rand(n, m), np.random.rand(n, m, 2)]
    Y_train = np.random.rand(n, 2)
    X_val = [np.random.rand(n // 10, m), np.random.rand(n // 10, m, 2)]
    Y_val = np.random.rand(n // 10, 2)
    efn = archs.EFN(input_dim=2,
                    Phi_sizes=[10],
                    F_sizes=[10],
                    summary=False,
                    filepath=model_path,
                    save_while_training=save_while_training,
                    save_weights_only=save_weights_only,
                    modelcheck_opts=modelcheck_opts)
    hist = efn.fit(X_train,
                   Y_train,
                   epochs=2,
                   batch_size=10,
                   validation_data=[X_val, Y_val])