File size: 1,202 Bytes
fe79a8f
 
 
 
 
 
 
fcbfe77
fe79a8f
 
 
 
 
 
 
 
 
 
 
82f2206
 
b82152e
 
fe79a8f
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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=0, euclidean=0, passing_threshold=40, 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,
        'euclidean': 0
    }
    
    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