275 feature implementation of coral#278
Open
inarteroger wants to merge 8 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
CORALandSubspaceAlignmentsklearn-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 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_) |
Collaborator
Author
There was a problem hiding this comment.
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)
Collaborator
Author
|
Addressed all Copilot suggestions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why is this change needed?
Adds the
CORAL(CORrelation ALignment) andSubspaceAlignment(SA) transformers to thechemotools.adaptationmodule. 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
Description
Implementation of
CORALfollowing 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
SubspaceAlignmentfollowing 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
CORALtransformer inchemotools/adaptation/_coral.pySubspaceAlignmenttransformer inchemotools/adaptation/_subspace_alignment.pyfit,transform,fit_transform)X_source=NoneTests added