Code Monkey home page Code Monkey logo

de_algorithm_multi_objective_function's Introduction

A Differential Evolution Algorithm with side-objective function

In this Kernel, we modify the DE algorithm codes developed previously here. The modified DE Algorithm now can be used by taking multi-objective functions into account.

Steps taken are as follow:

  • The main objective function (fobj) and side objective function are defined.
  • The DE Algorithm written by Pablo R. Mier is modified and includes the new function called generate candidate.
  • The generate candidate function takes the main objective function (fobj) and side objective function and the boundaries into account to generates candidates.
  • The generate candidate function considered the side objective function along with maximum and minimum limitations to filter the candidates (See this following line in the generates function).
if side_obj_1_fitness[0] < 1000 and side_obj_1_fitness[0] > 900: 
  • Evaluate the side objective function and filter those candidates that are not satisfied the side_objective function.
  • Here we use side objective function and we want to make sure that the DE performs evolution on those candidates that are between 900 and 1000 values generated by side objective function.
def generate_candidate(fobj, side_obj_1, bounds):
    
        cond = True
        while cond == True:

            dimensions = len(bounds)
            pop = np.random.rand(1, dimensions)
            min_b, max_b = np.asarray(bounds).T
            diff = np.fabs(min_b - max_b)
            pop_denorm = min_b + pop * diff
            # calculate the fitness using fitness function and save it into the fitness parameter
            fitness = np.asarray([fobj(ind) for ind in pop_denorm])
            # calculate the side objective function and save it into the side object_1 parameter
            side_obj_1_fitness = np.asarray([side_obj_1(ind) for ind in pop_denorm])
            #evaluate the side objective function and filter those candidates
            #that are not satisfied the side_objective function.
            # Here we use side objective function and we want to make sure that the DE performs evolution on those candidates 
            # that is between 900 and 1000 values generated by side objective function.
            if side_obj_1_fitness[0] < 1000 and side_obj_1_fitness[0] > 900:
                cond = False
    #             print('candidate = ', pop_denorm)

    #     print('fitness = ', fitness[0]), print('side_obj_1_fitness = ', side_obj_1_fitness[0])
        return pop[0], pop_denorm[0] 
  • The De Algorithm modified to evaluate the new candidate's fitness taking both main and side objective functions into account. Check out the line in the main code (DE_Algorithm_Multi_Objective_Function\codes\Differential Evolution Algorithm Modified.ipynb).
fitness = np.asarray([fobj(ind) for ind in pop_denorm])
#Sub_Objective function are evaluated at the following.
side_obj_1_fitness = np.asarray([side_obj_1(ind) for ind in pop_denorm])
  • A new function (gene_trial_in_range) is defined which generates the trial candidates in predetermined ranges as follows.
def gene_trial_in_range(popsize, j, mut, dimensions, crossp, pop, min_b, diff):
   
   cond = True
   while cond == True:
       
       idxs = [idx for idx in range(popsize) if idx != j]
       a, b, c = pop[np.random.choice(idxs, 3, replace = False)]
       mutant = np.clip(a + mut * (b - c), 0, 1)
       cross_points = np.random.rand(dimensions) < crossp
       if not np.any(cross_points):
           cross_points[np.random.randint(0, dimensions)] = True

       trial = np.where(cross_points, mutant, pop[j])
       trial_denorm = min_b + trial * diff
       cond = False

   return trial_denorm, trial
  • You may run the program for a population of 5 and see the output along with their fitness after 4 iterations. Check out the results (res) as follow). The first array includes the 5 best candidates after 4 iterations. the second array includes each candidate's fitness (using a main-objective function) after 4 iterations.
(array([[9.71347573],
       [9.69980814],
       [9.72554979],
       [9.69181503],
       [9.67379587]]),
array([47.1758054 , 47.04313899, 47.29315934, 46.96563926, 46.79116331]),
4)

de_algorithm_multi_objective_function's People

Contributors

atashnezhad avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.