Skip to main content

DeepKernel

Struct DeepKernel 

Source
pub struct DeepKernel<F: NeuralFeatureMap, K: Kernel> { /* private fields */ }
Expand description

Composition of a neural feature extractor with a classical kernel.

F — the neural feature extractor (e.g. crate::deep_kernel::MLPFeatureExtractor).

K — the base kernel (e.g. crate::RbfKernel).

Implementations§

Source§

impl<F: NeuralFeatureMap, K: Kernel> DeepKernel<F, K>

Source

pub fn new(extractor: F, base: K) -> Self

Compose a feature extractor with a base kernel.

Source

pub fn feature_extractor(&self) -> &F

Immutable view of the feature extractor.

Source

pub fn feature_extractor_mut(&mut self) -> &mut F

Mutable view of the feature extractor — needed by optimisers that write into parameters_mut() and then call sync_from_flat on a concrete MLP.

Source

pub fn base_kernel(&self) -> &K

Immutable view of the base kernel.

Source

pub fn features(&self, x: &[f64]) -> Result<Vec<f64>>

Apply the feature map to a single input.

Source

pub fn evaluate(&self, x: &[f64], y: &[f64]) -> Result<f64>

Evaluate the composed kernel on a single input pair.

Source

pub fn compute_gram( &self, xs: &[&[f64]], ys: &[&[f64]], ) -> Result<Vec<Vec<f64>>>

Compute a Gram matrix G[i,j] = K_DKL(xs[i], ys[j]).

Feature maps are cached — each xs[i] is passed through the extractor at most once, same for ys[j]. For square xs == ys callers should prefer Self::compute_symmetric_gram.

Source

pub fn compute_symmetric_gram(&self, xs: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>

Symmetric Gram matrix for a single input set.

Takes advantage of K(a, b) == K(b, a) to halve the base-kernel evaluations; still calls the feature extractor n times.

Trait Implementations§

Source§

impl<F: Clone + NeuralFeatureMap, K: Clone + Kernel> Clone for DeepKernel<F, K>

Source§

fn clone(&self) -> DeepKernel<F, K>

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<F: Debug + NeuralFeatureMap, K: Debug + Kernel> Debug for DeepKernel<F, K>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<F: NeuralFeatureMap, K: Kernel> Kernel for DeepKernel<F, K>

Source§

fn compute(&self, x: &[f64], y: &[f64]) -> Result<f64>

Compute kernel value between two inputs. Read more
Source§

fn name(&self) -> &str

Get kernel name for identification.
Source§

fn is_psd(&self) -> bool

Check if kernel is positive semi-definite.
Source§

fn compute_matrix(&self, inputs: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>

Compute kernel matrix for a set of inputs. Read more

Auto Trait Implementations§

§

impl<F, K> Freeze for DeepKernel<F, K>
where F: Freeze, K: Freeze,

§

impl<F, K> RefUnwindSafe for DeepKernel<F, K>

§

impl<F, K> Send for DeepKernel<F, K>

§

impl<F, K> Sync for DeepKernel<F, K>

§

impl<F, K> Unpin for DeepKernel<F, K>
where F: Unpin, K: Unpin,

§

impl<F, K> UnsafeUnpin for DeepKernel<F, K>
where F: UnsafeUnpin, K: UnsafeUnpin,

§

impl<F, K> UnwindSafe for DeepKernel<F, K>
where F: UnwindSafe, K: UnwindSafe,

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.

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> 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