Skip to main content

SaeAssignment

Struct SaeAssignment 

Source
pub struct SaeAssignment {
    pub logits: Array2<f64>,
    pub coords: Vec<LatentCoordValues>,
    pub mode: AssignmentMode,
    pub ungated: Vec<bool>,
    pub frozen_logits: Option<Array2<f64>>,
}
Expand description

Per-row latent assignment state.

The stored assignment parameter is logits; non-negative assignments are derived by row-wise softmax, independent IBP-MAP sigmoid active indicators, or JumpReLU gates. Softmax logits are canonicalized to the reference chart logits[K - 1] = 0, so the row-local Newton coordinates contain only the first K - 1 logits (0 coordinates for K = 1). Gate-style modes keep all K logits as identifiable scalar parameters. coords[k] holds t_{.,k} for atom k.

Fields§

§logits: Array2<f64>§coords: Vec<LatentCoordValues>§mode: AssignmentMode§ungated: Vec<bool>

#1026 — per-atom UNGATED flag (length K, default all-false). An ungated atom is the dense linear/background tier: its per-row gate is fixed at a_k ≡ 1 (it contributes γ_k(t_k) to EVERY row, unweighted), it is excluded from the other atoms’ gate (for the column-separable IBP / JumpReLU modes the remaining atoms are computed independently, so they are unaffected), and its logit is NOT a free parameter — its logit-JVP, sparsity-prior gradient/curvature, and softmax majorizer contributions are all zero, leaving its logit slot an inert (ridge-regularized) null direction in the per-row Newton block. This lets the linear tier carry FULL-RANK reconstructible variance (fitted = γ_ungated(x) + Σ_{gated} a_k·γ_k(x)) so a linear SAE can reach the rank-(K·d) PCA ceiling, while the gated curved atoms still add sparse structure on the residual (#1026 routing-bound finding).

§frozen_logits: Option<Array2<f64>>

#1033 — AMORTIZED / FROZEN routing. When Some, this (n, K) matrix is a ρ-INVARIANT predicted routing (the amortized x → logits map distilled from the frozen dictionary): the gates are computed from THESE logits instead of the free self.logits, and the logits are NOT optimized by the inner Newton (their gradient/curvature/prior contributions are zeroed, exactly as for Self::ungated). This is the generalization of an ungated atom from “pin the gate at 1” to “pin the gate at the predicted value”: it makes the per-row routing a fixed function of x + the frozen dictionary, so the outer ρ-search reuses ONE routing instead of re-solving per-row gates every outer eval — the n-independent-outer-loop lever (#1033). None is the historical free-logit path (bit-identical).

Implementations§

Source§

impl SaeAssignment

Source

pub fn new( logits: Array2<f64>, coords: Vec<LatentCoordValues>, temperature: f64, ) -> Result<Self, String>

Source

pub fn with_mode( logits: Array2<f64>, coords: Vec<LatentCoordValues>, mode: AssignmentMode, ) -> Result<Self, String>

Source

pub fn with_frozen_routing( self, predicted: Option<Array2<f64>>, ) -> Result<Self, String>

#1033 — install a ρ-INVARIANT FROZEN routing (the amortized predicted logits; see SaeAssignment::frozen_logits). predicted must be (n, K). With routing frozen, the gates are computed from predicted and the logits are excluded from the inner Newton (their gradient/curvature are inert, like an ungated atom’s). Passing None restores the free-logit path.

Source

pub fn routing_is_frozen(&self) -> bool

Whether the per-row routing is FROZEN (amortized) rather than free-logit.

Source

pub fn freeze_routing_from_current_logits(self) -> Result<Self, String>

#1033 — install the simplest faithful AMORTIZED routing predictor: a fixed-form DISTILL of the current dictionary’s routing, namely the current (converged) logits SNAPSHOTTED as the ρ-invariant frozen routing. This is the x → logits map “evaluated once at the frozen dictionary” — the routing the dictionary already expresses — held fixed so the outer ρ-search reuses it instead of re-optimizing the gates at every ρ. (A richer predictor that recomputes logits from x via the encode-atlas chart geometry is a later refinement; snapshotting the converged routing is the exact fixed-point it would target at the frozen dictionary.) Rejected for Softmax for the same simplex-coupling reason as Self::with_frozen_routing.

Source

pub fn freeze_routing_in_place(&mut self) -> Result<(), String>

#1033 — in-place variant of Self::freeze_routing_from_current_logits for callers holding &mut SaeAssignment (e.g. inside a SaeManifoldTerm), where moving the assignment out is awkward. Same contract: snapshot the current logits as the ρ-invariant frozen routing; reject Softmax.

Source

pub fn set_frozen_routing_in_place( &mut self, predicted: Array2<f64>, ) -> Result<(), String>

#1033 — install an explicit predicted routing in place (the RoutingPredictor::ChartGeometry output), &mut self variant of Self::with_frozen_routing. predicted must be (n, K); rejects Softmax (separable-mode contract) and non-finite predictions.

Source

pub fn thaw_routing(&mut self)

#1033 — lift the frozen routing, restoring the free-logit search path.

Source

pub fn with_ungated(self, flags: Vec<bool>) -> Result<Self, String>

#1026 — designate which atoms are UNGATED (the dense linear/background tier; see SaeAssignment::ungated). flags must have length K.

Ungating is defined for the COLUMN-SEPARABLE gate modes (IBP-MAP and JumpReLU): each atom’s gate is an independent per-atom function of its own logit, so pinning one atom to a_k ≡ 1 leaves every other atom’s gate exactly as computed. Softmax is a coupled simplex (Σ_k a_k = 1 over all K), so a unit gate for one atom is only well defined relative to a gated-subset renormalization that must also be reflected in the logit-JVP and the entropy majorizer; this constructor’s contract is restricted to the separable modes, and an ungated atom under Softmax is REJECTED here so the inner solve never runs on a value/gradient-mismatched gate. Callers wanting a dense background tier under Softmax route it as an IBP-MAP or JumpReLU atom.

Source

pub fn has_ungated(&self) -> bool

Whether any atom is ungated (the #1026 background tier is engaged).

Source

pub fn n_obs(&self) -> usize

Source

pub fn k_atoms(&self) -> usize

Source

pub fn total_coord_dim(&self) -> usize

Source

pub fn assignment_coord_dim(&self) -> usize

Source

pub fn row_block_dim(&self) -> usize

Source

pub fn coord_offsets(&self) -> Vec<usize>

Source

pub fn assignments(&self) -> Array2<f64>

Source

pub fn assignments_row(&self, row: usize) -> Array1<f64>

Source

pub fn try_assignments_row(&self, row: usize) -> Result<Array1<f64>, String>

Source

pub fn flatten_ext_coords(&self) -> Array1<f64>

Flatten extension coordinates in row-major SAE layout: (assignment chart_i, t_i0[0..d_0], ..., t_iK[0..d_K]) for every row. Softmax contributes the first K - 1 reference logits and omits the fixed reference logit; gate-style assignment modes contribute all K logits.

Source

pub fn from_blocks_with_mode( logits: Array2<f64>, coord_blocks: Vec<Array2<f64>>, mode: AssignmentMode, ) -> Result<Self, String>

Source

pub fn from_blocks_with_mode_and_manifolds( logits: Array2<f64>, coord_blocks: Vec<Array2<f64>>, manifolds: Vec<LatentManifold>, mode: AssignmentMode, ) -> Result<Self, String>

Trait Implementations§

Source§

impl Clone for SaeAssignment

Source§

fn clone(&self) -> SaeAssignment

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SaeAssignment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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