Skip to content

Commit

Permalink
README.RST
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Blank committed Mar 27, 2020
1 parent 088f24c commit d8f05eb
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 31 deletions.
34 changes: 24 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
:target: https://www.apache.org/licenses/LICENSE-2.0


.. |logo| image:: doc/source/_theme/custom_theme/static/img/pymoo_banner_github.png
:target: https://pymoo.org
:alt: pymoo


.. |animation| image:: doc/source/_theme/custom_theme/static/img/animation.gif
:target: https://pymoo.org
:alt: pymoo


.. _Github: https://github.com/msu-coinlab/pymoo
.. _Documentation: https://www.pymoo.org/
.. _Paper: https://arxiv.org/abs/2002.04504


.. raw:: html

<div>
<a href="https://pymoo.org"><img src="https://pymoo.org/_static/img/pymoo_banner_github.png" alt="pymoo"></a>
</div>

|travis| |python| |license|


|travis| |python| |license|
|logo|


Documentation_ / Paper_ / Installation_ / Usage_ / `Cite Us`_ / Contact_

Documentation_ / Paper_ / Installation_ / Usage_ / Citation_ / Contact_




Expand Down Expand Up @@ -76,14 +85,14 @@ However, for instance executing NSGA2:
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter
problem = get_problem("zdt3")
problem = get_problem("zdt1")
algorithm = NSGA2(pop_size=100)
res = minimize(problem,
algorithm,
('n_gen', 200),
seed=84,
seed=1,
verbose=True)
plot = Scatter()
Expand All @@ -94,8 +103,12 @@ However, for instance executing NSGA2:
.. _Cite Us:
Cite Us
|animation|



.. _Citation:
Citation
====================================================================

We are currently working on a journal publication for *pymoo*.
Expand Down Expand Up @@ -125,3 +138,4 @@ Feel free to contact me if you have any question:
| Computational Optimization and Innovation Laboratory (COIN)
| East Lansing, MI 48824, USA

30 changes: 22 additions & 8 deletions doc/github/README.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
:target: https://www.apache.org/licenses/LICENSE-2.0


.. |logo| image:: doc/source/_theme/custom_theme/static/img/pymoo_banner_github.png
:target: https://pymoo.org
:alt: pymoo


.. |animation| image:: doc/source/_theme/custom_theme/static/img/animation.gif
:target: https://pymoo.org
:alt: pymoo


.. _Github: https://github.com/msu-coinlab/pymoo
.. _Documentation: https://www.pymoo.org/
.. _Paper: https://arxiv.org/abs/2002.04504


.. raw:: html

<div>
<a href="https://pymoo.org"><img src="https://pymoo.org/_static/img/pymoo_banner_github.png" alt="pymoo"></a>
</div>

|travis| |python| |license|


|travis| |python| |license|
|logo|


Documentation_ / Paper_ / Installation_ / Usage_ / `Cite Us`_ / Contact_

Documentation_ / Paper_ / Installation_ / Usage_ / Citation_ / Contact_




Expand Down Expand Up @@ -76,8 +85,12 @@ However, for instance executing NSGA2:



.. _Cite Us:
Cite Us
|animation|



.. _Citation:
Citation
====================================================================

We are currently working on a journal publication for *pymoo*.
Expand Down Expand Up @@ -108,3 +121,4 @@ Feel free to contact me if you have any question:
| East Lansing, MI 48824, USA



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions pymoo/model/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
class Plot:

def __init__(self,
fig=None,
ax=None,
figsize=(8, 6),
title=None,
legend=False,
Expand All @@ -31,8 +33,8 @@ def __init__(self,
plt.rc('font', family='serif')

# the matplotlib classes
self.fig = None
self.ax = None
self.fig = fig
self.ax = ax
self.figsize = figsize

# the title of the figure - can also be a list if subfigures
Expand Down Expand Up @@ -81,6 +83,8 @@ def __init__(self,
self.bounds = bounds

def init_figure(self, n_rows=1, n_cols=1, plot_3D=False, force_axes_as_matrix=False):
if self.fig is not None or self.ax is not None:
return

if not plot_3D:
self.fig, self.ax = plt.subplots(nrows=n_rows, ncols=n_cols, figsize=self.figsize)
Expand Down
4 changes: 4 additions & 0 deletions pymoo/model/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def __new__(cls, n_individuals=0, individual=Individual()):
obj.individual = individual
return obj

@classmethod
def merge(cls, a, b):
return a.merge(b)

def merge(self, other):
if len(self) == 0:
return other
Expand Down
26 changes: 26 additions & 0 deletions pymoo/problems/single/multimodal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import autograd.numpy as anp

from pymoo.model.problem import Problem


def curve(problem, n_points=200):
X = anp.linspace(problem.xl[0], problem.xu[0], n_points)[:, None]
F = problem.evaluate(X)
return anp.column_stack([X, F])


class MultiModalSimple1(Problem):
def __init__(self, n_var=1):
super().__init__(n_var=n_var, n_obj=1, n_constr=0, xl=0, xu=1, type_var=anp.double)

def _evaluate(self, x, out, *args, **kwargs):
out["F"] = 1 - anp.exp(-x ** 2) * anp.sin(2 * anp.pi * x) ** 2


class MultiModalSimple2(Problem):
def __init__(self, n_var=1):
super().__init__(n_var=n_var, n_obj=1, n_constr=0, xl=-1, xu=0, type_var=anp.double)

def _evaluate(self, x, out, *args, **kwargs):
x = - x
out["F"] = 1.1 - anp.exp(-2 * x) * anp.sin(5 * anp.pi * x) ** 2
3 changes: 0 additions & 3 deletions pymoo/usage/algorithms/usage_ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@
termination=('n_gen', 50),
seed=1,
verbose=False)

print("Best solution found: \nX = %s\nF = %s" % (res.X, res.F))

4 changes: 2 additions & 2 deletions pymoo/usage/algorithms/usage_nsga2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter

problem = get_problem("zdt3")
problem = get_problem("zdt1")

algorithm = NSGA2(pop_size=100)

res = minimize(problem,
algorithm,
('n_gen', 200),
seed=84,
seed=1,
verbose=True)

plot = Scatter()
Expand Down
48 changes: 48 additions & 0 deletions pymoo/usage/visualization/usage_gif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import matplotlib.pyplot as plt

from pymoo.algorithms.nsga2 import NSGA2
from pymoo.optimize import minimize
from pymoo.problems.multi import ZDT1
from pymoo.util.nds.non_dominated_sorting import NonDominatedSorting
from pymoo.visualization.pcp import PCP
from pymoo.visualization.scatter import Scatter
from pyrecorder.recorders.gif import GIF
from pyrecorder.video import Video

problem = ZDT1(n_var=6)

algorithm = NSGA2()

ret = minimize(problem,
algorithm,
termination=('n_gen', 61),
seed=1,
save_history=True,
verbose=False)

print(ret.F)

with Video(GIF("animation.gif")) as vid:
for algorithm in ret.history:

if algorithm.n_gen % 5 == 0:
X, F = algorithm.pop.get("X", "F")
nds = NonDominatedSorting().do(F, only_non_dominated_front=True)
other = [k for k in range(len(F)) if k not in nds]

fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6))
fig.suptitle("%s - %s - Gen %s" % ("ZDT1", "NSGA2", algorithm.n_gen), fontsize=16)

pcp = PCP(ax=ax1, bounds=(problem.xl, problem.xu))
pcp.set_axis_style(color="black", alpha=0.7)
pcp.add(X[other], color="blue", linewidth=0.5)
pcp.add(X[nds], color="red", linewidth=2)
pcp.do()

sc = Scatter(ax=ax2)
sc.add(F[other], color="blue")
sc.add(F[nds], color="red")
sc.add(problem.pareto_front(), plot_type="line", color="black")
sc.do()

vid.record()
58 changes: 58 additions & 0 deletions pymoo/util/clearing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np


def func_select_by_objective(pop):
F = pop.get("F")
return F[:, 0].argmin()


def select_by_clearing(pop, D, n_select, func_select, eps=0.05):
clearing = EpsilonClearing(D, eps)

while len(clearing.selected()) < n_select:
remaining = clearing.remaining()

if len(remaining) == 0:
clearing.reset()

best = remaining[func_select(pop[remaining])]
clearing.select(best)

S = clearing.selected()
return S


class EpsilonClearing:

def __init__(self, D,
epsilon) -> None:
super().__init__()
self.D = D
self.n = len(D)
self.epsilon = epsilon

self.S = []
self.C = np.full(self.n, False)

def remaining(self):
return np.where(~self.C)[0]

def has_remaining(self):
return self.C.sum() != self.n

def cleared(self):
return self.C

def selected(self):
return self.S

def reset(self):
self.C = np.full(self.n, False)
self.C[self.S] = True

def select(self, k):
self.S.append(k)
self.C[k] = True

less_than_epsilon = self.D[k] < self.epsilon
self.C[less_than_epsilon] = True
10 changes: 9 additions & 1 deletion pymoo/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,23 @@ def cdist(A, B, **kwargs):
return scipy.spatial.distance.cdist(A, B, **kwargs)


def vectorized_cdist(A, B, func_dist=euclidean_distance, **kwargs):
def vectorized_cdist(A, B, func_dist=euclidean_distance, fill_diag_with_inf=False, **kwargs):
u = np.repeat(A, B.shape[0], axis=0)
v = np.tile(B, (A.shape[0], 1))

D = func_dist(u, v, **kwargs)
M = np.reshape(D, (A.shape[0], B.shape[0]))

if fill_diag_with_inf:
np.fill_diagonal(M, np.inf)

return M


def norm_eucl_dist(problem, A, B, **kwargs):
return vectorized_cdist(A, B, func_dist=norm_euclidean_distance(problem), **kwargs)


def covert_to_type(problem, X):
if problem.type_var == np.double:
return X.astype(np.double)
Expand Down
27 changes: 27 additions & 0 deletions pymoo/util/roulette.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np


class RouletteWheelSelection:

def __init__(self, val, larger_is_better=True):
super().__init__()
if not larger_is_better:
val = val.max() - val
_sum = val.sum()
self.cumulative = np.array([val[:k].sum() / _sum for k in range(1, len(val))])

def next(self, n=None):
if n is None:
X = np.random.random((1, 1))
else:
X = np.random.random((n, 1))
if n > 1:
X.repeat(n - 1, axis=1)

M = self.cumulative[None, :].repeat(len(X), axis=0)
B = X >= M
ret = B.sum(axis=1)

if n is None:
return ret[0]
return ret
Loading

0 comments on commit d8f05eb

Please sign in to comment.