Skip to content

275 feature implementation of coral#278

Open
inarteroger wants to merge 8 commits into
mainfrom
275-feature-implementation-of-coral
Open

275 feature implementation of coral#278
inarteroger wants to merge 8 commits into
mainfrom
275-feature-implementation-of-coral

Conversation

@inarteroger

Copy link
Copy Markdown
Collaborator

Why is this change needed?

Adds the CORAL (CORrelation ALignment) and SubspaceAlignment (SA) transformers to the chemotools.adaptation module. Both are unsupervised linear domain adaptation methods that align target spectral data to a source (reference) domain without requiring labelled target samples. This extends the adaptation module alongside the existing DS, PDS and SST transformers.

Type of change

  • New feature

Description

Implementation of CORAL following the method described in:

Sun, B., Feng, J., & Saenko, K. (2016). Return of Frustratingly Easy Domain Adaptation. Proceedings of the AAAI Conference on Artificial Intelligence, 30(1). https://doi.org/10.1609/aaai.v30i1.10306

Implementation of SubspaceAlignment following the method described in:

Fernando, B., Habrard, A., Sebban, M., & Tuytelaars, T. (2013). Unsupervised Visual Domain Adaptation Using Subspace Alignment. IEEE International Conference on Computer Vision (ICCV). https://doi.org/10.1109/ICCV.2013.368

What was added

  • CORAL transformer in chemotools/adaptation/_coral.py
  • SubspaceAlignment transformer in chemotools/adaptation/_subspace_alignment.py
  • Full sklearn API compliance for both transformers (fit, transform, fit_transform)
  • Identity fallback when X_source=None

Tests added

  • sklearn estimator compliance
  • fit attributes and shape checks
  • boundary and edge case validation
  • Pipeline + GridSearchCV + metadata routing integration

@inarteroger inarteroger requested a review from paucablop May 28, 2026 14:13
@inarteroger inarteroger self-assigned this May 28, 2026
@inarteroger inarteroger added the enhancement New feature or request label May 28, 2026
@inarteroger inarteroger linked an issue May 28, 2026 that may be closed by this pull request
@paucablop paucablop requested review from NusretSalli and Copilot May 28, 2026 16:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unsupervised domain adaptation transformers to chemotools.adaptation, extending the module beyond DS/PDS/SST with CORAL covariance alignment and PCA-based Subspace Alignment.

Changes:

  • Implements CORAL and SubspaceAlignment sklearn-compatible transformers.
  • Exports both transformers from chemotools.adaptation.
  • Adds estimator compliance, numerical, identity-fallback, and pipeline/metadata-routing tests.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
chemotools/adaptation/_coral.py Adds CORAL transformer implementation.
chemotools/adaptation/_subspace_alignment.py Adds SubspaceAlignment transformer implementation.
chemotools/adaptation/__init__.py Exposes the new transformers in the public adaptation API.
chemotools/adaptation/_direct_standardization.py Updates See Also references.
chemotools/adaptation/_piecewise_direct_standardization.py Updates See Also references.
chemotools/adaptation/_spectral_space_transform.py Updates See Also references.
tests/adaptation/test_coral.py Adds tests for CORAL behavior and integration.
tests/adaptation/test_subspace_alignment.py Adds tests for SubspaceAlignment behavior and integration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread chemotools/adaptation/_coral.py Outdated
Comment on lines +208 to +214
# Covariance matrix
self.C_X_ = np.cov(self.X_centered_, rowvar=False, ddof=1) + self.reg * np.eye(
self.n_features_in_
)
self.C_X_source_ = np.cov(
self.X_source_centered_, rowvar=False, ddof=1
) + self.reg * np.eye(self.n_features_in_)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add after validate_data:

if X.shape[0] < 2:
    raise ValueError(
        f"X must have at least 2 samples, got {X.shape[0]}."
    )
if X_source.shape[0] < 2:
    raise ValueError(
        f"X_source must have at least 2 samples, got {X_source.shape[0]}."
    )

and the relative test:

class TestFit:
    """Test for the fit method behavior."""
    def test_coral_raises_if_single_sample(self):
        X = np.array([[1.0, 2.0]])
        X_source = np.array([[3.0, 4.0]])
        with pytest.raises(ValueError, match="at least 2 samples"):
            CORAL().fit(X, X_source=X_source)

Comment thread chemotools/adaptation/_subspace_alignment.py Outdated
Comment thread chemotools/adaptation/_subspace_alignment.py Outdated
Comment thread chemotools/adaptation/_subspace_alignment.py Outdated
@inarteroger

Copy link
Copy Markdown
Collaborator Author

Addressed all Copilot suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Implementation of CORAL

2 participants