Skip to content

Commit 714f20b

Browse files
Merge pull request #85 from antoinedemathelin/master
docs: Updates doc and test
2 parents 1c4fce4 + 3ef3cca commit 714f20b

File tree

8 files changed

+763
-2
lines changed

8 files changed

+763
-2
lines changed
71.8 KB
Loading

src_docs/_static/images/fork.png

36.2 KB
Loading

src_docs/_templates/layout.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<ul>
2525
<li class="toctree-l1"><a class="reference internal" href="{{ pathto("map") }}">Choosing the right algorithm</a></li>
2626
<li class="toctree-l1"><a class="reference internal" href="{{ pathto("examples/Quick_start") }}">Quick-Start</a></li>
27+
<li class="toctree-l1"><a class="reference internal" href="{{ pathto("examples/Developer_Guide") }}">Developer Guide</a></li>
2728
</ul>
2829
<p class="caption" role="heading"><span class="caption-text">API Documentation</span></p>
2930
<ul>

src_docs/examples/Developer_Guide.ipynb

Lines changed: 696 additions & 0 deletions
Large diffs are not rendered by default.

tests/test_iwc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test functions for iwn module.
33
"""
44

5+
import numpy as np
56
from sklearn.linear_model import RidgeClassifier
67
from adapt.utils import make_classification_da
78
from adapt.instance_based import IWC
@@ -15,6 +16,9 @@ def test_iwn():
1516
model.fit(Xs, ys);
1617
model.predict(Xt)
1718
model.score(Xt, yt)
19+
w1 = model.predict_weights()
20+
w2 = model.predict_weights(Xs)
21+
assert np.abs(w1-w2).sum() < 10**-5
1822

1923

2024
def test_default_classif():
@@ -23,6 +27,9 @@ def test_default_classif():
2327
model.fit(Xs, ys);
2428
model.predict(Xt)
2529
model.score(Xt, yt)
30+
w1 = model.predict_weights()
31+
w2 = model.predict_weights(Xs)
32+
assert np.abs(w1-w2).sum() < 10**-5
2633

2734

2835
def test_nn_classif():
@@ -32,3 +39,7 @@ def test_nn_classif():
3239
model.fit(Xs, ys);
3340
model.predict(Xt)
3441
model.score(Xt, yt)
42+
w1 = model.predict_weights()
43+
w2 = model.predict_weights(Xs)
44+
assert np.abs(w1-w2).sum() < 10**-5
45+

tests/test_iwn.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from sklearn.linear_model import RidgeClassifier
66
from adapt.utils import make_classification_da
77
from adapt.instance_based import IWN
8+
from adapt.utils import get_default_task
9+
from sklearn.neighbors import KNeighborsClassifier
810

911
Xs, ys, Xt, yt = make_classification_da()
1012

@@ -15,3 +17,21 @@ def test_iwn():
1517
model.score(Xt, yt)
1618
model.predict(Xs)
1719
model.predict_weights(Xs)
20+
21+
22+
def test_iwn_fit_estim():
23+
task = get_default_task()
24+
task.compile(optimizer="adam", loss="mse", metrics=["mae"])
25+
model = IWN(task, Xt=Xt, sigma_init=0.1, random_state=0,
26+
pretrain=True, pretrain__epochs=100, pretrain__verbose=0)
27+
model.fit(Xs, ys)
28+
model.score(Xt, yt)
29+
model.predict(Xs)
30+
model.predict_weights(Xs)
31+
32+
model = IWN(KNeighborsClassifier(), Xt=Xt, sigma_init=0.1, random_state=0,
33+
pretrain=True, pretrain__epochs=100, pretrain__verbose=0)
34+
model.fit(Xs, ys)
35+
model.score(Xt, yt)
36+
model.predict(Xs)
37+
model.predict_weights(Xs)

tests/test_transfertree.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from sklearn.tree import DecisionTreeClassifier
44
from sklearn.ensemble import RandomForestClassifier
55

6+
from adapt.utils import make_classification_da
67
from adapt.parameter_based import TransferTreeClassifier, TransferForestClassifier
78

89
methods = [
@@ -188,4 +189,16 @@ def test_transfer_tree():
188189
print('Testing score transferred model ({}) : {:.3f}'.format(method, score))
189190
clfs.append(transferred_dt.estimator)
190191
#clfs.append(clf_transfer)
191-
scores.append(score)
192+
scores.append(score)
193+
194+
195+
def test_specific():
196+
Xs, ys, Xt, yt = make_classification_da()
197+
198+
src_model = DecisionTreeClassifier()
199+
src_model.fit(Xs, ys)
200+
201+
model = TransferTreeClassifier(src_model)
202+
203+
model.estimator_ = src_model
204+
model._strut(Xt[:0], yt[:0], no_prune_on_cl=True, cl_no_prune=[0], node=3)

tests/test_ulsif.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,31 @@ def test_ulsif():
1111
model.fit(Xs, ys);
1212
model.predict(Xs)
1313
model.score(Xt, yt)
14+
model.predict_weights()
15+
model.predict_weights(Xs)
16+
17+
model = ULSIF(RidgeClassifier(0.), Xt=Xt, kernel="rbf",
18+
lambdas=[0.1, 1., 10.], gamma=[0.1, 1., 10.], random_state=0)
19+
model.fit(Xs, ys);
20+
21+
model = ULSIF(RidgeClassifier(0.), Xt=Xt, kernel="rbf",
22+
lambdas=[0.1, 1., 10.], gamma=[0.1, 1., 10.], random_state=0)
23+
model.fit(Xs[:73], ys[:73]);
1424

1525

1626
def test_rulsif():
1727
model = RULSIF(RidgeClassifier(0.), Xt=Xt, kernel="rbf", alpha=0.1,
1828
lambdas=[0.1, 1., 10.], gamma=[0.1, 1., 10.], random_state=0)
1929
model.fit(Xs[:73], ys[:73]);
2030
model.predict(Xs)
21-
model.score(Xt, yt)
31+
model.score(Xt, yt)
32+
model.predict_weights()
33+
model.predict_weights(Xs)
34+
35+
model = RULSIF(RidgeClassifier(0.), Xt=Xt, kernel="rbf", alpha=0.1,
36+
lambdas=[0.1, 1., 10.], gamma=[0.1, 1., 10.], random_state=0)
37+
model.fit(Xs, ys);
38+
39+
model = RULSIF(RidgeClassifier(0.), Xt=Xt[:73], kernel="rbf", alpha=0.1,
40+
lambdas=[0.1, 1., 10.], gamma=[0.1, 1., 10.], random_state=0)
41+
model.fit(Xs, ys);

0 commit comments

Comments
 (0)