Commit a9dc298
committed
Add comprehensive unit tests for specialized loss function fitness calculators
This commit implements comprehensive unit tests for four specialized loss function
fitness calculators as requested in issue #376:
- DiceLossFitnessCalculator: Tests for medical imaging and segmentation scenarios
- JaccardLossFitnessCalculator: Tests for object detection using IoU metrics
- ContrastiveLossFitnessCalculator: Tests for similarity learning (face recognition)
- CosineSimilarityLossFitnessCalculator: Tests for document similarity and embeddings
Test Coverage Includes:
- Perfect predictions (zero loss)
- Worst case scenarios (maximum loss)
- Partial overlaps and varying degrees of similarity
- Edge cases (division by zero, empty sets, all zeros)
- Probabilistic predictions
- Different numeric types (float, double)
- Real-world scenarios (medical imaging, object detection, etc.)
- Proper null handling and exception testing
Each test file contains 20+ comprehensive test cases covering:
- Constructor behavior with different data set types
- Mathematical correctness of loss calculations
- IsBetterFitness comparison logic
- ModelEvaluationData integration
- Float and double type support
- Magnitude invariance (for cosine similarity)
- Imbalanced data handling
The tests follow the existing project patterns and conventions used in
other loss function tests (e.g., MeanSquaredErrorLossTests, HuberLossTests).
Resolves #3761 parent 4bbb1b8 commit a9dc298
File tree
4 files changed
+1629
-0
lines changed- tests/AiDotNet.Tests/UnitTests/FitnessCalculators
4 files changed
+1629
-0
lines changed
0 commit comments