feat(trinity_loss): L-S51 — φ-prior-aware ternary contrastive loss (Trinity Loss)#810
Open
gHashTag wants to merge 1 commit into
Open
feat(trinity_loss): L-S51 — φ-prior-aware ternary contrastive loss (Trinity Loss)#810gHashTag wants to merge 1 commit into
gHashTag wants to merge 1 commit into
Conversation
Implements the Trinity loss function for JEPA-T training.
Formula:
sim(a,b) = dot_ternary(a,b) / 64
L_triplet = max(0, margin + sim(a,n) - sim(a,p)) [margin=0.5]
L_phi_prior = 0.382 * (zeros_a + zeros_p + zeros_n) / 192
L_total = L_triplet + 0.1 * L_phi_prior
Files:
crates/trinity_loss/Cargo.toml — crate manifest (Apache-2.0)
crates/trinity_loss/src/lib.rs — dot_ternary, sim, zero_count,
phi_prior_term, trinity_loss
crates/trinity_loss/tests/loss.rs — 10 hand-computed triplets
(±1e-4) + 50 LFSR stability
crates/trinity_loss/python_ref/ — NumPy reference (docs only)
crates/trinity_loss/README.md — usage + formula docs
Constraints:
- R1 CROWN: Rust only in cargo build; Python is reference-only
- All functions deterministic, allocation-free, no std::time
- Apache-2.0
cargo test -p trinity_loss: 26 tests passed (0 failed)
Closes #809
DOI: 10.5281/zenodo.19227877
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.
Closes #809
Summary
Implements the Trinity Loss — a φ-prior-aware ternary contrastive loss function for JEPA-T training (L-S51).
Formula
where
||x||₀counts zero entries in the ternary vector x.Files Changed
crates/trinity_loss/Cargo.tomlcrates/trinity_loss/src/lib.rsdot_ternary,sim,zero_count,phi_prior_term,trinity_losscrates/trinity_loss/tests/loss.rscrates/trinity_loss/python_ref/trinity_loss_ref.pycrates/trinity_loss/README.mdTest Results
Constraints Satisfied
cargo build/cargo test. Python file is reference docs only (not listed in Cargo.toml).std::time: safe for embedded-adjacent usage.