Skip to content

Commit 85a7b92

Browse files
Update docs
1 parent 40c1920 commit 85a7b92

26 files changed

+443
-8
lines changed

adapt/feature_based/_ccsa.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,38 @@ def pairwise_X(X, Y):
3131
@make_insert_doc(["encoder", "task"], supervised=True)
3232
class CCSA(BaseAdaptDeep):
3333
"""
34-
CCSA :
34+
CCSA : Classification and Contrastive Semantic Alignment
35+
36+
CCSA is a supervised feature based method for classification.
37+
38+
It aims at producing an encoded space where the distances between
39+
source and target pairs from the same label are minized, whereas
40+
the distances between pairs from different labels are maximized.
41+
42+
The optimization can be written as follows:
43+
44+
.. math::
45+
46+
\mathcal{L}_{CCSA} = \\gamma \mathcal{L}_{task}(h \circ g) +
47+
(1-\\gamma) (\mathcal{L}_{SA}(g) + \mathcal{L}_{S}(g))
48+
49+
Where:
50+
51+
.. math::
52+
53+
\mathcal{L}_{SA}(g) = \sum_{i, j; \; y^s_i = y^t_j} || g(x^s_i) - g(x^t_j) ||^2
54+
55+
.. math::
56+
57+
\mathcal{L}_{S}(g) = \sum_{i, j; \; y^s_i \\neq y^t_j} \max(0, m - || g(x^s_i) - g(x^t_j) ||^2)
58+
59+
With:
60+
61+
- :math:`(x^s_i, y^s_i)` the labeled source data (:math:`y^s_i` gives the label)
62+
- :math:`(x^t_i, y^t_i)` the labeled target data
63+
- :math:`g, h` are respectively the **encoder** and the **task** networks
64+
- :math:`\\gamma` is the trade-off parameter.
65+
- :math:`m` is the margin parameter.
3566
3667
Parameters
3768
----------
@@ -59,6 +90,12 @@ class CCSA(BaseAdaptDeep):
5990
history of the losses and metrics across the epochs.
6091
If ``yt`` is given in ``fit`` method, target metrics
6192
and losses are recorded too.
93+
94+
References
95+
----------
96+
.. [1] `[1] <https://arxiv.org/abs/1709.10190>`_ S. Motiian, M. Piccirilli, \
97+
D. A Adjeroh, and G. Doretto. "Unified deep supervised domain adaptation and \
98+
generalization". In ICCV 2017.
6299
"""
63100

64101
def __init__(self,

adapt/feature_based/_fe.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ def transform(self, X, domain="tgt"):
188188
"""
189189
Return augmented features for X.
190190
191+
In single source:
192+
193+
- If ``domain="src"``, the method returns the array (X, **0**, X).
194+
- If ``domain="tgt"``, the method returns the array (**0**, X, X).
195+
196+
With **0** the array of same shape as X with zeros everywhere.
197+
198+
In single Multi-source:
199+
200+
- If ``domain="src_%i"%i``, the method returns the array
201+
(X, [X]*i, **0**, [X]*(n_sources-i)).
202+
- If ``domain="tgt"``, the method returns the array (**0**, [X]*(n_sources+1)).
203+
191204
Parameters
192205
----------
193206
X : array

adapt/feature_based/_fmmd.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class fMMD(BaseAdaptEstimator):
111111
Choose the kernel between
112112
['linear', 'rbf', 'poly'].
113113
The kernels are computed as follows:
114+
114115
- kernel = linear::
115116
116117
k(X, Y) = <X, Y>
@@ -148,6 +149,12 @@ class fMMD(BaseAdaptEstimator):
148149
--------
149150
CORAL
150151
FE
152+
153+
References
154+
----------
155+
.. [1] `[1] <https://www.cs.cmu.edu/afs/cs/Web/People/jgc/publication\
156+
/Feature%20Selection%20for%20Transfer%20Learning.pdf>`_ S. Uguroglu and J. Carbonell. \
157+
"Feature selection for transfer learning." In ECML PKDD. 2011.
151158
"""
152159

153160
def __init__(self,

adapt/feature_based/_mcd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def train_step(self, data):
225225
def predict_avg(self, X):
226226
"""
227227
Return the average predictions between
228-
task_ and discriminator_ networks.
228+
``task_`` and ``discriminator_`` networks.
229229
230230
Parameters
231231
----------

adapt/feature_based/_sa.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SA(BaseAdaptEstimator):
2222
to the input dimension of ``X``
2323
2424
Attributes
25-
----------
25+
----------
2626
estimator_ : object
2727
Fitted estimator.
2828
@@ -34,6 +34,12 @@ class SA(BaseAdaptEstimator):
3434
3535
M_ : numpy array
3636
Alignment matrix
37+
38+
References
39+
----------
40+
.. [1] `[1] <https://arxiv.org/abs/1409.5241>`_ B. Fernando, A. Habrard, \
41+
M. Sebban, and T. Tuytelaars. "Unsupervised visual domain adaptation using \
42+
subspace alignment". In ICCV, 2013.
3743
"""
3844

3945
def __init__(self,

adapt/instance_based/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ._tradaboost import TrAdaBoost, TrAdaBoostR2, TwoStageTrAdaBoostR2
88
from ._wann import WANN
99
from ._ldm import LDM
10-
from ._nnw import NearestNeighborsWeighting
10+
from ._nearestneighborsweighting import NearestNeighborsWeighting
1111

12-
__all__ = ["KLIEP", "KMM", "TrAdaBoost", "TrAdaBoostR2",
12+
__all__ = ["LDM", "KLIEP", "KMM", "TrAdaBoost", "TrAdaBoostR2",
1313
"TwoStageTrAdaBoostR2", "WANN", "NearestNeighborsWeighting"]

adapt/instance_based/_ldm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ class LDM(BaseAdaptEstimator):
2020
2121
.. math::
2222
23-
\min_{||w||_1 = 1, w>0} \max{||u||=1} |u^T M(w) u|
23+
\min_{||w||_1 = 1, w>0} \max_{||u||=1} |u^T M(w) u|
2424
2525
Where:
26+
2627
- :math:`M(w) = (1/n) X_T^T X_T - X^T_S diag(w) X_S`
2728
- :math:`X_S, X_T` are respectively the source dataset
28-
and the target dataset of size :math:`n`
29+
and the target dataset of size :math:`m` and :math:`n`
2930
3031
Parameters
3132
----------

adapt/instance_based/_nnw.py renamed to adapt/instance_based/_nearestneighborsweighting.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ class NearestNeighborsWeighting(BaseAdaptEstimator):
2525
2626
algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, (default='auto')
2727
Algorithm used to compute the nearest neighbors:
28+
2829
- 'ball_tree' will use ``BallTree``
2930
- 'kd_tree' will use ``KDTree``
3031
- 'brute' will use a brute-force search.
3132
- 'auto' will attempt to decide the most appropriate algorithm
3233
based on the values passed to ``fit`` method.
34+
3335
Note: fitting on sparse input will override the setting of
3436
this parameter, using brute force.
3537
@@ -74,6 +76,11 @@ class NearestNeighborsWeighting(BaseAdaptEstimator):
7476
--------
7577
KMM
7678
KLIEP
79+
80+
References
81+
----------
82+
.. [1] `[1] <https://arxiv.org/pdf/2102.02291.pdf>`_ \
83+
M. Loog. "Nearest neighbor-based importance weighting". In MLSP 2012.
7784
"""
7885

7986
def __init__(self,

adapt/parameter_based/_finetuning.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ class FineTuning(BaseAdaptDeep):
1414
fitted first using the ``pretrain`` parameter. The layers
1515
to train in the encoder can be set via the parameter ``training``.
1616
17+
.. figure:: ../_static/images/regulartransfer.png
18+
:align: center
19+
20+
Transferring parameters of a CNN pretrained on Imagenet
21+
(source: [1])
22+
1723
Parameters
1824
----------
1925
training : bool or list of bool, optional (default=True)
@@ -40,6 +46,13 @@ class FineTuning(BaseAdaptDeep):
4046
history_ : dict
4147
history of the losses and metrics across the epochs
4248
of the network training.
49+
50+
References
51+
----------
52+
.. [1] `[1] <https://hal.inria.fr/hal-00911179v1/document>`_ \
53+
Oquab M., Bottou L., Laptev I., Sivic J. "Learning and \
54+
transferring mid-level image representations using convolutional \
55+
neural networks". In CVPR, 2014.
4356
"""
4457

4558
def __init__(self,

src_docs/_templates/layout.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,23 @@
2020
<li class="toctree-l1"><a class="reference internal" href="{{ pathto("contents") }}{{ contents }}{{ "adapt-feature-based" }}">Feature-based</a><ul>
2121
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.FE") }}">FE</a></li>
2222
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.CORAL") }}">CORAL</a></li>
23+
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.SA") }}">SA</a></li>
24+
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.fMMD") }}">fMMD</a></li>
2325
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.DeepCORAL") }}">DeepCORAL</a></li>
2426
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.DANN") }}">DANN</a></li>
2527
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.ADDA") }}">ADDA</a></li>
2628
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.WDGRL") }}">WDGRL</a></li>
2729
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.CDAN") }}">CDAN</a></li>
2830
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.MCD") }}">MCD</a></li>
2931
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.MDD") }}">MDD</a></li>
32+
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.feature_based.CCSA") }}">CCSA</a></li>
3033
</ul>
3134
</li>
3235
<li class="toctree-l1"><a class="reference internal" href="{{ pathto("contents") }}{{ contents }}{{ "adapt-instance-based" }}">Instance-based</a><ul>
36+
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.instance_based.LDM") }}">LDM</a></li>
3337
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.instance_based.KLIEP") }}">KLIEP</a></li>
3438
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.instance_based.KMM") }}">KMM</a></li>
39+
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.instance_based.NearestNeighborsWeighting") }}">NearestNeighborsWeighting</a></li>
3540
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.instance_based.TrAdaBoost") }}">TrAdaBoost</a></li>
3641
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.instance_based.TrAdaBoostR2") }}">TrAdaBoostR2</a></li>
3742
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.instance_based.TwoStageTrAdaBoostR2") }}">TwoStageTrAdaBoostR2</a></li>
@@ -42,9 +47,11 @@
4247
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.parameter_based.RegularTransferLR") }}">RegularTransferLR</a></li>
4348
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.parameter_based.RegularTransferLC") }}">RegularTransferLC</a></li>
4449
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.parameter_based.RegularTransferNN") }}">RegularTransferNN</a></li>
50+
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.parameter_based.FineTuning") }}">FineTuning</a></li>
4551
</ul>
4652
</li>
4753
<li class="toctree-l1"><a class="reference internal" href="{{ pathto("contents") }}{{ contents }}{{ "adapt-metrics" }}">Metrics</a><ul>
54+
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.metrics.make_uda_scorer") }}">make_uda_scorer</a></li>
4855
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.metrics.cov_distance") }}">cov_distance</a></li>
4956
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.metrics.j_score") }}">j_score</a></li>
5057
<li class="toctree-l2"><a class="reference internal" href="{{ pathto("generated/adapt.metrics.linear_discrepancy") }}">linear_discrepancy</a></li>

0 commit comments

Comments
 (0)