Skip to content

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).

Terminal window
pip install "hypermesh[analytics]" # numpy + scipy
import hypermesh as hm
db = hm.connect("/var/lib/hypermesh/data")
a = db.analytics("CoProximity") # -> hypermesh.analytics.Analytics
# Structural summary
a.summary()
a.density()
a.redundancy()
a.node_degree() # {node_id: degree}; pass node_id=5 for one node
a.hyperedge_size() # {edge_idx: size}
# Importance / centrality
a.pagerank()
a.katz_centrality(alpha=0.1)
a.eigenvector_centrality()
a.weighted_degree()
a.hedc()
# Spectral
a.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 dynamics
a.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).

# Easiest: snapshot a whole table into a sparse HypergraphPy
hg = db.to_hypergraph("CoProximity")
print(hg.n_nodes, hg.n_edges)
# Or build from rows you already fetched
from hypermesh.analytics import build_hypergraph
rows = list(db.execute("MATCH HYPEREDGE (he:CoProximity) RETURN *"))
hg = build_hypergraph(rows)
import hypermesh as hm
hg = db.to_hypergraph("CoProximity")
g = hm.interop.to_networkx(hg) # bipartite NetworkX graph
H = hm.interop.to_hypernetx(hg) # HyperNetX Hypergraph
X = hm.interop.to_xgi(hg) # XGI Hypergraph
df = hm.interop.to_pandas(hg) # node/edge incidence DataFrame
hm.interop.write_hif(hg, "graph.hif.json") # portable HIF JSON

See Interoperability for the full matrix.

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.