예제 #1
0
def test_errors():
    cca = CCA()
    with pytest.raises(ValueError):
        cca.fit([train1, train2, train2])

    with pytest.raises(ValueError):
        cca.fit([train1, train2])
        cca.stats([train1, train1, train1])

    with pytest.raises(AssertionError):
        cca.fit([train1, train2])
        _ = cca.stats([train1, train2])

    with pytest.raises(KeyError):
        cca.fit([train1, train2])
        _ = cca.stats([train1, train1], 'FAIL')
예제 #2
0
# Split each dataset into a training set and test set
# (10% of dataset is training data)
train1 = data1[:int(nSamples / 10)]
train2 = data2[:int(nSamples / 10)]
test1 = data1[int(nSamples / 10):]
test2 = data2[int(nSamples / 10):]

n_components = 4

# Initialize CCA
cca = CCA(regs=0.001, n_components=n_components)

# Use the methods to find a CCA mapping and transform the views of data
cca_ft = cca.fit_transform([train1, train2])
cca_f = cca.fit([train1, train2])
cca_t = cca.transform([train1, train2])

# gaussian related data
N = 100
t = np.random.uniform(-np.pi, np.pi, N)
e1 = np.random.normal(0, 0.05, (N, 2))
e2 = np.random.normal(0, 0.05, (N, 2))

x = np.zeros((N, 2))
x[:, 0] = t
x[:, 1] = np.sin(3 * t)
x += e1

y = np.zeros((N, 2))
y[:, 0] = np.exp(t / 4) * np.cos(2 * t)
예제 #3
0
def test_n_components(n_components):
    cca = CCA(n_components=n_components)
    with pytest.raises(ValueError, match="n_components must be an integer"):
        cca = cca.fit([train1, train2])