reranker-v1 / utils.py
Aaron Snoswell
Revert "Whitespace and version bump"
97eec15
import math
import numpy as np
from scipy.spatial.distance import jensenshannon
def maxNormalize(scores):
max_score = max(scores)
normalized_scores = [score / max_score for score in scores]
return normalized_scores
def minmaxNormalization(scores):
min_score = min(scores)
max_score = max(scores)
normalized_scores = [(score - min_score) / (max_score - min_score) for score in scores]
return normalized_scores
def decayFunction(sorted_list):
result = []
for i,_ in enumerate(sorted_list, 1):
score = 1 / math.log2(i + 1)
result.append(score)
return result
def get_jsd_distance(vector_1, vector_2):
all_zeros = all(map(lambda x: x == 0, vector_1))
if all_zeros:
distance = 1
else:
distance = jensenshannon(vector_1, vector_2)
return distance
def linearCombination(rel_score, fairness_score, LAMBDA=0.5):
score = (LAMBDA * rel_score) + ((1-LAMBDA) * fairness_score)
return score