pub struct LearnedMixtureKernel { /* private fields */ }Expand description
A differentiable mixture over a library of base kernels.
The mixture is parameterised by a vector of logits w. Weights
p = softmax(w) are always strictly positive and sum to 1. The
evaluation is
K_mix(x, y) = sum_i p_i * K_i(x, y).Logits are unconstrained real numbers; the softmax parameterisation guarantees a valid convex combination on the simplex, which keeps the mixture positive semi-definite when every base kernel is PSD.
Implementations§
Source§impl LearnedMixtureKernel
impl LearnedMixtureKernel
Sourcepub fn new(base_kernels: Vec<Arc<dyn Kernel>>, logits: Vec<f64>) -> Result<Self>
pub fn new(base_kernels: Vec<Arc<dyn Kernel>>, logits: Vec<f64>) -> Result<Self>
Build a mixture from a non-empty library and matching logits.
Errors when the library is empty, the vectors disagree in length, or any logit is non-finite.
Sourcepub fn uniform(base_kernels: Vec<Arc<dyn Kernel>>) -> Result<Self>
pub fn uniform(base_kernels: Vec<Arc<dyn Kernel>>) -> Result<Self>
Build a mixture with uniform logits (all zeros → equal weights).
Sourcepub fn num_kernels(&self) -> usize
pub fn num_kernels(&self) -> usize
Number of base kernels in the library.
Sourcepub fn weights(&self) -> Vec<f64>
pub fn weights(&self) -> Vec<f64>
Softmax weights p_i = softmax(w)_i. Always strictly positive,
always sums to 1 in exact arithmetic.
Sourcepub fn set_logits(&mut self, new_logits: Vec<f64>) -> Result<()>
pub fn set_logits(&mut self, new_logits: Vec<f64>) -> Result<()>
Replace the logits. The new vector must match num_kernels() and
every element must be finite.
Sourcepub fn apply_gradient_step(
&mut self,
gradient: &[f64],
learning_rate: f64,
) -> Result<()>
pub fn apply_gradient_step( &mut self, gradient: &[f64], learning_rate: f64, ) -> Result<()>
Apply a raw gradient update w_i <- w_i - lr * g_i in place.
Used by crate::learned_composition::TrainableKernelMixture.
Sourcepub fn evaluate(&self, x: &[f64], y: &[f64]) -> Result<f64>
pub fn evaluate(&self, x: &[f64], y: &[f64]) -> Result<f64>
Evaluate the mixture on a single input pair.
Sourcepub fn gradient_wrt_logits(&self, x: &[f64], y: &[f64]) -> Result<Vec<f64>>
pub fn gradient_wrt_logits(&self, x: &[f64], y: &[f64]) -> Result<Vec<f64>>
Return the analytical gradient dK_mix/dw_i = p_i * (K_i - K_mix).
This form is numerically cleaner than routing through the full
softmax Jacobian (it stays bounded as p_i concentrates mass).
Trait Implementations§
Source§impl Clone for LearnedMixtureKernel
impl Clone for LearnedMixtureKernel
Source§fn clone(&self) -> LearnedMixtureKernel
fn clone(&self) -> LearnedMixtureKernel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LearnedMixtureKernel
impl Debug for LearnedMixtureKernel
Source§impl From<LearnedMixtureKernel> for TrainableKernelMixture
impl From<LearnedMixtureKernel> for TrainableKernelMixture
Source§fn from(inner: LearnedMixtureKernel) -> Self
fn from(inner: LearnedMixtureKernel) -> Self
Auto Trait Implementations§
impl Freeze for LearnedMixtureKernel
impl !RefUnwindSafe for LearnedMixtureKernel
impl Send for LearnedMixtureKernel
impl Sync for LearnedMixtureKernel
impl Unpin for LearnedMixtureKernel
impl UnsafeUnpin for LearnedMixtureKernel
impl !UnwindSafe for LearnedMixtureKernel
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more