Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization of katsuura function calculation #31

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Version 1.0.3

+ Optimized katsuura_func performance, at 1M ndim > 80x speedup

---------------------------------------------------------------------
# Version 1.0.2

+ Fix modified_schwefel_func() in operator.py
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
author = 'Thieu'

# The full version, including alpha/beta/rc tags
release = '1.0.2'
release = '1.0.3'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/pages/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Installation

Install the `current PyPI release <https://pypi.python.org/pypi/opfunu/>`_::

$ pip install opfunu==1.0.2
$ pip install opfunu==1.0.3


Or install the development version from GitHub::
Expand Down
2 changes: 1 addition & 1 deletion opfunu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# >>> opfunu.plot_2d(f22005, n_space=1000, ax=None)
# >>> opfunu.plot_3d(f22005, n_space=1000, ax=None)

__version__ = "1.0.2"
__version__ = "1.0.3"

import inspect
import re
Expand Down
4 changes: 4 additions & 0 deletions opfunu/cec_based/cec.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ def check_ndim_and_bounds(self, ndim=None, dim_max=None, bounds=None, default_bo
if self.dim_changeable:
if type(ndim) is int and ndim > 1:
if dim_max is None or ndim <= dim_max:
# Check if ndim in supported dimensions
if self.dim_supported is not None and ndim not in self.dim_supported:
raise ValueError(f'{self.__class__.__name__} ndim not in supported dimensions '
f'{self.dim_supported}')
self._ndim = int(ndim)
self._bounds = np.array([default_bounds[0] for _ in range(self._ndim)])
else:
Expand Down
4 changes: 3 additions & 1 deletion opfunu/utils/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ def katsuura_func(x):
x = np.array(x).ravel()
ndim = len(x)
result = 1.0
powers_of_two = 2 ** np.arange(1, 34)
reciprocals_of_two = 1 / powers_of_two
for idx in range(0, ndim):
temp = np.sum([np.abs(2 ** j * x[idx] - np.round(2 ** j * x[idx])) / 2 ** j for j in range(1, 33)])
temp = np.sum(np.abs(powers_of_two * x[idx] - np.round(powers_of_two * x[idx])) * reciprocals_of_two)
result *= (1 + (idx + 1) * temp) ** (10.0 / ndim ** 1.2)
return (result - 1) * 10 / ndim ** 2

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def readme():

setup(
name="opfunu",
version="1.0.2",
version="1.0.3",
author="Thieu",
author_email="nguyenthieu2102@gmail.com",
description="Opfunu: An Open-source Python Library for Optimization Benchmark Functions",
Expand Down