Skip to content

Commit

Permalink
Working on usage test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Blank committed Dec 7, 2020
1 parent 88ef75c commit 958bc7c
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 379 deletions.
65 changes: 32 additions & 33 deletions doc/source/operators/repair.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -61,18 +61,22 @@
}
],
"source": [
"from pymoo.factory import get_algorithm, get_crossover, get_mutation, get_sampling\n",
"from pymoo.factory import get_crossover, get_mutation, get_sampling\n",
"from pymoo.optimize import minimize\n",
"from pymoo.algorithms.so_genetic_algorithm import GA\n",
"\n",
"\n",
"from pymoo.problems.single.knapsack import create_random_knapsack_problem\n",
"\n",
"problem = create_random_knapsack_problem(30)\n",
"\n",
"algorithm = get_algorithm(\"ga\",\n",
" pop_size=200,\n",
" sampling=get_sampling(\"bin_random\"),\n",
" crossover=get_crossover(\"bin_hux\"),\n",
" mutation=get_mutation(\"bin_bitflip\"),\n",
" eliminate_duplicates=True)\n",
"\n",
"algorithm = GA(pop_size=200,\n",
" sampling=get_sampling(\"bin_random\"),\n",
" crossover=get_crossover(\"bin_hux\"),\n",
" mutation=get_mutation(\"bin_bitflip\"),\n",
" eliminate_duplicates=True)\n",
"\n",
"\n",
"res = minimize(problem,\n",
" algorithm,\n",
Expand Down Expand Up @@ -137,7 +141,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -147,33 +151,28 @@
"===========================================================================\n",
"n_gen | n_eval | cv (min) | cv (avg) | fopt | favg \n",
"===========================================================================\n",
" 1 | 200 | 1.28000E+02 | 5.00570E+02 | - | -\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 2 | 400 | 9.80000E+01 | 3.56070E+02 | - | -\n",
" 3 | 600 | 0.00000E+00 | 2.59780E+02 | -291 | -2.91000E+02\n",
" 4 | 800 | 0.00000E+00 | 1.82020E+02 | -425 | -3.36400E+02\n",
" 5 | 1000 | 0.00000E+00 | 1.19465E+02 | -454 | -3.35556E+02\n",
" 6 | 1200 | 0.00000E+00 | 6.68000E+01 | -454 | -2.95400E+02\n",
" 7 | 1400 | 0.00000E+00 | 2.88800E+01 | -454 | -2.90133E+02\n",
" 8 | 1600 | 0.00000E+00 | 4.270000000 | -522 | -2.80194E+02\n",
" 9 | 1800 | 0.00000E+00 | 0.00000E+00 | -553 | -3.10615E+02\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 10 | 2000 | 0.00000E+00 | 0.00000E+00 | -553 | -3.59055E+02\n"
" 1 | 171 | 0.00000E+00 | 0.00000E+00 | -437 | -1.47743E+02\n",
" 2 | 371 | 0.00000E+00 | 0.00000E+00 | -437 | -2.21790E+02\n",
" 3 | 571 | 0.00000E+00 | 0.00000E+00 | -474 | -2.66900E+02\n",
" 4 | 771 | 0.00000E+00 | 0.00000E+00 | -524 | -3.20120E+02\n",
" 5 | 971 | 0.00000E+00 | 0.00000E+00 | -544 | -3.71800E+02\n",
" 6 | 1171 | 0.00000E+00 | 0.00000E+00 | -640 | -4.14070E+02\n",
" 7 | 1371 | 0.00000E+00 | 0.00000E+00 | -640 | -4.54460E+02\n",
" 8 | 1571 | 0.00000E+00 | 0.00000E+00 | -657 | -4.84725E+02\n",
" 9 | 1771 | 0.00000E+00 | 0.00000E+00 | -657 | -5.16825E+02\n",
" 10 | 1971 | 0.00000E+00 | 0.00000E+00 | -657 | -5.34625E+02\n"
]
}
],
"source": [
"algorithm.repair = ConsiderMaximumWeightRepair()\n",
"algorithm = GA(pop_size=200,\n",
" sampling=get_sampling(\"bin_random\"),\n",
" crossover=get_crossover(\"bin_hux\"),\n",
" mutation=get_mutation(\"bin_bitflip\"),\n",
" repair=ConsiderMaximumWeightRepair(),\n",
" eliminate_duplicates=True)\n",
"\n",
"\n",
"\n",
"res = minimize(problem,\n",
" algorithm,\n",
Expand Down Expand Up @@ -205,7 +204,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from pymoo.algorithms.so_gradient_descent import GradientBasedAlgorithm
from pymoo.algorithms.convex.base import GradientBasedAlgorithm


class Adam(GradientBasedAlgorithm):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,3 @@ def _next(self):

# set the gradient to none to be ready for the next iteration
self.dX = None


class GradientDescent(GradientBasedAlgorithm):

def __init__(self, X, learning_rate=0.005, **kwargs) -> None:
super().__init__(X, **kwargs)
self.learning_rate = learning_rate

def restart(self):
self.learning_rate /= 2

def apply(self):
self.X = self.X - self.learning_rate * self.dX
14 changes: 14 additions & 0 deletions pymoo/algorithms/convex/gradient_descent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pymoo.algorithms.convex.base import GradientBasedAlgorithm


class GradientDescent(GradientBasedAlgorithm):

def __init__(self, X, learning_rate=0.005, **kwargs) -> None:
super().__init__(X, **kwargs)
self.learning_rate = learning_rate

def restart(self):
self.learning_rate /= 2

def apply(self):
self.X = self.X - self.learning_rate * self.dX
1 change: 0 additions & 1 deletion pymoo/algorithms/ctaea.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pymoo.algorithms.genetic_algorithm import GeneticAlgorithm
from pymoo.docs import parse_doc_string
from pymoo.factory import get_decomposition
from pymoo.model.individual import Individual
from pymoo.model.population import Population
from pymoo.operators.crossover.simulated_binary_crossover import SimulatedBinaryCrossover
from pymoo.operators.mutation.polynomial_mutation import PolynomialMutation
Expand Down
Empty file removed pymoo/algorithms/deriv/base.py
Empty file.
95 changes: 0 additions & 95 deletions pymoo/algorithms/mocs.py

This file was deleted.

2 changes: 2 additions & 0 deletions pymoo/algorithms/rvea.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def setup(self, problem, **kwargs):
if not isinstance(self.termination, MaximumGenerationTermination):
raise Exception("Please use the n_gen or n_eval as a termination criterion to execute RVEA!")

return self

def _next(self):
super()._next()

Expand Down
Loading

0 comments on commit 958bc7c

Please sign in to comment.