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.
This pull request introduces several improvements focusing on enhancing numerical stability and performance. The changes include adding gradient computation disabling for specific operations, and ensuring edge cases are handled correctly in loss functions.
Enhancements to Numerical Stability and Performance:
skada/deep/callbacks.py
: Disabled gradient computation for feature extraction inon_epoch_begin
to improve performance.skada/deep/utils.py
: Updated_compute_dissimilarities
to compute dissimilarities in batches, improving performance for large datasets.skada/deep/losses.py
: Added a small epsilon (eps
) to the median pairwise distance calculation to avoid division by zero errors.skada/deep/utils.py
: Wrapped centroid initialization, fitting, and prediction methods intorch.no_grad()
to prevent unnecessary gradient computations. [1] [2] [3]Refinements in Centroid Calculations:
skada/deep/callbacks.py
: Changed centroid calculation from mean to sum inon_epoch_begin
to ensure consistency with normalization.skada/deep/losses.py
: Ensuredsource_centroids
is stacked properly after calculation incdd_loss
.Handling Edge Cases in Loss Functions:
skada/deep/losses.py
: Added checks to ensure intra-class and inter-class domain discrepancy measures (e1
,e2
,e3
) are set to zero if their corresponding masks sum to zero. This prevents potential errors from invalid operations.Enhancements to tests:
skada/deep/tests/test_deep_divergence.py
: Added a new test functiontest_cdd_loss_edge_cases
to verify thatcdd_loss
handles edge cases correctly, such as when all source features are identical.