qbiocode.apps.quvine.data.subgraph module#

Summary#

Functions:

add_neighbors_until_budget

expand_neighborhood

Expand neighborhood around roots up to given hop radius using adjacency dict access.

fill_degree_matched_until_budget

fill_random_until_budget

Fill remaining budget preferring nodes adjacent to keep; fall back to random.

induce_subgraph_by_nodes

Materialize an induced subgraph without using G.subgraph(...) to avoid view contamination.

materialize_undirected_simple_graph

Return a fully materialized undirected simple nx.Graph (no views, no DiGraph internals).

subsample_nodes

subsample_nodes_with_protected

Subsample nodes while preserving a protected set.

Reference#

materialize_undirected_simple_graph(G)[source]#

Return a fully materialized undirected simple nx.Graph (no views, no DiGraph internals). This avoids traversal issues from graph views and preserves node/edge attributes.

Return type:

Graph

induce_subgraph_by_nodes(G, nodes)[source]#

Materialize an induced subgraph without using G.subgraph(…) to avoid view contamination.

Return type:

Graph

expand_neighborhood(G, roots, radius)[source]#

Expand neighborhood around roots up to given hop radius using adjacency dict access. No G.neighbors() calls;

Return type:

Set[Hashable]

add_neighbors_until_budget(G, roots, keep, max_nodes, rng)[source]#
fill_random_until_budget(G, keep, max_nodes, rng)[source]#

Fill remaining budget preferring nodes adjacent to keep; fall back to random.

fill_degree_matched_until_budget(G, keep, max_nodes, rng, *, reference_nodes=None)[source]#
Return type:

Set[Hashable]

subsample_nodes_with_protected(G, protected, max_nodes, rng, *, expand_radius=None, require_full_budget=True, degree_matched_fill=False, degree_matched_trim=False, degree_reference_nodes=None)[source]#

Subsample nodes while preserving a protected set.

Workflow:

  • keep all protected nodes

  • optionally expand by hop radius around them

  • if expansion exceeds budget, optionally trim in a degree-matched way

  • fill remaining budget either with neighborhood/random expansion or with degree-matched sampling from the remaining graph

Return type:

Graph

subsample_nodes(G, seeds, targets, max_nodes, radius, rng, *, degree_matched_fill=False, degree_matched_trim=False, degree_reference_nodes=None)[source]#
Return type:

Graph