Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-111

Novelty Search Score

Problem

Compute the novelty score of an individual against an archive.

Return the average Euclidean distance to the k nearest archive points, using all points when the archive holds fewer than k. Return 0.0 for an empty archive or a non-positive k.

Hint

Sort the distances and average the smallest k.

Test cases

case 1
in: [[0,0],[[1,0],[0,2],[3,4]],2]
expected: 1.5
case 2
in: [[0,0],[[1,0],[0,2],[3,4]],1]
expected: 1
case 3
in: [[0,0],[[1,0],[0,2],[3,4]],10]
expected: 2.6666666666666665
case 4
in: [[0,0],[],3]
expected: 0
Starter codePython
def novelty_score(individual, archive, k):
    # Your code here
    pass

4 test cases · run your code against them in the editor