Of course. Here is a Python script with no external dependencies that generates a formatted table to visualize the score.
The script implements your scoring function, defines some sample ranges for distance and similarity, and then prints a neatly aligned table to the console.
The Script
#!/usr/bin/env python3
def calculate_score(dist, similarity):
"""
Calculates a score based on distance and similarity.
The formula is: score = dist + 500.0 * (1.0 - similarity)
- Lower scores are better.
- A perfect match (similarity=1.0, dist=0) results in a score of 0.
- The score increases as distance increases or similarity decreases.
"""
return float(dist) + 500.0 * (1.0 - float(similarity))
def print_score_table():
"""
Generates and prints a table visualizing the score for various
distance and similarity values.
"""
# --- Define the values you want to see in the table ---
# Similarity is typically between 0.0 (dissimilar) and 1.0 (identical)
similarities = [1.0, 0.95, 0.9, 0.8, 0.7, 0.5, 0.25, 0.0]
# Distance can be any non-negative number
distances = [0, 1, 5, 10, 25, 50, 100, 200]
# --- Formatting settings for the table ---
# Width of the first column (for distance labels)
first_col_width = 10
# Width of the subsequent data columns
data_col_width = 10
# --- Print Header Row ---
# Print the top-left corner label
print(f"{'Dist \\ Sim':<{first_col_width}}", end="|")
# Print the similarity values as column headers
for sim in similarities:
print(f"{sim:^{data_col_width}.2f}", end="")
print() # End the header line
# --- Print Separator Line ---
separator = "-" * first_col_width + "+" + "-" * (data_col_width * len(similarities))
print(separator)
# --- Print Data Rows ---
# Iterate over each distance to create a row
for dist in distances:
# Print the distance value as the row header
print(f"{dist:<{first_col_width}.1f}", end="|")
# In the same row, calculate and print the score for each similarity
for sim in similarities:
score = calculate_score(dist, sim)
print(f"{score:^{data_col_width}.2f}", end="")
print() # End the row with a newline
if __name__ == "__main__":
print("Score Calculation Table")
print("Formula: score = dist + 500.0 * (1.0 - similarity)")
print("Lower scores indicate a better match.\n")
print_score_table()
How to Run
- Save the code above as a Python file (e.g.,
score_visualizer.py).
- Run it from your terminal:
python3 score_visualizer.py
Example Output
Running the script will produce a table like this:
Score Calculation Table
Formula: score = dist + 500.0 * (1.0 - similarity)
Lower scores indicate a better match.
Dist \ Sim| 1.00 0.95 0.90 0.80 0.70 0.50 0.25 0.00
----------+--------------------------------------------------------------------------------
0.0 | 0.00 25.00 50.00 100.00 150.00 250.00 375.00 500.00
1.0 | 1.00 26.00 51.00 101.00 151.00 251.00 376.00 501.00
5.0 | 5.00 30.00 55.00 105.00 155.00 255.00 380.00 505.00
10.0 | 10.00 35.00 60.00 110.00 160.00 260.00 385.00 510.00
25.0 | 25.00 50.00 75.00 125.00 175.00 275.00 400.00 525.00
50.0 | 50.00 75.00 100.00 150.00 200.00 300.00 425.00 550.00
100.0 | 100.00 125.00 150.00 200.00 250.00 350.00 475.00 600.00
200.0 | 200.00 225.00 250.00 300.00 350.00 450.00 575.00 700.00
How to Customize
You can easily change the values to be tested by modifying the similarities and distances lists at the top of the print_score_table function.