pub struct TrainableKernel {
pub theta: Vec<f32>,
/* private fields */
}Expand description
A trainable quantum embedding kernel with per-feature rotation scales θ.
Fields§
§theta: Vec<f32>Trainable per-feature scale parameters.
Implementations§
Source§impl TrainableKernel
impl TrainableKernel
Sourcepub fn new(n_features: usize) -> Self
pub fn new(n_features: usize) -> Self
Construct with all scales initialized to 1.0 (plain angle embedding).
Sourcepub fn with_theta(n_features: usize, theta: Vec<f32>) -> QuantumResult<Self>
pub fn with_theta(n_features: usize, theta: Vec<f32>) -> QuantumResult<Self>
Construct with explicit initial scales.
§Errors
Returns QuantumError::DimensionMismatch if theta.len() != n_features.
Sourcepub fn n_features(&self) -> usize
pub fn n_features(&self) -> usize
Number of features / qubits.
Sourcepub fn gram(&self, xs: &[Vec<f32>]) -> QuantumResult<Vec<Vec<f32>>>
pub fn gram(&self, xs: &[Vec<f32>]) -> QuantumResult<Vec<Vec<f32>>>
Full Gram matrix for xs using the current scales.
§Errors
Returns QuantumError::EmptyInput for empty data; propagates embedding
errors.
Sourcepub fn alignment(&self, xs: &[Vec<f32>], labels: &[f32]) -> QuantumResult<f32>
pub fn alignment(&self, xs: &[Vec<f32>], labels: &[f32]) -> QuantumResult<f32>
Kernel-target alignment with the current scales.
§Errors
Returns QuantumError::DimensionMismatch if labels.len() != xs.len(),
QuantumError::EmptyInput for empty data, and propagates embedding errors.
Sourcepub fn train_alignment(
&mut self,
xs: &[Vec<f32>],
labels: &[f32],
cfg: &TrainableKernelConfig,
) -> QuantumResult<Vec<f32>>
pub fn train_alignment( &mut self, xs: &[Vec<f32>], labels: &[f32], cfg: &TrainableKernelConfig, ) -> QuantumResult<Vec<f32>>
Train the scales θ by gradient ascent on the kernel-target alignment.
Gradients use the parameter-shift rule on each scale component (the
alignment is a smooth function of the scales). Returns the alignment value
at every iteration (length iters + 1, including the initial alignment).
§Errors
Returns QuantumError::DimensionMismatch on a label/data length
mismatch and propagates embedding errors.
Trait Implementations§
Source§impl Clone for TrainableKernel
impl Clone for TrainableKernel
Source§fn clone(&self) -> TrainableKernel
fn clone(&self) -> TrainableKernel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more