Skip to main content

RandomProjectionFrameSketch

Struct RandomProjectionFrameSketch 

Source
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 of d that 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

Source

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

Source§

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

Dimension of the sketch vectors this implementor produces. Must be the same positive value for every atom in one dictionary so the index can build a single hyperplane bank.
Source§

fn output_dim(&self) -> usize

Dimension of the ambient output space the query directions live in.
Source§

fn num_atoms(&self) -> usize

Number of atoms this source can sketch.
Source§

fn atom_sketch(&self, atom_id: usize) -> Array1<f64>

Sketch of atom 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>

Sketch of a query direction 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

Alignment score in [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§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V