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).
When exclude_noise is false, noise (-1) is always retained if present.
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
cluster_score_percentile_summary(assignments)
¶
Percentiles of cluster_score overall, emergent-only, and noise rows.
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, min_within_cluster_fraction=0.0)
¶
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).
When min_within_cluster_fraction > 0, entity slices below that share of their
cluster's total mass are rolled into Other (...).
Source code in pelinker/cluster_composition_viz.py
limit_entity_flow_for_plots(flow_df, *, max_clusters=DEFAULT_MAX_CLUSTERS_FOR_PLOTS, max_entities=DEFAULT_MAX_ENTITIES_FOR_FLOW_PLOTS, min_within_cluster_fraction=0.0)
¶
Subset a KB-in entity→cluster flow table for Sankey charts.
Keeps top clusters by mass and top entities by total mass; drops the rest
(no synthetic Other labels). Thin within-cluster edges below
min_within_cluster_fraction are dropped.
Source code in pelinker/cluster_composition_viz.py
top_cluster_ids_by_mass(mass, *, max_clusters, always_include=None)
¶
Cluster ids ordered by descending total mass (optionally truncated).
always_include ids present in mass are appended after the truncated
ranking (so noise -1 is not dropped when capping emergent clusters).
Source code in pelinker/cluster_composition_viz.py
with_noise_cluster_label(cluster_labels)
¶
Copy labels and ensure HDBSCAN noise maps to :data:NOISE_CLUSTER_LABEL.