Last active
June 14, 2024 00:56
-
-
Save calebdre/7fd83603d9b3a251bfe6c83038d72381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const calculateAveragePrecision = ( | |
sampleQuery: SampleQuery, | |
retrievedResults: QueryResult[], | |
k: number | |
) => { | |
// get the function names from the validation set | |
const relevantFunctions = sampleQuery.expectedFunctions.map((func) => func.functionName) | |
// get the function names from the retrieved results | |
const retrievedFunctionNames = retrievedResults.map((result) => result.funcName) | |
let relevantCount = 0 | |
let precisionSum = 0 | |
for (let i = 0; i < k; i++) { | |
// check if the function from the retrieved results is relevant | |
if (relevantFunctions.includes(retrievedFunctionNames[i])) { | |
// if so, increment the relevant count and calculate the precision | |
relevantCount++ | |
precisionSum += relevantCount / (i + 1) | |
} | |
} | |
return precisionSum / Math.min(k, relevantFunctions.length) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment