Skip to content

Commit 958bc7c

Browse files
author
Julian Blank
committed
Working on usage test fix
1 parent 88ef75c commit 958bc7c

File tree

21 files changed

+111
-379
lines changed

21 files changed

+111
-379
lines changed

doc/source/operators/repair.ipynb

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"cell_type": "code",
40-
"execution_count": 1,
40+
"execution_count": 4,
4141
"metadata": {},
4242
"outputs": [
4343
{
@@ -61,18 +61,22 @@
6161
}
6262
],
6363
"source": [
64-
"from pymoo.factory import get_algorithm, get_crossover, get_mutation, get_sampling\n",
64+
"from pymoo.factory import get_crossover, get_mutation, get_sampling\n",
6565
"from pymoo.optimize import minimize\n",
66+
"from pymoo.algorithms.so_genetic_algorithm import GA\n",
67+
"\n",
68+
"\n",
6669
"from pymoo.problems.single.knapsack import create_random_knapsack_problem\n",
6770
"\n",
6871
"problem = create_random_knapsack_problem(30)\n",
6972
"\n",
70-
"algorithm = get_algorithm(\"ga\",\n",
71-
" pop_size=200,\n",
72-
" sampling=get_sampling(\"bin_random\"),\n",
73-
" crossover=get_crossover(\"bin_hux\"),\n",
74-
" mutation=get_mutation(\"bin_bitflip\"),\n",
75-
" eliminate_duplicates=True)\n",
73+
"\n",
74+
"algorithm = GA(pop_size=200,\n",
75+
" sampling=get_sampling(\"bin_random\"),\n",
76+
" crossover=get_crossover(\"bin_hux\"),\n",
77+
" mutation=get_mutation(\"bin_bitflip\"),\n",
78+
" eliminate_duplicates=True)\n",
79+
"\n",
7680
"\n",
7781
"res = minimize(problem,\n",
7882
" algorithm,\n",
@@ -137,7 +141,7 @@
137141
},
138142
{
139143
"cell_type": "code",
140-
"execution_count": 3,
144+
"execution_count": 5,
141145
"metadata": {},
142146
"outputs": [
143147
{
@@ -147,33 +151,28 @@
147151
"===========================================================================\n",
148152
"n_gen | n_eval | cv (min) | cv (avg) | fopt | favg \n",
149153
"===========================================================================\n",
150-
" 1 | 200 | 1.28000E+02 | 5.00570E+02 | - | -\n"
151-
]
152-
},
153-
{
154-
"name": "stdout",
155-
"output_type": "stream",
156-
"text": [
157-
" 2 | 400 | 9.80000E+01 | 3.56070E+02 | - | -\n",
158-
" 3 | 600 | 0.00000E+00 | 2.59780E+02 | -291 | -2.91000E+02\n",
159-
" 4 | 800 | 0.00000E+00 | 1.82020E+02 | -425 | -3.36400E+02\n",
160-
" 5 | 1000 | 0.00000E+00 | 1.19465E+02 | -454 | -3.35556E+02\n",
161-
" 6 | 1200 | 0.00000E+00 | 6.68000E+01 | -454 | -2.95400E+02\n",
162-
" 7 | 1400 | 0.00000E+00 | 2.88800E+01 | -454 | -2.90133E+02\n",
163-
" 8 | 1600 | 0.00000E+00 | 4.270000000 | -522 | -2.80194E+02\n",
164-
" 9 | 1800 | 0.00000E+00 | 0.00000E+00 | -553 | -3.10615E+02\n"
165-
]
166-
},
167-
{
168-
"name": "stdout",
169-
"output_type": "stream",
170-
"text": [
171-
" 10 | 2000 | 0.00000E+00 | 0.00000E+00 | -553 | -3.59055E+02\n"
154+
" 1 | 171 | 0.00000E+00 | 0.00000E+00 | -437 | -1.47743E+02\n",
155+
" 2 | 371 | 0.00000E+00 | 0.00000E+00 | -437 | -2.21790E+02\n",
156+
" 3 | 571 | 0.00000E+00 | 0.00000E+00 | -474 | -2.66900E+02\n",
157+
" 4 | 771 | 0.00000E+00 | 0.00000E+00 | -524 | -3.20120E+02\n",
158+
" 5 | 971 | 0.00000E+00 | 0.00000E+00 | -544 | -3.71800E+02\n",
159+
" 6 | 1171 | 0.00000E+00 | 0.00000E+00 | -640 | -4.14070E+02\n",
160+
" 7 | 1371 | 0.00000E+00 | 0.00000E+00 | -640 | -4.54460E+02\n",
161+
" 8 | 1571 | 0.00000E+00 | 0.00000E+00 | -657 | -4.84725E+02\n",
162+
" 9 | 1771 | 0.00000E+00 | 0.00000E+00 | -657 | -5.16825E+02\n",
163+
" 10 | 1971 | 0.00000E+00 | 0.00000E+00 | -657 | -5.34625E+02\n"
172164
]
173165
}
174166
],
175167
"source": [
176-
"algorithm.repair = ConsiderMaximumWeightRepair()\n",
168+
"algorithm = GA(pop_size=200,\n",
169+
" sampling=get_sampling(\"bin_random\"),\n",
170+
" crossover=get_crossover(\"bin_hux\"),\n",
171+
" mutation=get_mutation(\"bin_bitflip\"),\n",
172+
" repair=ConsiderMaximumWeightRepair(),\n",
173+
" eliminate_duplicates=True)\n",
174+
"\n",
175+
"\n",
177176
"\n",
178177
"res = minimize(problem,\n",
179178
" algorithm,\n",
@@ -205,7 +204,7 @@
205204
"name": "python",
206205
"nbconvert_exporter": "python",
207206
"pygments_lexer": "ipython3",
208-
"version": "3.7.4"
207+
"version": "3.7.3"
209208
}
210209
},
211210
"nbformat": 4,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22

3-
from pymoo.algorithms.so_gradient_descent import GradientBasedAlgorithm
3+
from pymoo.algorithms.convex.base import GradientBasedAlgorithm
44

55

66
class Adam(GradientBasedAlgorithm):

pymoo/algorithms/deriv/gradient_descent.py renamed to pymoo/algorithms/convex/base.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,3 @@ def _next(self):
7979

8080
# set the gradient to none to be ready for the next iteration
8181
self.dX = None
82-
83-
84-
class GradientDescent(GradientBasedAlgorithm):
85-
86-
def __init__(self, X, learning_rate=0.005, **kwargs) -> None:
87-
super().__init__(X, **kwargs)
88-
self.learning_rate = learning_rate
89-
90-
def restart(self):
91-
self.learning_rate /= 2
92-
93-
def apply(self):
94-
self.X = self.X - self.learning_rate * self.dX
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pymoo.algorithms.convex.base import GradientBasedAlgorithm
2+
3+
4+
class GradientDescent(GradientBasedAlgorithm):
5+
6+
def __init__(self, X, learning_rate=0.005, **kwargs) -> None:
7+
super().__init__(X, **kwargs)
8+
self.learning_rate = learning_rate
9+
10+
def restart(self):
11+
self.learning_rate /= 2
12+
13+
def apply(self):
14+
self.X = self.X - self.learning_rate * self.dX

pymoo/algorithms/ctaea.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pymoo.algorithms.genetic_algorithm import GeneticAlgorithm
77
from pymoo.docs import parse_doc_string
88
from pymoo.factory import get_decomposition
9-
from pymoo.model.individual import Individual
109
from pymoo.model.population import Population
1110
from pymoo.operators.crossover.simulated_binary_crossover import SimulatedBinaryCrossover
1211
from pymoo.operators.mutation.polynomial_mutation import PolynomialMutation

pymoo/algorithms/deriv/base.py

Whitespace-only changes.

pymoo/algorithms/mocs.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

pymoo/algorithms/rvea.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def setup(self, problem, **kwargs):
8888
if not isinstance(self.termination, MaximumGenerationTermination):
8989
raise Exception("Please use the n_gen or n_eval as a termination criterion to execute RVEA!")
9090

91+
return self
92+
9193
def _next(self):
9294
super()._next()
9395

0 commit comments

Comments
 (0)