pub fn sliced_wasserstein_graph_kernel(
features1: &[Vec<f64>],
features2: &[Vec<f64>],
num_projections: usize,
lambda: f64,
seed: u64,
) -> f64Expand description
Sliced Wasserstein graph kernel.
Compares graphs by computing the Sliced Wasserstein distance between their node feature distributions, then exponentiating:
k(G1, G2) = exp(-lambda * SW(features_G1, features_G2))
Each graph is represented as a set of node feature vectors (an empirical distribution in feature space). The SW distance projects both distributions onto random directions and averages the 1D Wasserstein distances.
For graphs without explicit node features, use structural_node_features
to compute degree, clustering coefficient, and average neighbor degree.
§Arguments
features1- Node features of graph 1 (n1 vectors of dimension d)features2- Node features of graph 2 (n2 vectors of dimension d)num_projections- Number of random projection directionslambda- Bandwidth parameter (larger = more sensitive to distance)seed- RNG seed for reproducible projections
§Example
use graphops::{sliced_wasserstein_graph_kernel, structural_node_features};
// Triangle vs path
let tri = vec![vec![1, 2], vec![0, 2], vec![0, 1]];
let path = vec![vec![1], vec![0, 2], vec![1]];
let f1 = structural_node_features(&tri);
let f2 = structural_node_features(&path);
let k = sliced_wasserstein_graph_kernel(&f1, &f2, 50, 1.0, 42);
assert!(k > 0.0 && k <= 1.0);