Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thieu1995 committed May 24, 2024
1 parent 987f59d commit f89d926
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ traditional functions with different dimensions are implemented.

pages/quick_start.rst
pages/integrated.rst
pages/visualization.rst
pages/categories.rst


Expand Down
9 changes: 9 additions & 0 deletions docs/source/pages/support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ If you are using opfunu in your project, we would appreciate citations:

::

@article{Van_Thieu_2024_Opfunu,
author = {Van Thieu, Nguyen},
title = {Opfunu: An Open-source Python Library for Optimization Benchmark Functions},
doi = {10.5334/jors.508},
journal = {Journal of Open Research Software},
month = {May},
year = {2024}
}

@software{thieu_nguyen_2020_3711682,
author = {Nguyen Van Thieu},
title = {Opfunu: An Open-source Python Library for Optimization Benchmark Functions},
Expand Down
71 changes: 71 additions & 0 deletions docs/source/pages/visualization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Visualization
=============

Inside Function
---------------

You can use our visualization module to draw our function.

Code::

from opfunu.cec_based import F12010

# Visualize opfunu function using method in object
f0 = F12010()

f0.plot_2d(selected_dims=(2, 3), n_points=300, ct_cmap="viridis", ct_levels=30, ct_alpha=0.7,
fixed_strategy="mean", fixed_values=None, title="Contour map of the F1 CEC 2010 function",
x_label=None, y_label=None, figsize=(10, 8), filename="2d-f12010", exts=(".png", ".pdf"), verbose=True)

f0.plot_3d(selected_dims=(1, 6), n_points=500, ct_cmap="viridis", ct_levels=30, ct_alpha=0.7,
fixed_strategy="mean", fixed_values=None, title="3D visualization of the F1 CEC 2010 function",
x_label=None, y_label=None, figsize=(10, 8), filename="3d-f12010", exts=(".png", ".pdf"), verbose=True)

## Visualize opfunu function using utility function
from opfunu import draw_2d, draw_3d

draw_2d(f0.evaluate, f0.lb, f0.ub, selected_dims=(2, 3), n_points=300)
draw_3d(f0.evaluate, f0.lb, f0.ub, selected_dims=(2, 3), n_points=300)


Custom Function
---------------

You can also use our visualization module to draw your custom function.

Code::

from opfunu import draw_2d, draw_3d

## Define a custom function, for example. I will use mealpy problem as an example
from mealpy import Problem, FloatVar
import numpy as np

# Our custom problem class
class Squared(Problem):
def __init__(self, bounds=None, minmax="min", data=None, **kwargs):
self.data = data
super().__init__(bounds, minmax, **kwargs)

def obj_func(self, solution):
x = self.decode_solution(solution)["my_var"]
return np.sum(x ** 2)

bound = FloatVar(lb=(-10., )*20, ub=(10., )*20, name="my_var")
custom_squared = Squared(bounds=bound, minmax="min", data="Amazing", name="Squared")

## Visualize function using utility function
draw_2d(custom_squared.obj_func, custom_squared.lb, custom_squared.ub, selected_dims=(2, 3), n_points=300)
draw_3d(custom_squared.obj_func, custom_squared.lb, custom_squared.ub, selected_dims=(2, 3), n_points=300)


.. toctree::
:maxdepth: 4


.. toctree::
:maxdepth: 4


.. toctree::
:maxdepth: 4

0 comments on commit f89d926

Please sign in to comment.