Skip to main content

motifs_randesu_estimate

Function motifs_randesu_estimate 

Source
pub fn motifs_randesu_estimate(
    graph: &Graph,
    size: u32,
    cut_prob: Option<&[f64]>,
    sample: Option<&[VertexId]>,
    sample_size: usize,
    seed: u64,
) -> IgraphResult<f64>
Expand description

Estimate the total number of connected induced subgraphs of a given size by sampling root vertices.

This is the sampling counterpart of motifs_randesu_no. Instead of using every vertex as a search root, it visits only the vertices in sample (or a uniform random sample of sample_size vertices when sample is None) and scales the raw count by vcount / sample_size. It is intended for graphs too large to enumerate every connected subgraph.

Counterpart of igraph_motifs_randesu_estimate() in references/igraph/src/misc/motifs.c.

§Arguments

  • graph — the input graph.
  • size — motif size (must be ≥ 3).
  • cut_prob — optional per-level branch-cut probabilities. When Some, it must have length size; element l is the probability of pruning the search at level l. Passing None performs a complete search over the sampled roots (equivalent to an all-zero vector) and draws no random numbers, so the result is fully deterministic.
  • sample — explicit sample of root vertex IDs. When Some, sample_size is ignored.
  • sample_size — number of root vertices to draw uniformly without replacement when sample is None.
  • seed — seeds the internal PRNG used for random sampling and for branch cutting.

§Errors

  • InvalidArgumentsize < 3, cut_prob length disagrees with size, a sampled vertex ID is out of range, the effective sample is empty, or sample_size exceeds the vertex count.

§Examples

use rust_igraph::{Graph, motifs_randesu_estimate, motifs_randesu_no};

// Complete graph K5 has C(5,3) = 10 triangles.
let mut g = Graph::with_vertices(5);
for u in 0..5u32 {
    for v in (u + 1)..5 {
        g.add_edge(u, v).unwrap();
    }
}
// Sampling every vertex with no cutting reproduces the exact count.
let all: Vec<u32> = (0..5).collect();
let est = motifs_randesu_estimate(&g, 3, None, Some(&all), 0, 0).unwrap();
let exact = motifs_randesu_no(&g, 3).unwrap();
assert!((est - exact).abs() < 1e-10);