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): # Normalize sequence and phonetic to 0-100 scale sequence_normalized = sequence * 100 phonetic_normalized = phonetic * 100 # Normalize Euclidean distance to a similarity measure (0-100 scale) euclidean_similarity = normalize_euclidean(euclidean, euclidean_max) # Calculate the weighted average 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'] ) # Check if the weighted score meets or exceeds the passing threshold is_passing = weighted_score >= passing_threshold return weighted_score, is_passing