GithubHelp home page GithubHelp logo

haris989 / nsga-ii Goto Github PK

View Code? Open in Web Editor NEW
384.0 384.0 158.0 8 KB

This is a python implementation of NSGA-II algorithm. NSGA is a popular non-domination based genetic algorithm for multi-objective optimization. It is a very effective algorithm but has been generally criticized for its computational complexity, lack of elitism and for choosing the optimal parameter value for sharing parameter σshare. A modified version, NSGA II was developed, which has a better sorting algorithm , incorporates elitism and no sharing parameter needs to be chosen a priori.

License: MIT License

Python 100.00%

nsga-ii's People

Contributors

haris989 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nsga-ii's Issues

Result differ from R

Hello, I test the code and compare the results with R. Why is the number of result values different from R's result? I am a beginner to the NSGA. I appreciate if anyone has idea about it. Many thanks.

Some questions hoping for answering

Hello Haris,
First of all thank you very much for sharing your work! I have some questions regarding the code.

  1. In line 136, the output of non_dominated_sorted_solution2_1 will always be 0,1,2... for every i, so it seems that the code is meaningless. I think what we should do is to align crowding distance and front order, which seems not to appear in the code.

The code below is the original code which seems not to achieve the target aligning crowding distance and front order.

for i in range(0,len(non_dominated_sorted_solution2)):
non_dominated_sorted_solution2_1 = [index_of(non_dominated_sorted_solution2[i][j], non_dominated_sorted_solution2[i] ) for j in range(0,len(non_dominated_sorted_solution2[i]))]
  1. In line 22, the definition of index_of(a,list) is not rigorous. If there are two same values which equal to a in the list, the function only outputs the first position. Thus, using the list.index(a) perhaps is a better choice.
def index_of(a,list):
    for i in range(0,len(list)):
        if list[i] == a:
            return i
    return -1
  1. The operations of mutation and crossover are strange, because it seems the parent is not correlated with children at all. From the code, we can see no matter which the selected individuals a, b are, the crossover will give a new random solution.
def crossover(a,b):
    r=random.random()
    if r>0.5:
        return mutation((a+b)/2)
    else:
        return mutation((a-b)/2)

def mutation(solution):
    mutation_prob = random.random()
    if mutation_prob <1:
        solution = min_x+(max_x-min_x)*random.random()
    return solution
  1. The crowding distance was also miscalculated and should have been calculated for each target and then added up, which has mentioned by other many times.

Crowding Distance

There is an error in Crowding Distance function.
It should be values1[i-1] - values1[i+i]
and values2[i-1] - values2[i+1]

Mutation prob and multi variate function

Hello Haris,

First of all thank you very much for sharing this work. I have a question regarding mutation prob. You wrote if mutation_prob < 1 but as random.random() outputs values between 0 and 1, should we make it less than 1 ? and I have a question regarding multi variate objective function, how would you define the solutions and the mutation ? i did it this way:

def mutation(solution):
    mutation_prob = random.random()
    if mutation_prob <0.5:
        solution = [min_x+(max_x-min_x)*random.random(), min_x+(max_x-min_x)*random.random()]
    return solution

solution=[[min_x+(max_x-min_x)*random.random(),min_x+(max_x-min_x)*random.random()]  for i in range(0,pop_size)]

thanks

Why muliply with -1 to plot

Hey,

I just remarked, that to plot all results for function1 and function2 are multplied by -1 and I can't understand why.

Cheers
Fabi

Why do you calculate the index of the minimum value of a list to calculate three times?

#Function to sort by values
def sort_by_values(list1, values):
    sorted_list = []
    while(len(sorted_list)!=len(list1)):
        if index_of(min(values),values) in list1:
            sorted_list.append(index_of(min(values),values))
        values[index_of(min(values),values)] = math.inf
    return sorted_list

Why do you calculate the index of the minimum value of a list to calculate three times?
And does this function not generate a return value the same as list1?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.