|
def normalize_euclidean(euclidean, max_value): |
|
""" |
|
Normalize the Euclidean distance to a 0-100 scale, where 0 is the maximum distance |
|
and 100 is the minimum distance. |
|
""" |
|
return max(0, 100 - (euclidean / max_value) * 100) |
|
|
|
def calculate_passing(sequence, phonetic, cosine, euclidean, passing_threshold=70, euclidean_max=200): |
|
|
|
sequence_normalized = sequence * 100 |
|
phonetic_normalized = phonetic * 100 |
|
|
|
|
|
euclidean_similarity = normalize_euclidean(euclidean, euclidean_max) |
|
|
|
|
|
|
|
|
|
weights = { |
|
'sequence': 0.35, |
|
'phonetic': 0.35, |
|
'cosine': 0.10, |
|
'euclidean': 0.20 |
|
} |
|
|
|
weighted_score = ( |
|
sequence_normalized * weights['sequence'] + |
|
phonetic_normalized * weights['phonetic'] + |
|
cosine * weights['cosine'] + |
|
euclidean_similarity * weights['euclidean'] |
|
) |
|
|
|
|
|
is_passing = weighted_score >= passing_threshold |
|
|
|
return weighted_score, is_passing |