Skip to content

Commit 47336cb

Browse files
committed
refactor: rename Rosenbrock2DFunction to RosenbrockFunction and update related documentation
feat: Add Himmelblau function image and update special functions documentation
1 parent 313078e commit 47336cb

File tree

4 files changed

+35
-80
lines changed

4 files changed

+35
-80
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ import numpy as np
7474
x = np.linspace(-2, 2, 100)
7575
y = np.linspace(-1, 3, 100)
7676
X, Y = np.meshgrid(x, y)
77-
Z = Rosenbrock2DFunction(X, Y).__eval__
77+
Z = RosenbrockFunction(X, Y).__eval__
7878

7979
import matplotlib.pyplot as plt
8080
fig = plt.figure()
8181
ax = fig.add_subplot(111, projection="3d")
8282
ax.plot_surface(X, Y, Z, cmap="viridis")
83-
plt.savefig("Rosenbrock2DFunction.png", dpi=300, transparent=True)
83+
plt.savefig("RosenbrockFunction.png", dpi=300, transparent=True)
8484
```
8585

8686
## Documentation
446 KB
Loading

docs/modules/functions/optimization/special.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
heading_level: 0
2929
members: None
3030

31-
| |
32-
| :---------------------------------------------------------: |
33-
| ![BraninFunction](../../../extra/images/BraninFunction.png) |
31+
| |
32+
| :-------------------------------------------------------------------------: |
33+
| ![StyblinskiTangFunction](../../../extra/images/StyblinskiTangFunction.png) |
3434

35-
## Styblinski-Tang Function
35+
## Goldstein-Price Function
3636

3737
<!-- prettier-ignore -->
38-
::: umf.functions.optimization.special.StyblinskiTangFunction
38+
::: umf.functions.optimization.special.GoldsteinPriceFunction
3939
options:
4040
show_bases: false
4141
show_source: true
@@ -47,12 +47,12 @@
4747

4848
| |
4949
| :-------------------------------------------------------------------------: |
50-
| ![StyblinskiTangFunction](../../../extra/images/StyblinskiTangFunction.png) |
50+
| ![GoldsteinPriceFunction](../../../extra/images/GoldsteinPriceFunction.png) |
5151

52-
## Goldstein-Price Function
52+
## Goldstein-Price Log Function
5353

5454
<!-- prettier-ignore -->
55-
::: umf.functions.optimization.special.GoldsteinPriceFunction
55+
::: umf.functions.optimization.special.GoldsteinPriceLogFunction
5656
options:
5757
show_bases: false
5858
show_source: true
@@ -62,14 +62,18 @@
6262
heading_level: 0
6363
members: None
6464

65-
| |
66-
| :-------------------------------------------------------------------------: |
67-
| ![GoldsteinPriceFunction](../../../extra/images/GoldsteinPriceFunction.png) |
65+
| |
66+
| :-------------------------------------------------------------------------------: |
67+
| ![GoldsteinPriceLogFunction](../../../extra/images/GoldsteinPriceLogFunction.png) |
6868

69-
## Goldstein-Price Log Function
69+
| |
70+
| :---------------------------------------------------------: |
71+
| ![BraninFunction](../../../extra/images/BraninFunction.png) |
72+
73+
## Himmelblau Function
7074

7175
<!-- prettier-ignore -->
72-
::: umf.functions.optimization.special.GoldsteinPriceLogFunction
76+
::: umf.functions.optimization.special.HimmelblauFunction
7377
options:
7478
show_bases: false
7579
show_source: true
@@ -79,6 +83,19 @@
7983
heading_level: 0
8084
members: None
8185

82-
| |
83-
| :-------------------------------------------------------------------------------: |
84-
| ![GoldsteinPriceLogFunction](../../../extra/images/GoldsteinPriceLogFunction.png) |
86+
| |
87+
| :-------------------------------------------------------------: |
88+
| ![HimmelblauFunction](../../../extra/images/HimmelblauFunction.png) |
89+
90+
## Styblinski-Tang Function
91+
92+
<!-- prettier-ignore -->
93+
::: umf.functions.optimization.special.StyblinskiTangFunction
94+
options:
95+
show_bases: false
96+
show_source: true
97+
show_inherited_members: false
98+
allow_inspection: false
99+
inheritance_graph: false
100+
heading_level: 0
101+
members: None

umf/functions/optimization/valley_shaped.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
__all__: list[str] = [
2121
"DixonPriceFunction",
22-
"Rosenbrock2DFunction",
2322
"RosenbrockFunction",
2423
"SixHumpCamelFunction",
2524
"ThreeHumpCamelFunction",
@@ -281,64 +280,3 @@ def __minima__(self) -> MinimaAPI:
281280
f_x=0.0,
282281
x=tuple(np.array([1.0 for _ in range(len(self._x))])),
283282
)
284-
285-
286-
class Rosenbrock2DFunction(OptFunction):
287-
r"""2D Rosenbrock function.
288-
289-
The 2D Rosenbrock function is a two-dimensional function with a single
290-
global minimum.
291-
292-
Examples:
293-
>>> import matplotlib.pyplot as plt
294-
>>> import numpy as np
295-
>>> from umf.functions.optimization.valley_shaped import Rosenbrock2DFunction
296-
>>> x = np.linspace(-2, 2, 100)
297-
>>> y = np.linspace(-1, 3, 100)
298-
>>> X, Y = np.meshgrid(x, y)
299-
>>> Z = Rosenbrock2DFunction(X, Y).__eval__
300-
>>> fig = plt.figure()
301-
>>> ax = fig.add_subplot(111, projection="3d")
302-
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
303-
>>> plt.savefig("Rosenbrock2DFunction.png", dpi=300, transparent=True)
304-
305-
Notes:
306-
The 2D Rosenbrock function is defined as:
307-
308-
$$
309-
f(x) = 100(x_2 - x_1^2)^2 + (1 - x_1)^2
310-
$$
311-
312-
> Reference: Original implementation can be found
313-
> [here](https://www.sfu.ca/~ssurjano/rosen.html).
314-
315-
Args:
316-
*x (UniversalArray): Input data, which has to be two-dimensional.
317-
318-
Raises:
319-
OutOfDimensionError: If the dimension of the input data is not 2.
320-
"""
321-
322-
def __init__(self, *x: UniversalArray) -> None:
323-
"""Initialize the 2D Rosenbrock function."""
324-
if len(x) != __2d__:
325-
raise OutOfDimensionError(
326-
function_name="Rosenbrock2D",
327-
dimension=__2d__,
328-
)
329-
super().__init__(*x)
330-
331-
@property
332-
def __eval__(self) -> UniversalArray:
333-
"""Evaluate 2D Rosenbrock function at x."""
334-
x_1 = self._x[0]
335-
x_2 = self._x[1]
336-
return 100 * (x_2 - x_1**2) ** 2 + (1 - x_1) ** 2
337-
338-
@property
339-
def __minima__(self) -> MinimaAPI:
340-
"""Return the zero function."""
341-
return MinimaAPI(
342-
f_x=0.0,
343-
x=(1.0, 1.0),
344-
)

0 commit comments

Comments
 (0)