Analytics Cookbook
hypermesh.analytics exposes the hypergraph analytics engine: degree and
centrality measures, PageRank/Katz, the Zhou Laplacian / spectral measures,
s-metrics, and temporal measures (burstiness, changepoints, activity windows).
pip install "hypermesh[analytics]" # numpy + scipyGet an analytics handle
Section titled “Get an analytics handle”import hypermesh as hm
db = hm.connect("/var/lib/hypermesh/data")a = db.analytics("CoProximity") # -> hypermesh.analytics.AnalyticsRecipes
Section titled “Recipes”# Structural summarya.summary()a.density()a.redundancy()a.node_degree() # {node_id: degree}; pass node_id=5 for one nodea.hyperedge_size() # {edge_idx: size}
# Importance / centralitya.pagerank()a.katz_centrality(alpha=0.1)a.eigenvector_centrality()a.weighted_degree()a.hedc()
# Spectrala.spectral_gap()a.cheeger_constant()a.zhou_laplacian_eigenvalues(k=6)
# s-connectivity (hyperedge dual graph)a.s_distance(s=2)a.s_closeness(s=2)a.s_diameter(s=2)a.s_efficiency(s=2)
# Temporal dynamicsa.burstiness()a.temporal_changepoints()a.activity_windows()a.hyperedge_persistence()Against a remote server, analytics run server-side and take the measure name as an argument:
db.analytics("CoProximity", "pagerank"),db.analytics("CoProximity", "s_distance", s=2).
Build a hypergraph object directly
Section titled “Build a hypergraph object directly”# Easiest: snapshot a whole table into a sparse HypergraphPyhg = db.to_hypergraph("CoProximity")print(hg.n_nodes, hg.n_edges)
# Or build from rows you already fetchedfrom hypermesh.analytics import build_hypergraph
rows = list(db.execute("MATCH HYPEREDGE (he:CoProximity) RETURN *"))hg = build_hypergraph(rows)Export to other graph libraries
Section titled “Export to other graph libraries”import hypermesh as hm
hg = db.to_hypergraph("CoProximity")g = hm.interop.to_networkx(hg) # bipartite NetworkX graphH = hm.interop.to_hypernetx(hg) # HyperNetX HypergraphX = hm.interop.to_xgi(hg) # XGI Hypergraphdf = hm.interop.to_pandas(hg) # node/edge incidence DataFramehm.interop.write_hif(hg, "graph.hif.json") # portable HIF JSONSee Interoperability for the full matrix.
Reporting
Section titled “Reporting”Turn detection output into shareable artefacts:
bundle = hm.reports.build_stix_bundle(detection_result, entity_map, report_id="r-1")html = hm.reports.render_html_report(detection_result, entity_map, report_id="r-1")See the full method list in the API reference.