def compute_fitness(target, candidate):
# first truncate the longer array
len_diff = np.abs(len(target) - len(candidate))
# truncate the longest one
a1 = target
a2 = candidate
if len(target) > len(candidate):# truncate a1, the target
a1 = a1[0:len(candidate)]
if len(candidate) > len(target):# truncate a2, the candidate
a2 = a2[0:len(target)]
dist = 0
for i in range(0, len(a1)):
dist = dist + euclidean(a1[i], a2[i])
if dist == 0:
return 1
else:
return 1/dist
评论列表
文章目录