pelinker.cluster_composition_viz¶
Entity-weighted cluster composition tables and emergent-cluster reporting.
aggregate_cluster_entity_mass(assignments, *, weight_by_entity=True, exclude_noise=True)
¶
Long table of weighted mass per (cluster, entity).
Columns: cluster (int), entity (str), count (float).
Source code in pelinker/cluster_composition_viz.py
build_cluster_composition_df(assignments, *, top_n=3, weight_by_entity=True, exclude_noise=True, max_clusters=None)
¶
Aggregate per-(cluster, entity) mass and keep top-N entities plus Other per cluster.
When weight_by_entity is true, each mention row contributes
1 / sqrt(n_mentions(entity)) instead of unit weight.
max_clusters keeps only the largest emergent clusters by total mass (for plots).
Source code in pelinker/cluster_composition_viz.py
build_emergent_clusters_catalog(composition, consensus_names, assignments, *, min_cluster_size, top_entities_per_cluster=5, weight_by_entity=True)
¶
Build JSON-serializable emergent-cluster catalog with stable cluster entity ids.
Each cluster gets entity_id cluster:{id}, display name, mass, and top entities
with within-cluster fractions.
Source code in pelinker/cluster_composition_viz.py
cluster_entity_mass_summary(assignments)
¶
Counts for fit logs and composition JSON metadata.
Source code in pelinker/cluster_composition_viz.py
count_emergent_clusters(assignments)
¶
Number of distinct emergent cluster labels (excludes -1).
Source code in pelinker/cluster_composition_viz.py
entity_mention_weights(entities)
¶
Per-row weight 1 / sqrt(n_mentions(entity)) in the sample.
Source code in pelinker/cluster_composition_viz.py
filter_emergent_assignments(assignments)
¶
Drop HDBSCAN noise rows (cluster -1).
Source code in pelinker/cluster_composition_viz.py
is_emergent_cluster(cluster)
¶
True for HDBSCAN cluster ids other than noise (-1).
limit_composition_for_flow_plots(composition_df, *, max_clusters=DEFAULT_MAX_CLUSTERS_FOR_PLOTS, max_entities=DEFAULT_MAX_ENTITIES_FOR_FLOW_PLOTS)
¶
Subset a long composition table for Sankey/bump charts.
Keeps top clusters by mass and top entities by total mass (drops Other (...) rows
from entity ranking, then re-adds per-cluster Other slices when needed).
Source code in pelinker/cluster_composition_viz.py
top_cluster_ids_by_mass(mass, *, max_clusters)
¶
Cluster ids ordered by descending total mass (optionally truncated).