ga.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:dx7-programmer 作者: yeeking 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号