Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TO_REVIEW] ConditionalTransferableComponentsAdapter Implementation #137

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following algorithms are currently implemented.
- Sample reweighting methods (Gaussian [1], Discriminant [2], KLIEPReweight [3],
DensityRatio [4], TarS [21], KMMReweight [23])
- Sample mapping methods (CORAL [5], Optimal Transport DA OTDA [6], LinearMonge [7], LS-ConS [21])
- Subspace methods (SubspaceAlignment [8], TCA [9], Transfer Subspace Learning [27])
- Subspace methods (SubspaceAlignment [8], TCA [9], Transfer Subspace Learning [27], CTC [29])
- Other methods (JDOT [10], DASVM [11], OT Label Propagation [28])

Any methods that can be cast as an adaptation of the input data can be used in one of two ways:
Expand Down Expand Up @@ -207,4 +207,6 @@ The library is distributed under the 3-Clause BSD license.

[27] S. Si, D. Tao and B. Geng. In IEEE Transactions on Knowledge and Data Engineering, (2010) [Bregman Divergence-Based Regularization for Transfer Subspace Learning](https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=4118b4fc7d61068b9b448fd499876d139baeec81)

[28] Solomon, J., Rustamov, R., Guibas, L., & Butscher, A. (2014, January). [Wasserstein propagation for semi-supervised learning](https://proceedings.mlr.press/v32/solomon14.pdf). In International Conference on Machine Learning (pp. 306-314). PMLR.
[28] Solomon, J., Rustamov, R., Guibas, L., & Butscher, A. (2014, January). [Wasserstein propagation for semi-supervised learning](https://proceedings.mlr.press/v32/solomon14.pdf). In International Conference on Machine Learning (pp. 306-314). PMLR.

[29] Gong, M., Zhang, K., Liu, T., Tao, D., Glymour, C., & Scholkopf, B. (2016). [Domain Adaptation with Conditional Transferable Components](https://proceedings.mlr.press/v48/gong16.pdf). JMLR workshop and conference proceedings, 48, 2839-2848.
2 changes: 2 additions & 0 deletions docs/source/all.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ DAEstimators with adapters (Pipeline):
SubspaceAlignment
TransferComponentAnalysis
TransferJointMatching
ConditionalTransferableComponents
CORAL
OTMapping
EntropicOTMapping
Expand All @@ -81,6 +82,7 @@ Adapters:
TransferComponentAnalysisAdapter
TransferJointMatchingAdapter
TransferSubspaceLearning
ConditionalTransferableComponentsAdapter
CORALAdapter
OTMappingAdapter
EntropicOTMappingAdapter
Expand Down
28 changes: 28 additions & 0 deletions examples/methods/plot_subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Author: Ruben Bueno <ruben.bueno@polytechnique.edu>
# Antoine Collas <contact@antoinecollas.fr>
# Oleksii Kachaiev <kachayev@gmail.com>
# Yanis Lalou <yanis.lalou@polytechnique.edu>
#
# License: BSD 3-Clause
# sphinx_gallery_thumbnail_number = 4
Expand All @@ -21,6 +22,7 @@
from sklearn.svm import SVC

from skada import (
ConditionalTransferableComponents,
SubspaceAlignment,
TransferComponentAnalysis,
TransferJointMatching,
Expand All @@ -46,6 +48,10 @@
# * :ref:`Transfer Component Analysis<Illustration of the Transfer Component
# Analysis method>`
# * :ref:`Transfer Joint Matching<Illustration of the Transfer Joint Matching method>`
# * :ref:`Transfer Subspace Learning
# <Illustration of the Transfer Subspace Learning method>`
# * :ref:`Conditional Transferable Components
# <Illustration of the Conditional Transferable Components method>`


base_classifier = SVC()
Expand Down Expand Up @@ -374,6 +380,28 @@ def plot_subspace_and_classifier(
clf.fit(X, y, sample_domain=sample_domain)
plot_subspace_and_classifier(clf, "TransferSubspaceLearning")

# %%
# Illustration of the Conditional Transferable Components method
# ------------------------------------------
#
# The objective of Conditional Transferable Components (CTC) is to
# learn domain-invariant representations by disentangling the data
# representation into domain-specific and domain-invariant components.
# By doing so, CTC enables the transfer of knowledge from the source domain
# to the target domain while mitigating the effects of domain shift.
#
# See [29] for details:
#
# .. [29] Gong, M., Zhang, K., Liu, T., Tao,
# D., Glymour, C., & Scholkopf, B. (2016).
# Domain Adaptation with Conditional Transferable Components.
# JMLR workshop and conference proceedings, 48, 2839-2848.
#

clf = ConditionalTransferableComponents(n_components=1)
clf.fit(X, y, sample_domain=sample_domain)
plot_subspace_and_classifier(clf, "ConditionalTransferableComponents")


# %%
# Comparison of score between subspace methods:
Expand Down
3 changes: 3 additions & 0 deletions examples/plot_method_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from skada import (
CORAL,
ClassRegularizerOTMapping,
ConditionalTransferableComponents,
DensityReweight,
DiscriminatorReweight,
EntropicOTMapping,
Expand Down Expand Up @@ -58,6 +59,7 @@
"Subspace Alignment",
"TCA",
"TSL",
"CTC",
"OT mapping",
"Entropic OT mapping",
"Class Reg. OT mapping",
Expand All @@ -82,6 +84,7 @@
SubspaceAlignment(base_estimator=SVC(), n_components=1),
TransferComponentAnalysis(base_estimator=SVC(), n_components=1, mu=0.5),
TransferSubspaceLearning(base_estimator=SVC(), n_components=1),
ConditionalTransferableComponents(base_estimator=SVC(), n_components=1),
OTMapping(base_estimator=SVC()),
EntropicOTMapping(base_estimator=SVC()),
ClassRegularizerOTMapping(base_estimator=SVC()),
Expand Down
4 changes: 4 additions & 0 deletions skada/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
TransferJointMatchingAdapter,
TransferSubspaceLearning,
TransferSubspaceLearningAdapter,
ConditionalTransferableComponents,
ConditionalTransferableComponentsAdapter,
)
from ._ot import (
solve_jdot_regression,
Expand Down Expand Up @@ -116,6 +118,8 @@
"TransferJointMatching",
"TransferSubspaceLearningAdapter",
"TransferSubspaceLearning",
"ConditionalTransferableComponentsAdapter",
"ConditionalTransferableComponents",

"DASVMClassifier",
"solve_jdot_regression",
Expand Down
Loading
Loading