pub mod ard_kernel;
pub mod batch;
pub mod cache;
pub mod composite_kernel;
pub mod deep_kernel;
pub mod error;
pub mod feature_extraction;
pub mod gradient;
pub mod graph_kernel;
pub mod kernel_alignment;
pub mod kernel_pca;
pub mod kernel_selection;
pub mod kernel_transform;
pub mod kernel_utils;
pub mod kpca;
pub mod learned_composition;
pub mod logic_kernel;
pub mod low_rank;
pub mod multitask;
pub mod online;
pub mod provenance;
pub mod random_features;
#[cfg(feature = "sklears")]
pub mod sklears_integration;
pub mod sparse;
pub mod spectral_kernel;
pub mod string_kernel;
pub mod symbolic;
pub mod tensor_kernels;
pub mod tree_kernel;
pub mod types;
pub use ard_kernel::{
ArdMaternKernel, ArdRationalQuadraticKernel, ArdRbfKernel, ConstantKernel, DotProductKernel,
KernelGradient, ScaledKernel, WhiteNoiseKernel,
};
pub use batch::{
BatchKernelComputer, GramMatrix, KernelCache as BatchKernelCache, KernelMatrixStats,
};
pub use cache::{CacheStats, CachedKernel, KernelMatrixCache};
pub use composite_kernel::{KernelAlignment, ProductKernel, WeightedSumKernel};
pub use deep_kernel::{
Activation as DeepKernelActivation, DeepKernel, DeepKernelBuilder, DenseLayer,
MLPFeatureExtractor, NeuralFeatureMap,
};
pub use error::{KernelError, Result};
pub use feature_extraction::{FeatureExtractionConfig, FeatureExtractor};
pub use graph_kernel::{
Graph, RandomWalkKernel, SubgraphMatchingConfig, SubgraphMatchingKernel, WalkKernelConfig,
WeisfeilerLehmanConfig, WeisfeilerLehmanKernel,
};
pub use kernel_alignment::{
alignment_stats, centered_kernel_alignment, gradient_ascent_alignment, grid_search_alignment,
hsic, kernel_target_alignment, AlignmentError, AlignmentOptConfig, AlignmentResult,
AlignmentStats, KernelMatrix, OptimizationResult,
};
pub use kernel_pca::{
FittedKernelPCA, KernelPCA, KernelPcaConfig, KernelPcaError, KernelPcaResult,
};
pub use kernel_selection::{
CrossValidationResult, GammaSearchResult, KFoldConfig, KernelComparison, KernelSelector,
};
pub use kernel_transform::NormalizedKernel;
pub use learned_composition::{
LearnedMixtureBuilder, LearnedMixtureKernel, TrainableKernelMixture,
};
pub use logic_kernel::{PredicateOverlapKernel, RuleSimilarityKernel};
pub use low_rank::{NystromApproximation, NystromConfig, SamplingMethod};
pub use multitask::{
HadamardTaskKernel, ICMKernel, ICMKernelWrapper, IndexKernel, LMCKernel, LMCKernelWrapper,
MultiTaskConfig, MultiTaskKernelBuilder, TaskInput,
};
pub use online::{
AdaptiveKernelMatrix, ForgetfulConfig, ForgetfulKernelMatrix, OnlineConfig, OnlineKernelMatrix,
OnlineStats, WindowedKernelMatrix,
};
pub use provenance::{
ComputationResult, ProvenanceConfig, ProvenanceId, ProvenanceKernel, ProvenanceRecord,
ProvenanceStatistics, ProvenanceTracker,
};
pub use random_features::{
KernelType as RffKernelType, NystroemFeatures, OrthogonalRandomFeatures, RandomFourierFeatures,
RffConfig,
};
#[cfg(feature = "sklears")]
pub use sklears_integration::SklearsKernelAdapter;
pub use sparse::{SparseKernelMatrix, SparseKernelMatrixBuilder};
pub use spectral_kernel::{
ExpSineSquaredKernel, LocallyPeriodicKernel, RbfLinearKernel, SpectralComponent,
SpectralMixtureKernel,
};
pub use string_kernel::{
EditDistanceKernel, NGramKernel, NGramKernelConfig, SubsequenceKernel, SubsequenceKernelConfig,
};
pub use symbolic::{KernelBuilder, KernelExpr, SymbolicKernel};
pub use tensor_kernels::{
ChiSquaredKernel, CosineKernel, HistogramIntersectionKernel, LaplacianKernel, LinearKernel,
MaternKernel, PeriodicKernel, PolynomialKernel, RationalQuadraticKernel, RbfKernel,
SigmoidKernel,
};
pub use tree_kernel::{
PartialTreeKernel, PartialTreeKernelConfig, SubsetTreeKernel, SubsetTreeKernelConfig,
SubtreeKernel, SubtreeKernelConfig, TreeNode,
};
pub use types::{Kernel, PredicateOverlapConfig, RbfKernelConfig, RuleSimilarityConfig};
#[deprecated(since = "0.1.0", note = "Use RuleSimilarityKernel instead")]
pub fn logic_kernel_similarity() {
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_kernel_trait_usage() {
let kernels: Vec<Box<dyn Kernel>> = vec![
Box::new(LinearKernel::new()),
Box::new(CosineKernel::new()),
Box::new(RbfKernel::new(RbfKernelConfig::new(0.5)).expect("unwrap")),
Box::new(PolynomialKernel::new(2, 1.0).expect("unwrap")),
];
let x = vec![1.0, 2.0, 3.0];
let y = vec![4.0, 5.0, 6.0];
for kernel in kernels {
let result = kernel.compute(&x, &y);
assert!(result.is_ok());
}
}
#[test]
fn test_kernel_names() {
assert_eq!(LinearKernel::new().name(), "Linear");
assert_eq!(CosineKernel::new().name(), "Cosine");
assert_eq!(
RbfKernel::new(RbfKernelConfig::new(0.5))
.expect("unwrap")
.name(),
"RBF"
);
assert_eq!(
PolynomialKernel::new(2, 1.0).expect("unwrap").name(),
"Polynomial"
);
}
#[test]
fn test_psd_property() {
let kernel = LinearKernel::new();
assert!(kernel.is_psd());
let kernel = RbfKernel::new(RbfKernelConfig::new(0.5)).expect("unwrap");
assert!(kernel.is_psd());
}
}