示例#1
0
def test_partial_equals_full():
    X1, _ = generate_data(10, 3, seed=1)
    X2 = X1 * np.random.normal(0, 1, X1.shape)
    Xs = [X1, X2]
    gcca = GCCA()
    projs_full = gcca.fit(Xs).transform(Xs)
    projs_partial = gcca.partial_fit(Xs, reset=True).transform(Xs)
    assert_almost_equal(np.abs(projs_full), np.abs(projs_partial))
示例#2
0
def test_fit_elbows():
    X, _ = generate_data(10, 3)
    Xs = [X, X]

    gcca = GCCA(n_elbows=2)
    _ = gcca.fit_transform(Xs)

    assert_equal(gcca.ranks_[0], 4)
示例#3
0
def test_max_ranks():
    X, _ = generate_data(10, 3)
    Xs = [X, X]

    gcca = GCCA(n_elbows=2, max_rank=True)
    projs = gcca.fit_transform(Xs)

    assert_equal(gcca.ranks_[0], 4)
示例#4
0
def test_fit_view_idx():
    n = 2
    Xs = _get_Xs(n)

    gcca = GCCA(fraction_var=0.9).fit(Xs)
    projs = [gcca.transform(Xs[i], view_idx=i) for i in range(n)]

    dists = _compute_dissimilarity(projs)

    # Checks up to 7 decimal points
    assert_almost_equal(np.zeros((n, n)), dists)
示例#5
0
def test_partial_multistep():
    X1, _ = generate_data(10, 3, seed=1)
    X2 = X1 * np.random.normal(0, 1, X1.shape)
    Xs = [X1, X2]
    gcca = GCCA()
    projs_full = gcca.partial_fit(Xs).transform(Xs)
    projs_partial = gcca.partial_fit(Xs[0], reset=True,
                                     multiview_step=False).partial_fit(
                                         Xs[1],
                                         reset=False,
                                         multiview_step=True).transform(Xs)
    assert_almost_equal(np.abs(projs_full), np.abs(projs_partial))
示例#6
0
def test_fit_sv_tolerance():
    n = 2
    Xs = _get_Xs(n)

    projs = GCCA(sv_tolerance=1).fit_transform(Xs)
    dists = _compute_dissimilarity(projs)

    # Checks up to 7 decimal points
    assert_almost_equal(np.zeros((n, n)), dists)
示例#7
0
def test_fit_tall():
    n = 2
    Xs = _get_Xs(n)

    projs = GCCA(fraction_var=0.9, tall=True).fit_transform(Xs)
    dists = _compute_dissimilarity(projs)

    # Checks up to 7 decimal points
    assert_almost_equal(np.zeros((n, n)), dists)
示例#8
0
# averages from 2x3 windows.

# Load the data
Xs, y = load_UCImultifeature(views=[1, 2, 3])

# Inspect the dataset
print(f'There are {len(Xs)} views.')
print(f'There are {Xs[0].shape[0]} observations')
print(f'The feature sizes are: {[X.shape[1] for X in Xs]}')

###############################################################################
# Embed Views
# ^^^^^^^^^^^

# Create GCCA object and embed the
gcca = GCCA()
Xs_latents = gcca.fit_transform(Xs)

print(f'The feature sizes are: {[X.shape[1] for X in Xs_latents]}')

###############################################################################
# Plot the first two views against each other
# -------------------------------------------
# The top three dimensions from the latents spaces of the profile correlation
# and pixel average views are plotted against each other. However, their latent
# spaces are influenced the the Karhunen-Love coefficients, not plotted.

crossviews_plot(Xs_latents[[0, 2]],
                dimensions=[0, 1, 2],
                labels=y,
                cmap='Set1',
示例#9
0
def test_multiview_step():
    X1, _ = generate_data(10, 3, seed=1)
    gcca = GCCA()
    with pytest.warns(UserWarning):
        projs_partial = gcca.partial_fit(X1)
示例#10
0
def test_no_fit(Xs={"Xs": mat_good}, err=RuntimeError):
    with pytest.raises(err):
        np.random.seed(1)
        GCCA().transform(**Xs)
示例#11
0
def test_bad_inputs(Xs, params, err):
    with pytest.raises(err):
        np.random.seed(1)
        GCCA(**params).fit(**Xs)
示例#12
0
def test_n_jobs():
    X, _ = generate_data(10, 3)
    Xs = [X, X]
    gcca = GCCA(n_elbows=2, n_jobs=-1)
    _ = gcca.fit_transform(Xs)