A correlation calculation starts when you decide which observations belong together. Here each observation pairs an alignment inlier count with an architecture drift score for the same staged room. Both variables are numeric, but a numeric drift value can survive a failed alignment because the scoring procedure has an unaligned fallback. Including that value would mix different kinds of comparisons. The published benchmark results provide the context for the measurements. The calculation below uses a flat CSV export of them with the columns tool, room, alignment_ok, alignment_inliers, architecture_drift and drift_aligned.
Choose the pairs
Use the tool and room fields together as the record key. The file contains 119 distinct records and no key repeats. The dictionary in the example collapses identical copies if present. If the same key ever arrives with conflicting fields, the script stops at that key. Without a date or another indication of precedence, silently keeping whichever record appeared last would let file order decide the result.
Keep a record only if alignment_ok is the literal string "True" and both measurements are populated. For drift_aligned, the exclusion is the literal string "False". This distinction matters because a CSV reader returns text, and a nonempty string containing the word False is truthy in Python. After selection, 85 paired observations remain. Build the pairs before extracting the columns so that sorting or filtering a column cannot accidentally give a score to the wrong room.
Compute both coefficients
Pearson correlation works on the measured values. For Spearman, replace the counts with their ranks, do the same independently for the drift scores, then calculate Pearson correlation on those ranks. Equal values share the average of their occupied positions. The function below sorts indices so it can write each rank back to the observation it came from. Run the snippet with python3 -I from the directory containing the CSV.
import csv
from itertools import groupby
from statistics import correlation, median
def ranks(values):
result = [0.0] * len(values)
ordered = sorted(range(len(values)), key=values.__getitem__)
start = 1
for _, group in groupby(ordered, key=values.__getitem__):
indices = list(group)
rank = start + (len(indices) - 1) / 2
for index in indices:
result[index] = rank
start += len(indices)
return result
with open("inl_drift.csv", newline="") as source:
rows = {}
for row in csv.DictReader(source):
key = row["tool"], row["room"]
if key in rows and rows[key] != row:
raise ValueError("Conflicting records for the same pair")
rows[key] = row
pairs = [(int(r["alignment_inliers"]), float(r["architecture_drift"]))
for r in rows.values()
if r["alignment_ok"] == "True" and r["drift_aligned"] != "False"
and r["alignment_inliers"] and r["architecture_drift"]]
x, y = zip(*pairs)
print("Records:", len(pairs))
print(f"Pearson: {correlation(x, y):.4f}")
print(f"Spearman: {correlation(ranks(x), ranks(y)):.4f}")
print("Median drift below 50:", median(d for n, d in pairs if n < 50))
print("Median drift at or above 50:", median(d for n, d in pairs if n >= 50))
The output from the CSV was:
Records: 85
Pearson: -0.4955
Spearman: -0.5039
Median drift below 50: 26.450000000000003
Median drift at or above 50: 21.0
Check the middle values
The long decimal in the output comes from binary floating point arithmetic. You can check it directly against the source values. In the lower count group, the middle drift values in sorted order are 26.3 and 26.6. Their midpoint is exactly 26.45 in decimal arithmetic, which is 26.5 when rounded half up to one decimal place. The higher count group has an odd number of records, so its middle value, 21.0, is already an observed score. This check also explains why a group median need not be a score assigned to any photograph.
Read the sign in context
The negative Pearson coefficient means that larger inlier counts tended to accompany lower drift. The similar Spearman coefficient says the tendency is visible in the ordering too. Ranking discards the distances between successive observations, so agreement in sign answers a slightly different question from the Pearson calculation. It cannot independently validate the measurement: both calculations start from exactly the same selected pairs.
Keep the units of observation in mind when interpreting that result. The data reuse the same 10 rooms across tools. A pooled coefficient describes the records considered together. It does not tell you whether the same relationship holds within each room or how a new photograph would score. More fundamentally, the inliers support the alignment used to measure drift. A region that supplies consistent matches may also supply agreeing edges after alignment. The pattern partly measures itself, and the calculations do not show that more inliers cause better results.
Top comments (0)