2

我有 nsga3(进化算法)的代码,但我得到错误“numpy.ndarray”对象没有属性“fitness”。为 NSGA-III 选择生成参考点。此代码基于jMetal NSGA-III implementation <https://github.com/jMetal/jMetal>_。请帮助消除此错误

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)
4

1 回答 1

1

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

于 2018-06-19T12:10:10.530 回答