Backbone¶
kenon.backbone.apply_disparity_filter(graph)
¶
Compute and attach disparity statistics to all edges in-place.
Adds the following attributes to each edge:
norm_weight: weight / node strengthalpha: disparity significancealpha_ptile: alpha percentile among all edges
Adds strength attribute to each node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
SemanticGraph
|
A weighted networkx Graph with |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of all alpha values (for threshold inspection). |
Contract
- Modifies the graph in-place.
- Every edge gets
norm_weight,alpha, andalpha_ptileattributes. - Every node gets a
strengthattribute.
Examples:
>>> import networkx as nx
>>> g = nx.Graph()
>>> g.add_edge("a", "b", weight=0.8)
>>> g.add_edge("b", "c", weight=0.3)
>>> g.add_edge("a", "c", weight=0.5)
>>> alphas = apply_disparity_filter(g)
>>> len(alphas) == g.number_of_edges()
True
Source code in kenon/backbone.py
kenon.backbone.extract_backbone(graph, min_alpha_ptile=0.5, min_degree=2)
¶
Extract the backbone of a graph using the disparity filter.
Removes edges whose alpha percentile falls below min_alpha_ptile,
then prunes isolated nodes with degree below min_degree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
SemanticGraph
|
Input weighted graph. Will be copied — original is not mutated. |
required |
min_alpha_ptile
|
float
|
Edges below this alpha percentile are removed. Must be in [0, 1]. Higher values = more aggressive pruning. |
0.5
|
min_degree
|
int
|
Nodes with degree below this after edge removal are pruned. |
2
|
Returns:
| Type | Description |
|---|---|
SemanticGraph
|
A new |
Contract
- Original graph is never mutated (deep copy).
- Result has <= nodes and <= edges compared to the original.
- All remaining nodes satisfy
degree >= min_degree.
Examples:
>>> import networkx as nx
>>> g = nx.path_graph(5)
>>> for u, v in g.edges():
... g[u][v]["weight"] = float(v + 1)
>>> backbone = extract_backbone(g, min_alpha_ptile=0.3)
>>> backbone.number_of_nodes() <= g.number_of_nodes()
True
Source code in kenon/backbone.py
kenon.backbone.disparity_integral(x, k)
¶
Compute the definite integral for the disparity filter PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Normalised edge weight. Must not equal 1.0. |
required |
k
|
float
|
Node degree. Must not equal 1.0. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Value of the integral |
Contract
xmust not equal 1.0 (division by zero).kmust not equal 1.0 (division by zero).
Examples:
Source code in kenon/backbone.py
kenon.backbone.get_disparity_significance(norm_weight, degree)
¶
Compute the alpha significance score for a single edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
norm_weight
|
float
|
Edge weight normalised by node strength. |
required |
degree
|
float
|
Degree of the node. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Alpha value in [0, 1]. Lower alpha = more significant. |
Contract
- If
degree<= 1, returns 0.0. - Result is clipped to [0, 1].
Examples: