1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! # Contrastive Learning Module
//!
//! This module provides contrastive learning primitives for self-supervised representation learning:
//!
//! - **InfoNCE Loss**: NT-Xent loss used in SimCLR and CLIP
//! - **Triplet Loss**: Classic metric learning loss with margin
//! - **Contrastive Augmentation**: SimCLR-style data augmentation pipeline
//!
//! ## Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │ Contrastive Learning │
//! └───────────────────────────────────────────────────────────────┘
//! │
//! ┌────────────────────┼────────────────────┐
//! ▼ ▼ ▼
//! ┌─────────┐ ┌──────────┐ ┌─────────────┐
//! │ InfoNCE │ │ Triplet │ │ Augmentation│
//! │ Loss │ │ Loss │ │ Pipeline │
//! └─────────┘ └──────────┘ └─────────────┘
//! NT-Xent with Margin-based SimCLR-style
//! temperature metric learning random crops,
//! scaling flips, jitter
//! ```
//!
//! ## Usage Example
//!
//! ```rust
//! use ruvector_cnn::contrastive::{InfoNCELoss, TripletLoss, ContrastiveAugmentation};
//!
//! // InfoNCE for self-supervised learning
//! let infonce = InfoNCELoss::new(0.07);
//!
//! // Triplet loss for metric learning
//! let triplet = TripletLoss::new(1.0);
//!
//! // Data augmentation pipeline
//! let augmentation = ContrastiveAugmentation::builder()
//! .crop_scale(0.08, 1.0)
//! .horizontal_flip_prob(0.5)
//! .color_jitter(0.4, 0.4, 0.4, 0.1)
//! .build();
//! ```
pub use ;
pub use ;
pub use ;