-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_basic_sampling.py
More file actions
44 lines (30 loc) · 1.38 KB
/
Copy path01_basic_sampling.py
File metadata and controls
44 lines (30 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Basic graph sampling with AetherGraph.
Demonstrates loading a graph, configuring a sampler, and sampling neighborhoods.
"""
import logging
from aethergraph import Graph, Sampler, SamplingConfig
logging.basicConfig(level=logging.INFO, format="%(message)s")
logger = logging.getLogger(__name__)
def main() -> None:
"""Run the basic sampling example.
Loads a graph from disk, creates a sampler with 2-hop configuration,
samples neighborhoods for seed nodes, and displays the results.
"""
logger.info("AetherGraph - Basic Sampling")
logger.info("=" * 50)
graph = Graph.load("../test_data/simple_graph.bin")
logger.info(f"Loaded graph: {graph.num_nodes:,} nodes, {graph.num_edges:,} edges")
stats = graph.stats()
logger.info(f"Avg degree: {stats['avg_degree']:.2f}, max: {stats['max_degree']}")
config = SamplingConfig(num_neighbors=[3, 2], replace=False, seed=42)
sampler = Sampler(graph, config)
logger.info(f"Sampler: {config.num_neighbors} neighbors per hop")
seed_nodes = [0, 1, 2]
subgraph = sampler.sample(seed_nodes)
logger.info(f"Sampled {subgraph.num_nodes} nodes, {subgraph.num_edges} edges")
logger.info(f"Edge index shape: {subgraph.edge_index.shape}")
for node in seed_nodes:
neighbors = graph.neighbors(node)
logger.info(f"Node {node}: {len(neighbors)} neighbors")
if __name__ == "__main__":
main()