I tried running platypus which can solve a little optimization problem-Part 2

Of the previous article I tried running platypus which can solve a little optimization problem So, I tried to move the DTLZ2 problem problem in the document. But I'm not sure because this document isn't written in detail.

It's a simple problem, and I'll try to understand how it is calculated.

minimize (x,-x)\qquad  for\quad x\in[-10,10]

I've changed the problem in the plotypus example a bit. The meaning of this problem is that when $ x $ takes $ -10 $ to $ 10 $, the two functions

y=f(x)\qquad y=-f(x) 

What is the answer to minimize? Is the problem.

First is ʻimport. These three look good. from platypus import NSGAII, Problem, Real`

Next, create a function that is the basis of the multipurpose solution. def schaffer(x):return [x[0], (x[0]*(-1))]

Set the number of explanatory variables and the number of objective variables with problem = Problem (1, 2). In other words, I think that the explanatory variable $ x $ is one and the objective variable is two. next With problem.types [:] = Real (-10, 10), set the type and range of numbers given to x. I think Real is a declaration that it is probably a real number. Declare the function to calculate with problem.function = schaffer. Declare to solve the schaffer function as a problem.

With ʻalgorithm = NSGAII (problem), create an instance that solves the problem of the function declared in problem` in NSGAII.

ʻAlgorithm.run (10000)` is set to calculate repeatedly 10000 times, and the calculation is performed.

This is the basic, and if you change the settings, it seems to work somehow.

from platypus import NSGAII, Problem, Real

def schaffer(x):
    return [x[0], (x[0]*(-1))]

problem = Problem(1, 2)
problem.types[:] = Real(-10, 10)
problem.function = schaffer

algorithm = NSGAII(problem)
algorithm.run(10000)

The answer comes out and it seems that it is in result without permission, so take it out and draw a graph.

import matplotlib.pyplot as plt

plt.scatter([s.objectives[0] for s in algorithm.result],
            [s.objectives[1] for s in algorithm.result])
plt.xlim([-10, 10])
plt.ylim([-10, 10])
plt.xlabel("$f_1(x)$")
plt.ylabel("$f_2(x)$")
plt.show()

The result.

platypus_2.png

Well, the answer is as expected.

Recommended Posts

I tried running platypus which can solve a little optimization problem-Part 2
I tried to solve a combination optimization problem with Qiskit
I tried running alembic, a Python migration tool
Draw a graph in Julia ... I tried a little analysis
I implemented NSGA-Ⅲ, which is a multi-objective optimization problem.
I tried running pymc
I tried running python etc. from a bat file
[Python] I tried running a local server using flask
I tried running TensorFlow
I tried Bayesian optimization!
I tried a little bit of the behavior of the zip function
I tried using "Asciichart Py" which can draw a beautiful graph on the console with Python.
I relaxed the conditions a little and let optuna solve Sudoku
I tried Diagram as Code (Diagrams) which can manage the configuration diagram code
Can I be a data scientist?
I tried running GAN in Colaboratory
I tried Grumpy (Go running Python).
I tried running prolog with python 3.8.2.
I made a note of Google colaboratory which can use Spleeter easily.
I tried using "Streamlit" which can do the Web only with Python