Exemple #1
0
def test_PFN_required(input_dim, Phi_sizes, F_sizes):
    n, m = 50, 10
    X_train = np.random.rand(n, m, input_dim)
    Y_train = np.random.rand(n, 2)
    pfn = archs.PFN(input_dim=input_dim,
                    Phi_sizes=Phi_sizes,
                    F_sizes=F_sizes,
                    summary=False)
    pfn.fit(X_train, Y_train, epochs=1, batch_size=10)
    pfn.inputs, pfn.latent, pfn.weights, pfn.outputs, pfn.Phi, pfn.F
Exemple #2
0
def test_PFN_required(nglobal):
    n, m = 50, 10
    X_train = [np.random.rand(n, m, 3), np.random.rand(n, nglobal)]
    Y_train = np.random.rand(n, 2)
    X_val = [np.random.rand(n // 10, m, 3), np.random.rand(n // 10, nglobal)]
    Y_val = np.random.rand(n // 10, 2)
    pfn = archs.PFN(input_dim=3,
                    Phi_sizes=[10],
                    F_sizes=[10],
                    num_global_features=nglobal,
                    summary=False)
    hist = pfn.fit(X_train,
                   Y_train,
                   epochs=1,
                   batch_size=5,
                   validation_data=(X_val, Y_val))
    pfn._global_feature_tensor
Exemple #3
0
def test_PFN_masking(mask_val):
    n, m1, m2 = (50, 10, 20)
    input_dim = 3

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

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

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

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

    kf = K.function(inputs=pfn.inputs, outputs=pfn.latent)
    pure_mask = kf([0 * X_test + mask_val])[0]
    assert epsilon_diff(pure_mask, 0, 10**-15)