Skip to main content

SparseEmpiricalCubaturePlan

Struct SparseEmpiricalCubaturePlan 

Source
pub struct SparseEmpiricalCubaturePlan { /* private fields */ }
Expand description

Row-wise Tchakaloff cubature of the joint σ-pushforward measure on a fixed target grid.

Laid out in flat Struct-of-Arrays (SoA) form for cache-friendly online evaluation:

  • row_starts[i]..row_starts[i+1] indexes into weights/atoms for row i.
  • weights[q] is the per-atom nonneg weight (sums to 1.0 within each row since the source measure is row-stochastic).
  • atoms[q] is a flat row-major block of length k storing the atom’s joint σ coordinates.

Built once per (grid, isotope_set, training_densities, anchor) tuple and applied repeatedly during LM / KL iterations via Self::forward and Self::forward_and_jacobian.

Implementations§

Source§

impl SparseEmpiricalCubaturePlan

Source

pub fn default_training_points(train_max: &[f64]) -> Vec<Vec<f64>>

Canonical default training-density rule from the codex04 round-2 reference: for an upper-bound density vector train_max ∈ ℝ^k, return S = 2 + k training points consisting of 0.25 * train_max, 0.75 * train_max, and the k axis-aligned “unit” points train_max[i] · e_i (all other components zero). Exposed as a helper so callers — including the wiring in PR #474b — don’t have to hand-roll the rule.

Duplicates are NOT removed. In practice the rule produces S = k + 2 distinct points for any k ≥ 1 with all train_max[i] > 0.

Source

pub fn default_jacobian_anchor(train_max: &[f64]) -> Vec<f64>

Canonical default Jacobian anchor from the codex04 round-2 reference: 0.5 * train_max, the midpoint of the density box.

Source

pub fn build( matrix: &ResolutionMatrix, sigmas: &[f64], k: usize, training_densities: &[Vec<f64>], jacobian_anchor: &[f64], ) -> Result<Self, CubatureBuildError>

Build a Tchakaloff sparse-cubature plan row-by-row from an exact ResolutionMatrix + isotope cross-section stack.

§Arguments
  • matrix — exact sparse R (built via crate::resolution::ResolutionPlan::compile_to_matrix).
  • sigmas — per-isotope cross-sections on the matrix’s target grid, flat row-major: sigmas[j * n_rows + ℓ] = σ_j(E’_ℓ).
  • k — number of isotopes (must match sigmas.len() / n_rows).
  • training_densities — a slice of density vectors n^(s) ∈ ℝ^k covering the density box the fit is expected to explore. Codex04’s default rule is [0.25 * train_max, 0.75 * train_max] ∪ {train_max_e_i : i=1..k} which gives S = 2 + k distinct training points.
  • jacobian_anchor — a single density n* ∈ ℝ^k at which the Jacobian features are evaluated. Codex04 uses 0.5 * train_max.

Per-row LP:

find   x ≥ 0 in ℝ^{|support|}
s.t.   Σ_q x_q = 1
       phi[s, q]  = exp(-n^(s) · σ_support[q])      for s = 1..S
       phi[ℓ, q]  = σ_{ℓ, support[q]} · exp(-n* · σ_support[q])
                                                    for ℓ = 1..k
       phi @ x    = phi @ w_exact_support

where w_exact_support = R[i, support] / Σ_q R[i, support[q]] is the exact full-support row measure (the existing non-sparse weight distribution — NOT uniform; the entries carry the kernel shape). It serves as the feasibility fallback for the LP: the identity x = w_exact_support always satisfies the equality constraints, so a feasible solution exists. The returned basic feasible solution has at most S + k + 1 nonzero entries (Carathéodory).

Source

pub fn len(&self) -> usize

Number of rows (target-grid size) covered by this plan.

Source

pub fn is_empty(&self) -> bool

True when the plan covers no target energies.

Source

pub fn k(&self) -> usize

Number of isotopes (per-atom dimensionality).

Source

pub fn n_atoms(&self) -> usize

Total number of stored atoms across all rows.

Source

pub fn target_energies(&self) -> &[f64]

Target energy grid the plan was built for.

Mirrors crate::resolution::ResolutionPlan::target_energies / crate::resolution::ResolutionMatrix::target_energies — callers implementing plan caches compare this against their current grid to decide whether the plan is still valid.

Source

pub fn row_starts(&self) -> &[u32]

CSR row-start offsets. row_starts()[i]..row_starts()[i+1] names the atom range for row i. Length len() + 1.

Source

pub fn weights(&self) -> &[f64]

Per-atom weights.

Source

pub fn atoms(&self) -> &[f64]

Per-atom σ coordinates, flat row-major. Atom q at atoms()[k * q .. k * (q + 1)].

Source

pub fn density_box(&self) -> Option<&[f64]>

Training-density upper bound recorded at build time, if any. Dispatch layers use this to detect when the fit iterate escapes the training region and safely fall back to the exact path (cubature accuracy degrades quickly outside the trained box). None when the caller chose not to record one — in that case dispatch cannot safety-check.

Source

pub fn with_density_box(self, train_max: Vec<f64>) -> Self

Attach the training-density upper bound (train_max) used during build, so dispatch can refuse to fire on iterates that escape the trained region. Builder-style; returns self for chaining. Callers in spatial_map_typed populate this with the same train_max vector fed into Self::default_training_points / Self::default_jacobian_anchor.

§Panics

Panics if train_max.len() != self.k().

Source

pub fn forward(&self, n: &[f64]) -> Vec<f64>

Evaluate the surrogate forward model T_i(n) at density vector n ∈ ℝ^k.

§Panics

Panics if n.len() != self.k().

Source

pub fn forward_and_jacobian(&self, n: &[f64]) -> (Vec<f64>, Vec<f64>)

Evaluate forward + per-density Jacobian at density vector n. Returns (T, J) where T[i] = T_i(n) and J[i * k + ℓ] = ∂T_i/∂n_ℓ, both computed from the same atom scan so the online cost is (k + 1) FLOPs per atom rather than k + 1 separate passes.

§Panics

Panics if n.len() != self.k().

Trait Implementations§

Source§

impl Clone for SparseEmpiricalCubaturePlan

Source§

fn clone(&self) -> SparseEmpiricalCubaturePlan

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SparseEmpiricalCubaturePlan

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> 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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more