Completed
Push — master ( 582254...17fb6a )
by Wouter
03:58
created

test_subspace_alignment()   A

Complexity

Conditions 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
dl 0
loc 9
ccs 8
cts 8
cp 1
crap 4
rs 9.2
1 1
import numpy as np
2 1
import numpy.random as rnd
3 1
from libtlda.suba import SubspaceAlignedClassifier
4
5
6 1
def test_init():
7
    """Test for object type."""
8 1
    clf = SubspaceAlignedClassifier()
9 1
    assert type(clf) == SubspaceAlignedClassifier
10 1
    assert not clf.is_trained
11
12
13 1
def test_subspace_alignment():
14
    """Test the alignment between datasets."""
15 1
    X = rnd.randn(100, 10)
16 1
    Z = np.dot(rnd.randn(100, 10), np.diag(np.arange(1, 11)))
17 1
    clf = SubspaceAlignedClassifier()
18 1
    V, CX, CZ = clf.subspace_alignment(X, Z, num_components=3)
19 1
    assert not np.any(np.isnan(V))
20 1
    assert CX.shape[1] == 3
21 1
    assert CZ.shape[1] == 3
22
23
24 1
def test_fit():
25
    """Test for fitting the model."""
26 1
    X = rnd.randn(10, 2)
27 1
    y = np.hstack((-np.ones((5,)), np.ones((5,))))
28 1 View Code Duplication
    Z = rnd.randn(10, 2) + 1
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
29 1
    clf = SubspaceAlignedClassifier()
30 1
    clf.fit(X, y, Z)
31 1
    assert clf.is_trained
32
33
34 1
def test_predict():
35
    """Test for making predictions."""
36 1
    X = rnd.randn(10, 2)
37 1
    y = np.hstack((-np.ones((5,)), np.ones((5,))))
38 1
    Z = rnd.randn(10, 2) + 1
39 1
    clf = SubspaceAlignedClassifier()
40 1
    clf.fit(X, y, Z)
41 1
    u_pred = clf.predict(Z)
42 1
    labels = np.unique(y)
43
    assert len(np.setdiff1d(np.unique(u_pred), labels)) == 0
44