-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.py
48 lines (37 loc) · 1.31 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 13 21:35:44 2015
@author: alexis
"""
import dml
import unittest
import numpy as np
class TestDML(unittest.TestCase):
def setUp(self):
self.callback = False
self.verbose = False
def test_pcca(self):
rng = np.random.RandomState(1)
X = rng.randn(10, 20)
pairs = [(i, i + 1) for i in range(5)] + [(i, i + 5) for i in range(5)]
labels = np.asarray([1] * 5 + [-1] * 5)
y = np.hstack([pairs, labels[:, np.newaxis]])
callback = dml.CrossValCallback(X, y) if self.callback else None
ml = dml.PCCA(3, callback=callback,
verbose=self.verbose)
ml.fit(X, y)
assert(ml.score(X, y) == 1.0)
def test_kernel_pcca(self):
rng = np.random.RandomState(1)
X = rng.randn(10, 5)
X = np.dot(X, X.T)
pairs = [(i, i + 1) for i in range(5)] + [(i, i + 5) for i in range(5)]
labels = np.asarray([1] * 5 + [-1] * 5)
y = np.hstack([pairs, labels[:, np.newaxis]])
callback = dml.CrossValCallback(X, y) if self.callback else None
ml = dml.PCCA(3, callback=callback, kernel=True,
verbose=self.verbose)
ml.fit(X, y)
assert(ml.score(X, y) == 1.0)
if __name__ == "__main__":
unittest.main()