pub struct RandomProjectionFrameSketch { /* private fields */ }Expand description
A concrete AtomFrameSketch built from raw decoder column blocks B_k.
For each atom it orthonormalizes the decoder columns (modified Gram–Schmidt)
to obtain a frame U_k with orthonormal columns spanning the decoder range,
then sketches via a single shared seeded Gaussian random projection
R ∈ ℝ^{s×p} applied to the in-range component of a direction:
atom_sketch(k) = normalize( R · u_k0 ), the sketch of the atom’s first (dominant) frame column — a stable representative point used to bucket the atom.project_direction(k, d) = R · (U_k U_kᵀ d), the sketch of the part ofdthat lies in the atom’s range.alignment(k, d) = ‖U_kᵀ d‖ / ‖d‖, the exact in-range energy fraction.
The shared R is a Johnson–Lindenstrauss style random projection, so sketch
inner products approximately preserve angles between in-range directions —
exactly what the LSH index needs. Everything is seeded; the same atoms +
seed always produce the same sketches.
Implementations§
Source§impl RandomProjectionFrameSketch
impl RandomProjectionFrameSketch
Sourcepub fn from_decoder_blocks(
decoder_blocks: &[Array2<f64>],
sketch_dim: usize,
seed: u64,
) -> Result<Self, String>
pub fn from_decoder_blocks( decoder_blocks: &[Array2<f64>], sketch_dim: usize, seed: u64, ) -> Result<Self, String>
Build the sketch from decoder column blocks.
decoder_blocks[k] is B_k with shape (p, m_k): p rows in output
space, m_k decoder columns for atom k. (SaeManifoldAtom stores the
transpose (m_k, p); orient it p-rows before passing in.) All blocks
must share the same p. sketch_dim is the target sketch length s;
seed makes the projection deterministic.
Trait Implementations§
Source§impl AtomFrameSketch for RandomProjectionFrameSketch
impl AtomFrameSketch for RandomProjectionFrameSketch
Source§fn query_sketch(&self, direction: ArrayView1<'_, f64>) -> Array1<f64>
fn query_sketch(&self, direction: ArrayView1<'_, f64>) -> Array1<f64>
Exact O(p·s) probe (#994): every atom shares the one projection R,
and the table representatives are normalize(R · u_k0), so the correct
cosine-LSH probe for a direction is simply normalize(R · d) — no atom
is touched, and no masked-average approximation is involved.
Source§fn sketch_dim(&self) -> usize
fn sketch_dim(&self) -> usize
Source§fn output_dim(&self) -> usize
fn output_dim(&self) -> usize
Source§fn atom_sketch(&self, atom_id: usize) -> Array1<f64>
fn atom_sketch(&self, atom_id: usize) -> Array1<f64>
atom_id’s frame itself (a representative point of the
atom’s column-space on the sphere of sketch space), used to place the
atom into the LSH tables at build time. Returns a vector of length
AtomFrameSketch::sketch_dim.Source§fn project_direction(
&self,
atom_id: usize,
direction: ArrayView1<'_, f64>,
) -> Array1<f64>
fn project_direction( &self, atom_id: usize, direction: ArrayView1<'_, f64>, ) -> Array1<f64>
d (length AtomFrameSketch::output_dim)
as seen through atom atom_id’s frame: the direction’s component inside
the atom’s column-space, mapped into sketch coordinates. Used at query
time to score how strongly a row residual aligns with the atom.Source§fn alignment(&self, atom_id: usize, direction: ArrayView1<'_, f64>) -> f64
fn alignment(&self, atom_id: usize, direction: ArrayView1<'_, f64>) -> f64
[0, 1]: the fraction of the query direction’s energy
that lies inside atom atom_id’s column-space. 1.0 means the direction
lies fully in the atom’s range, 0.0 means it is orthogonal. Used to
rank the (small) candidate set the index returns.Auto Trait Implementations§
impl Freeze for RandomProjectionFrameSketch
impl RefUnwindSafe for RandomProjectionFrameSketch
impl Send for RandomProjectionFrameSketch
impl Sync for RandomProjectionFrameSketch
impl Unpin for RandomProjectionFrameSketch
impl UnsafeUnpin for RandomProjectionFrameSketch
impl UnwindSafe for RandomProjectionFrameSketch
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.