У объекта 'numpy.ndarray' нет атрибута 'fitness'

1

У меня есть этот код для nsga3 (эволюционный алгоритм), но я получаю, что объект "numpy.ndarray" ошибки не имеет атрибута "пригодность". Создает опорные точки для выбора 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)
Теги:
deap
evolutionary-algorithm

1 ответ

1

Вы можете проверить, как подготовить вход для find_ideal_point в этом ноутбуке jupyter. Реализация связана с записями из deap.tools.Logbook, который является "записями эволюции как хронологический список словарей", а не массивами NumPy.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню