pub struct SpectralSampler {
pub epsilon: f64,
}Expand description
Samples edges from a graph proportional to their spectral importance.
The sampling probability for edge e = (u, v, w) is:
p(e) = min(1, C * score(e) * log(n) / epsilon^2)where C is a normalisation constant chosen so the expected number of
sampled edges matches budget. Kept edges are reweighted by w / p(e)
to make the sparsifier an unbiased estimator of the Laplacian.
Fields§
§epsilon: f64Approximation parameter.
Implementations§
Source§impl SpectralSampler
impl SpectralSampler
Sourcepub fn sample_edges(
&self,
scores: &[EdgeImportance],
budget: usize,
backbone_edges: &HashSet<(usize, usize)>,
) -> SparseGraph
pub fn sample_edges( &self, scores: &[EdgeImportance], budget: usize, backbone_edges: &HashSet<(usize, usize)>, ) -> SparseGraph
Sample edges from graph using the provided importance scores,
returning a new SparseGraph with at most budget edges.
Backbone edges (if any) should be marked in backbone_edges; they
are always included and reweighted to weight * 1.0 (kept as-is).
Sourcepub fn sample_single_edge(
&self,
importance: &EdgeImportance,
n_vertices: usize,
total_importance: f64,
budget: usize,
) -> Option<(usize, usize, f64)>
pub fn sample_single_edge( &self, importance: &EdgeImportance, n_vertices: usize, total_importance: f64, budget: usize, ) -> Option<(usize, usize, f64)>
Incrementally add a single edge to the sparsifier, deciding whether to keep it based on its importance.
Trait Implementations§
Source§impl Clone for SpectralSampler
impl Clone for SpectralSampler
Source§fn clone(&self) -> SpectralSampler
fn clone(&self) -> SpectralSampler
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SpectralSampler
impl Debug for SpectralSampler
Source§impl<'de> Deserialize<'de> for SpectralSampler
impl<'de> Deserialize<'de> for SpectralSampler
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SpectralSampler
impl RefUnwindSafe for SpectralSampler
impl Send for SpectralSampler
impl Sync for SpectralSampler
impl Unpin for SpectralSampler
impl UnsafeUnpin for SpectralSampler
impl UnwindSafe for SpectralSampler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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