首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“numpy.ndarray”对象没有属性“fitness”

“numpy.ndarray”对象没有属性“fitness”
EN

Stack Overflow用户
提问于 2018-06-19 19:41:20
回答 1查看 703关注 0票数 2

我有这段nsga3(进化算法)的代码,但我得到错误'numpy.ndarray‘对象没有属性’fitness‘。此代码基于jMetal NSGA-III implementation <https://github.com/jMetal/jMetal>_。请帮助删除此错误

代码语言:javascript
复制
import copy
import random
import numpy as np
from deap import tools


class ReferencePoint(list):   # A reference point exists in objective space an has a set of individuals associated with it

    def __init__(self, *args):
        list.__init__(self, *args)
        self.associations_count = 0
        self.associations = []



def generate_reference_points(num_objs, num_divisions_per_obj):

    def gen_refs_recursive(work_point, num_objs, left, total, depth):
        if depth == num_objs - 1:
            work_point[depth] = left/total
            ref = ReferencePoint(copy.deepcopy(work_point))
            return [ref]
        else:
            res = []
            for i in range(left):
                work_point[depth] = i/total
                res = res + gen_refs_recursive(work_point, num_objs, left-i, total, depth+1)
            return res
    print(gen_refs_recursive([0]*num_objs, num_objs, num_objs*num_divisions_per_obj,
                              num_objs*num_divisions_per_obj, 0))



def find_ideal_point(individuals):
    'Finds the ideal point from a set individuals.'
    current_ideal = [np.infty] * len(individuals[0].fitness.values)  # Here th error is coming 
    for ind in individuals:
        # Use wvalues to accomodate for maximization and minimization problems.
        current_ideal = np.minimum(current_ideal,
                                   np.multiply(ind.fitness.wvalues, -1))
    print("Ideal POint is\n",current_ideal)




global individulas
individulas=np.random.rand(10,4)
generate_reference_points(2, 4)
find_ideal_point(individulas)
EN

回答 1

Stack Overflow用户

发布于 2018-06-19 20:10:11

您可以在this jupyter notebook中检查如何准备find_ideal_point的输入。该实现处理来自deap.tools.Logbook的记录,它是“作为字典的时间顺序列表的演变记录”,而不是NumPy数组。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50927555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档