It is difficult to rank the importance of data points when you need to consider both how closely related they are to each other and where they are located spatially.
It ranks data points by looking at their connections and their geometric proximity at the same time.
It provides a way to prioritize information based on both context and location.
It was run inside an isolated container with no network access. This is the exact command and the real output it produced — captured process output, not written by a model.
$ python3 saliency_graph_tile.py Saliency Scores: A: 8.4852 B: 8.4852 C: 0.0000 Most salient node: A
A screenshot of that run.
A clean run proves this does what is shown above, in a CPU-only sandbox. It is a small research demo — not a production tool, and nothing here was published anywhere.
All of it — 84 lines, one file, standard library only.
# Saliency-Weighted-Graph-Tile Implementation
import math
from collections import defaultdict, deque
class Graph:
def __init__(self):
self.nodes = {}
self.edges = defaultdict(list)
self.spatial_index = defaultdict(list)
def add_node(self, node_id, coords, semantic_weight=1.0):
self.nodes[node_id] = {'coords': coords, 'semantic_weight': semantic_weight}
def add_edge(self, src, dst):
self.edges[src].append(dst)
self.edges[dst].append(src)
def partition_spatially(self, tile_size=1.0):
"""Assign nodes to spatial tiles using GeoJSON-style partitioning"""
for node_id, data in self.nodes.items():
x, y = data['coords']
tile_x = math.floor(x / tile_size)
tile_y = math.floor(y / tile_size)
self.spatial_index[(tile_x, tile_y)].append(node_id)
def calculate_reachability(self):
"""Recursive Graph-Node Reachability Score implementation"""
reachability = {}
for node in self.nodes:
# BFS to calculate shortest path to all other nodes
distances = {n: -1 for n in self.nodes}
distances[node] = 0
queue = deque([node])
while queue:
current = queue.popleft()
for neighbor in self.edges[current]:
if distances[neighbor] == -1:
distances[neighbor] = distances[current] + 1
queue.append(neighbor)
# Calculate average shortest path distance
total = sum(d for d in distances.values() if d != -1)
reachable_nodes = sum(1 for d in distances.values() if d != -1)
reachability[node] = (total / reachable_nodes) if reachable_nodes else 0
return reachability
def calculate_saliency(self, tile_size=1.0):
self.partition_spatially(tile_size)
reachability = self.calculate_reachability()
spatial_weights = defaultdict(float)
# Calculate spatial proximity weights
for tile, nodes in self.spatial_index.items():
for node in nodes:
# Inverse distance to other nodes in same tile (simplified)
spatial_weights[node] = sum(1 / (math.dist(self.nodes[node]['coords'], self.nodes[other]['coords']) + 1e-6) for other in nodes if other != node)
# Combine scores: reachability (graph) + spatial + semantic
saliency = {}
for node in self.nodes:
g_score = 1 / (reachability[node] + 1e-6) # Higher score = shorter paths
s_score = spatial_weights.get(node, 0)
semantic = self.nodes[node]['semantic_weight']
saliency[node] = g_score * s_score * semantic
return saliency
# Example usage
if __name__ == "__main__":
g = Graph()
# Add sample nodes with coordinates and semantic weights
g.add_node('A', coords=(0.0, 0.0), semantic_weight=1.2)
g.add_node('B', coords=(0.1, 0.1), semantic_weight=0.8)
g.add_node('C', coords=(1.0, 1.0), semantic_weight=1.5)
g.add_edge('A', 'B')
g.add_edge('B', 'C')
saliency_scores = g.calculate_saliency(tile_size=0.5)
print("Saliency Scores:")
for node, score in sorted(saliency_scores.items(), key=lambda x: x[1], reverse=True):
print(f"{node}: {score:.4f}")
# Output most salient node
most_salient = max(saliency_scores, key=saliency_scores.get)
print(f"\nMost salient node: {most_salient}")