1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Deep Kernel Learning (DKL).
//!
//! This module implements the Deep Kernel Learning architecture of
//! Wilson et al. (2016). A DKL wraps a classical base kernel
//! `K_base(·, ·)` with a differentiable feature extractor `g_θ` and
//! evaluates
//!
//! ```text
//! K_DKL(x, y) = K_base(g_θ(x), g_θ(y)).
//! ```
//!
//! In the v0.2.0 research preview we ship a single reference feature
//! extractor — an MLP with Xavier/Glorot-normal initialisation (via
//! SciRS2-Core's seeded RNG) and support for ReLU / Tanh / Identity
//! activations. The generic [`DeepKernel`] is parameterised by the
//! extractor and the base kernel, so any other kernel in this crate
//! (RBF, Linear, Matern, …) plugs in without modification.
//!
//! # Relationship to `learned_composition`
//!
//! This module is the "nonlinear feature composition" counterpart of
//! [`crate::learned_composition`]. Where
//! [`crate::learned_composition::LearnedMixtureKernel`] learns a
//! softmax-weighted mixture *over* a library of kernels,
//! [`DeepKernel`] learns a nonlinear feature map that *transforms*
//! inputs before a single base kernel is applied. The two modules are
//! intended to be used together for expressive, trainable similarity
//! metrics.
//!
//! # Module layout
//!
//! * [`layer`] — [`DenseLayer`] / [`Activation`] primitives.
//! * [`feature_extractor`] — [`NeuralFeatureMap`] trait and
//! [`MLPFeatureExtractor`] reference implementation.
//! * [`kernel`] — the [`DeepKernel`] wrapper that composes a feature
//! map with a base kernel and implements [`crate::Kernel`].
//! * [`gradient`] — finite-difference verification and an analytical
//! gradient path for the RBF-base case.
//! * [`builder`] — fluent [`DeepKernelBuilder`] for common MLP
//! topologies.
//!
//! # Gradient semantics
//!
//! * **Analytical**: the closed form `∂K_DKL/∂θ` for the
//! MLP-extractor + RBF-base case is available via
//! [`gradient::rbf_dkl_gradient`] — one forward+backward pass, no
//! autodiff.
//! * **Numerical**: every `DeepKernel<MLPFeatureExtractor, K>` supports
//! [`gradient::finite_difference_gradient`] as a correctness check or
//! as a stand-in for base kernels whose analytical chain rule has not
//! yet been derived.
//! * **Base-kernel hyperparameters**: gradients w.r.t. e.g. the RBF
//! `γ` are **not** produced here — callers should go through
//! [`crate::tensor_kernels::RbfKernel::compute_with_gradient`] or a
//! future autodiff layer.
//!
//! # Example
//!
//! ```rust
//! use tensorlogic_sklears_kernels::{
//! deep_kernel::{Activation, DeepKernelBuilder},
//! Kernel, RbfKernel, RbfKernelConfig,
//! };
//!
//! let rbf = RbfKernel::new(RbfKernelConfig::new(0.5)).expect("valid gamma");
//! let dkl = DeepKernelBuilder::new()
//! .input_dim(2)
//! .hidden_layer(4, Activation::Tanh)
//! .output_dim(2, Activation::Identity)
//! .seed(42)
//! .build(rbf)
//! .expect("valid topology");
//!
//! let x = vec![0.1, -0.2];
//! let y = vec![0.3, 0.4];
//! let _value = dkl.compute(&x, &y).expect("dkl value");
//! ```
pub use DeepKernelBuilder;
pub use ;
pub use ;
pub use ;
pub use ;