Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 28 additions & 6 deletions .github/changelog-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,53 @@
"template": "#{{CHANGELOG}}\n\n#### Other Changes\n\n#{{UNCATEGORIZED}}",
"pr_template": "- #{{TITLE}} ([##{{NUMBER}}](#{{URL}}))",
"empty_template": "- No pull requests were merged since the last release.",
"ignore_labels": ["dependabot", "bot", "ci"],
"ignore_labels": [
"dependabot",
"bot",
"ci"
],
"categories": [
{
"title": "#### New Features",
"labels": ["feature", "enhancement"],
"labels": [
"feature",
"enhancement"
],
"consume": true
},
{
"title": "#### Bug Fixes",
"labels": ["bug", "bugfix"],
"labels": [
"bug",
"bugfix"
],
"consume": true
},
{
"title": "#### Code Improvements",
"labels": ["improvements", "refactor", "refactoring"],
"labels": [
"improvements",
"refactor",
"refactoring"
],
"consume": true
},
{
"title": "#### Documentation",
"labels": ["documentation", "docs", "doc"],
"labels": [
"documentation",
"docs",
"doc"
],
"consume": true
},
{
"title": "#### Tests",
"labels": ["tests", "testing", "test"],
"labels": [
"tests",
"testing",
"test"
],
"consume": true
}
]
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The package is part of the [PyKale](https://github.com/pykale/pykale) ecosystem
- Dimension reduction for multiview tensor data:
- Multilinear Principal Component Analysis (`MPCA`) [[1](#references)]
- Transferable / generalizable feature extraction across domains or groups:
- Correlation Alignment (`CORAL`) [[13](#references)]
- Transfer Component Analysis (`TCA`) [[2](#references)]
- Joint Distribution Adaptation (`JDA`) [[3](#references)]
- Balanced Distribution Adaptation (`BDA`) [[4](#references)]
Expand Down Expand Up @@ -97,14 +98,15 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed contribution guidelines.
### Public API

```python
from kalelinear.transformer import BDA, JDA, MIDA, MPCA, TCA
from kalelinear.transformer import BDA, CORAL, JDA, MIDA, MPCA, TCA
from kalelinear.estimator import ARRLS, ARSVM, CoIRLS, CoIRSVM, GSDA, LapRLS, LapSVM
```

Worked examples for the main transformers and estimators are collected in
[Tutorials](TUTORIALS.md):

- Learn a domain-invariant embedding with TCA
- Align source and target features with CORAL
- Use MIDA with categorical covariates
- Extract common and individual features across groups with CIFE or AJIVE
- Train a domain adaptation classifier (ARSVM, ARRLS)
Expand Down Expand Up @@ -136,6 +138,8 @@ Worked examples for the main transformers and estimators are collected in

[12] Feng, Q., Jiang, M., Hannig, J. and Marron, J.S., 2018. [Angle-based joint and individual variation explained](https://www.sciencedirect.com/science/article/pii/S0047259X1730204X). _Journal of Multivariate Analysis_, 166, pp.241-265.

[13] Sun, B., Feng, J. and Saenko, K., 2016. [Return of frustratingly easy domain adaptation](https://ojs.aaai.org/index.php/AAAI/article/view/10306). In _Proceedings of the AAAI Conference on Artificial Intelligence_ (Vol. 30, No. 1, pp. 2058-2065).

## Other open domain adaptation repositories

- [POT: Python Optimal Transport](https://github.com/rflamary/POT)
Expand Down
33 changes: 33 additions & 0 deletions TUTORIALS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,39 @@ TCA, JDA, and BDA take domain labels through `covariates`. They do not accept
separate source and target arrays; stack samples into one array and use
`target_covariate` to identify the target domain.

### Align Source and Target Features with CORAL

CORAL is an asymmetric domain alignment method: it whitens the source
covariance and recolors it with the target covariance. As with TCA, pass all
samples in one array with binary domain labels. `fit_transform` centers each
domain by its own mean, aligns the source samples, and leaves the target
samples in the same centered space.

```python
import numpy as np
from kalelinear.transformer import CORAL

X = np.array(
[
[-2.0, -1.8],
[-1.8, -2.1],
[1.9, 1.7],
[2.1, 2.0],
[-1.4, -1.2],
[-1.2, -1.1],
[1.2, 1.1],
[1.4, 1.3],
]
)
domain_labels = np.array([0, 0, 0, 0, 1, 1, 1, 1])

transformer = CORAL()
z = transformer.fit_transform(X, covariates=domain_labels, target_covariate=1)

z_source = z[domain_labels == 0]
z_target = z[domain_labels == 1]
```

### Use MIDA with Categorical Domain Covariates

```python
Expand Down
5 changes: 5 additions & 0 deletions docs/source/api_transformers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ The transformer classes are also available through the PyKale-compatible alias
:undoc-members:
:show-inheritance:

.. autoclass:: CORAL
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: MIDA
:members:
:undoc-members:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ covariates, side information, or unlabeled target samples.
Main Features
-------------

* Transformer models for learning feature embeddings: MPCA, TCA, JDA, BDA,
MIDA, CIFE, and AJIVE.
* Transformer models for learning feature embeddings: CORAL, MPCA, TCA, JDA,
BDA, MIDA, CIFE, and AJIVE.
* Estimator models for classification and adaptation: LapSVM, LapRLS, ARSVM,
ARRLS, CoIRSVM, CoIRLS, and GSDA.
* NumPy-compatible inputs and outputs.
Expand Down
34 changes: 34 additions & 0 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,40 @@ label is the target domain.
z_source = z[domain_labels == 0]
z_target = z[domain_labels == 1]

Align Source and Target Features with CORAL
-------------------------------------------

CORAL is an asymmetric domain alignment method: it whitens the source
covariance and recolors it with the target covariance. As with TCA, pass all
samples in one array with binary domain labels. ``fit_transform`` centers each
domain by its own mean, aligns the source samples, and leaves the target
samples in the same centered space.

.. code-block:: python

import numpy as np
from kalelinear.transformer import CORAL

X = np.array(
[
[-2.0, -1.8],
[-1.8, -2.1],
[1.9, 1.7],
[2.1, 2.0],
[-1.4, -1.2],
[-1.2, -1.1],
[1.2, 1.1],
[1.4, 1.3],
]
)
domain_labels = np.array([0, 0, 0, 0, 1, 1, 1, 1])

transformer = CORAL()
z = transformer.fit_transform(X, covariates=domain_labels, target_covariate=1)

z_source = z[domain_labels == 0]
z_target = z[domain_labels == 1]

Use MIDA with Categorical Covariates
------------------------------------

Expand Down
7 changes: 4 additions & 3 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Usage
Domain Adaptation Transformers
------------------------------

TCA, JDA, and BDA take all samples in a single input array and receive domain
labels through ``covariates``. Use ``target_covariate`` to identify which domain
label is the target domain.
TCA, JDA, BDA, and CORAL take all samples in a single input array and receive
domain labels through ``covariates``. Use ``target_covariate`` to identify
which domain label is the target domain. CORAL is asymmetric: after fitting, it
aligns source samples to the target covariance and centers target samples.

.. code-block:: python

Expand Down
4 changes: 2 additions & 2 deletions kalelinear/embed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Embedding models exposed with a PyKale-style API."""

from kalelinear.transformer import AJIVE, BDA, CIFE, JDA, MIDA, MPCA, TCA
from kalelinear.transformer import AJIVE, BDA, CIFE, CORAL, JDA, MIDA, MPCA, TCA

__all__ = ["TCA", "JDA", "BDA", "MIDA", "MPCA", "CIFE", "AJIVE"]
__all__ = ["TCA", "JDA", "BDA", "CORAL", "MIDA", "MPCA", "CIFE", "AJIVE"]
2 changes: 2 additions & 0 deletions kalelinear/transformer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from kalelinear.transformer._ajive import AJIVE
from kalelinear.transformer._cife import CIFE
from kalelinear.transformer._coral import CORAL
from kalelinear.transformer._jda import BDA, JDA
from kalelinear.transformer._mida import MIDA
from kalelinear.transformer._mpca import MPCA
Expand All @@ -9,6 +10,7 @@
"TCA",
"JDA",
"BDA",
"CORAL",
"MIDA",
"MPCA",
"CIFE",
Expand Down
Loading
Loading