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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
//! Region embeddings for entailment and set containment.
//!
//! `subsume` represents concepts as geometric regions. A general concept
//! contains the regions for its more specific concepts, so containment becomes
//! the scoring operation for hierarchy, ontology, and set-query tasks.
//!
//! # Example
//!
//! ```rust
//! use ndarray::array;
//! use subsume::{ndarray_backend::NdarrayBox, HyperBox};
//!
//! # fn main() -> Result<(), subsume::BoxError> {
//! let premise = NdarrayBox::new(array![0., 0., 0.], array![1., 1., 1.], 1.0)?;
//! let hypothesis = NdarrayBox::new(array![0.2, 0.2, 0.2], array![0.8, 0.8, 0.8], 1.0)?;
//!
//! let p = premise.containment_prob(&hypothesis)?;
//! assert!(p > 0.9);
//! # Ok(())
//! # }
//! ```
//!
//! # Choosing a Geometry
//!
//! | Task | Start with |
//! | --- | --- |
//! | Containment hierarchy | `ndarray_backend::NdarrayBox` or `NdarrayGumbelBox` |
//! | Logical queries with negation | Cone or subspace |
//! | Taxonomy expansion with uncertainty | Gaussian boxes |
//! | EL++ ontology completion | `el`, `transbox` |
//! | Tree-like hierarchies in low dimension | Hyperbolic intervals or balls |
//!
//! Scores are meaningful within a geometry. Do not compare raw scores across
//! geometries without calibration.
//!
//! # Modules
//!
//! - `box_trait`: `HyperBox`, containment, overlap, volume, and intersection.
//! - `ndarray_backend`: default CPU box and Gumbel-box implementations.
//! - `dataset`, `trainer`, `metrics`: knowledge-graph loading, training, and
//! rank-based evaluation.
//! - `el`: EL++ ontology embedding losses.
//! - `gaussian`, `cone`, `octagon`, `hyperbolic`: additional geometries.
//!
//! # Limits
//!
//! - For ordinary link prediction, point embeddings are often simpler.
//! - Region scores from different geometries are not directly comparable.
//! - Several geometry trainers are research paths, not recommended defaults.
// ---------------------------------------------------------------------------
// Core traits and geometry
// ---------------------------------------------------------------------------
/// Core [`HyperBox`] trait: containment probability, overlap, volume, and intersection.
/// Cone embeddings: angular containment on the unit sphere, with negation support.
/// Octagon embeddings: axis-aligned polytopes with diagonal constraints (IJCAI 2024).
/// Knowledge graph dataset loading (WN18RR, FB15k-237, YAGO3-10, and similar formats).
/// Distance metrics: Query2Box distance scoring.
/// Poincare ball embeddings for tree-like hierarchical structures.
///
/// Requires the `hyperbolic` feature (uses `ndarray::ArrayView1` for
/// interoperability with the `hyperball` and `skel` crates).
/// AMSGrad optimizer state and learning rate utilities.
/// Sheaf neural networks: algebraic consistency enforcement on graphs.
/// Learnable box and cone representations with gradient-compatible parameters.
/// Training loop utilities: negative sampling, loss kernels, link prediction evaluation.
/// Rank-based evaluation metrics (MRR, Hits@k, Mean Rank).
/// Re-export rankops for rank fusion, IR evaluation (nDCG, MAP), and reranking.
pub use rankops;
/// Numerical stability: log-space volume, stable sigmoid, Gumbel operations.
/// Ball embeddings for subsumption via Euclidean containment.
///
/// Concepts are solid balls `(center, radius)` in R^d. Containment:
/// `||c_A - c_B|| + r_A <= r_B`. Supports SpherE-style relation transforms
/// (translate + scale) and RegD depth/boundary dissimilarity scoring.
///
/// References:
/// - SpherE (SIGIR 2024, arXiv:2404.19130): ball embeddings for set retrieval
/// - RegD (Jan 2025, arXiv:2501.17518): balls isometric to hyperbolic space
/// Spherical cap embeddings for subsumption on the unit sphere.
///
/// Concepts are regions on S^{d-1} defined by a center (unit vector)
/// and an angular radius. Containment: `angle(c_A, c_B) + theta_A <= theta_B`.
/// This is the spherical analog of ball containment in Euclidean space.
/// Subspace embeddings for logical operations (conjunction, disjunction, negation).
///
/// Concepts are linear subspaces of R^d, represented by orthonormal bases.
/// Containment via projection, intersection via common subspace, negation
/// via orthogonal complement.
///
/// Reference: Moreira et al. (2025), arXiv:2508.16687
/// Full-covariance Gaussian embeddings (rotated ellipsoids).
///
/// Concepts are multivariate Gaussians with full covariance, parameterized
/// via Cholesky decomposition. Supports KL divergence (asymmetric containment)
/// and Bhattacharyya distance (symmetric overlap).
/// TransBox: EL++-closed box embeddings with translational composition.
///
/// Concepts and roles as boxes with additive composition. Handles many-to-many
/// relations and complex role compositions while preserving EL++ semantics.
///
/// Reference: Yang, Chen, Sattler (2024), arXiv:2410.14571
/// Annular sector embeddings for knowledge graph completion.
///
/// Concepts as ring-shaped regions in the complex plane. Combines rotation-based
/// relations with region uncertainty, handling 1-N/N-1/N-N relations.
///
/// Reference: Zhu & Zeng (2025), arXiv:2506.11099
/// Diagonal Gaussian box embeddings for taxonomy expansion (TaxoBell).
/// Density matrix region embeddings (pure-state quantum embeddings).
///
/// Represents concepts as rank-1 density matrices in a complex Hilbert space.
/// Subsumption via Loewner order, distance via fidelity / Bures metric.
/// Reference: Garg et al. (2019), "Quantum Embedding of Knowledge for Reasoning" (NeurIPS).
/// Spherical knowledge graph embeddings on the unit sphere.
///
/// Entities are points on `S^{d-1}` (unit vectors). Relations are axis-angle
/// rotations. Scoring uses geodesic (great-circle) distance.
/// Density matrix EL++ training losses: NF1-NF4 and disjointness losses
/// using fidelity-based scoring on pure-state density matrices.
/// EL++ ontology embedding primitives (Box2EL / TransBox).
/// EL++ normalized axiom dataset loader (GALEN, GO, Anatomy formats).
/// EL++ ontology embedding primitives for cones (angular containment).
/// EL++ ontology embedding training: axiom parsing, training loop, evaluation.
/// Conjunctive least-common-ancestor queries over faithful EL++ box embeddings
/// via containment-gated proximity to the join box.
/// Taxonomy dataset loading for the TaxoBell format (`.terms` / `.taxo` / `dic.json`).
/// TaxoBell combined training loss for taxonomy expansion.
// ---------------------------------------------------------------------------
// Re-exports: primary traits and types
// ---------------------------------------------------------------------------
/// The core box (axis-aligned hyperrectangle) embedding trait. Start here.
///
/// Named `HyperBox` (not `Box`) so it does not shadow [`std::boxed::Box`].
/// "Box" in the geometric-embedding literature means an n-dimensional
/// hyperrectangle; this trait models exactly that.
pub use ;
/// The unified region abstraction over all geometries (boxes, balls,
/// ellipsoids, subspaces). See [`region::Region`].
pub use Region;
/// Deprecated alias for [`HyperBox`]. The trait was renamed from `Box` to
/// `HyperBox` so it no longer shadows [`std::boxed::Box`]; switch to `HyperBox`.
pub use HyperBox as Box;
/// Convenience alias for the [`HyperBox`] trait, retained for compatibility.
pub use HyperBox as BoxRegion;
// Re-exports: geometry errors
pub use ConeError;
pub use ;
pub use OctagonError;
pub use SheafError;
// Re-exports: data loading
pub use ;
// Re-exports: training (always available)
pub use ;
// Re-exports: training (requires kge feature)
pub use ;
// Re-export: ndarray (public dependency -- appears in NdarrayBox/NdarrayGumbelBox/NdarrayCone API)
pub use ndarray;
// Re-exports: evaluation metrics
pub use ;
// Re-exports: Ball embeddings
pub use ;
// Re-exports: Spherical cap embeddings
pub use ;
// Re-exports: Subspace embeddings
pub use ;
// Re-exports: Ellipsoid (full-covariance Gaussian) embeddings
pub use Ellipsoid;
// Re-exports: Annular sector embeddings
pub use ;
// Re-exports: TransBox embeddings
pub use ;
// Re-exports: Gaussian boxes
pub use GaussianBox;
// Re-exports: Density matrix embeddings
pub use DensityRegion;
// Re-exports: Spherical embeddings
pub use ;
// Re-exports: Density matrix EL++ training
pub use ;
// Re-exports: EL++ training
pub use ;
// Re-exports: cone EL++ primitives
pub use ;
// ---------------------------------------------------------------------------
// Feature-gated backends
// ---------------------------------------------------------------------------
/// Ndarray backend: `NdarrayBox`, `NdarrayGumbelBox`, optimizer, and learning rate scheduler.
///
/// This is the default backend. Enable with `features = ["ndarray-backend"]`.
/// Adapter for constructing datasets from [`petgraph`] graphs.
///
/// Requires the `petgraph` feature.
/// Bridge from [`lattix`] knowledge graphs to subsume datasets.
///
/// Converts lattix KGs (loaded from N-Triples, Turtle, CSV, JSON-LD)
/// into subsume datasets for training.