Giter Site home page Giter Site logo

thieu1995 / opfunu Goto Github PK

View Code? Open in Web Editor NEW
102.0 3.0 37.0 20.34 MB

A collection of Benchmark functions for numerical optimization problems

Home Page: https://opfunu.readthedocs.io

License: GNU General Public License v3.0

Python 100.00%
benchmark-functions soft-computing global-optimization convex-optimization non-convex-optimization unimodal-functions multimodal-functions cec-2014 cec-2017 cec-2019

opfunu's Introduction

Hi πŸ‘‹, I'm Thieu

dev.to badge Gmail Badge githubbadge githubbadge

My interested fields including Artificial Intelligence || Machine Learning || Deep Learning || Optimization || Metaheuristics || Nature-inspired Computing || Fullstack Web Technologies || Nature Language Processing || Transfer Learning|| ...

  • πŸ‘¨β€πŸ’» All of my projects are available πŸ‘‰ here
  • ✏️ Google Scholar profile: here
  • βš’οΈ My AIIR team: coding store and web
  • πŸ“« Looking for collaboration, contact me [email protected]

I'm also an active open-source developer. Check out some of my open-source projects:

Library Downloads
Mealpy Downloads
Opfunu Downloads
PerMetrics Downloads
pfevaluator Downloads
mafese Downloads
MetaCluster Downloads
IntelELM Downloads
MetaPerceptron Downloads
deforce Downloads
ENOPPY Downloads
reflame Downloads
GrafoRVFL Downloads
EvoRBF N/A
BIO-ANFIS N/A

πŸ”§ Favorite Languages and Tools

OS Preferences: linux linux

Programming:

β€’ Language: java php javascript C C++

β€’ AI Frameworks: scikit_learn tensorflow keras

β€’ Web Development:

html5 css3 materialize sass boostrap angularjs expressjs flask hexo hugo jekyll nodejs spring

β€’ App Development: java-android ionic

β€’ Storage: git firebase heroku

β€’ Database: sqlite mysql mongodb mongodb


⚑ Github Stats

Github stats Top Langs

πŸ† Github Awards

thieu1995

opfunu's People

Contributors

dependabot[bot] avatar firestrand avatar mcrimi avatar skylull avatar thieu1995 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

opfunu's Issues

[BUG]: Different results in CEC2015 series of benchmark functions compared with the original Matlab implementation!

Description of the bug

Hi, I was benchmarking results on CEC2015 problems. The implementation of the methods I selected is via Matlab and python. For python codes, I followed your implementation of CEC2015. For Matlab codes, I followed the zip file provided by the competition authors (https://github.com/P-N-Suganthan/CEC2015), and when I compared optimization results of the selected methods, I found that on some CEC2015 problems, these two implementations returned different results.
I am looking forward to the bug fixation!

Steps To Reproduce

Here are the ones with problems: F4, F6, F7, F11, F12, F13, F14, and F15. Among them, some result in minor differences, like 1~2. Even so, it does influence the comparison. Others (e.g., F12) result in a huge gap in the order of magnitudes.
Currently, I have not found the right way to fix this, but I do find mistakes in CEC2015 problems, such as on F12, the leveraged input file is mistaken from the ones of F10.

Additional Information

No response

[BUG]: Wrong `self._bounds` index used for setting `self._ndim`

Problem

When presented a funciton where ndim cannot be 2 (if dim_changeable=False and default_dim != 2) and ndim=None is given upon initialization, this function makes it so the dimension is set to 2, because the wrong index is given when setting self._ndim = self._bounds.shape[1].

self._ndim = self._bounds.shape[1]

Possible solution

This should be the first index (self._bounds.shape[0]). This is correctly implemented in the cec_based submodule

[BUG]: opfunu install in mac

Description of the bug

hi i cant install opfunu . i installed before but now in visual studio i cant use it does any one have a solution?

Steps To Reproduce

i install step by step to read me file

Additional Information

No response

[BUG]: python 3.12 import failed

Description of the bug

python 3.12 import opfunu
from . import cec_based
from .cec2005 import *
from opfunu.cec_based.cec import CecBenchmark
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
how to fix it ?

Steps To Reproduce

python3.12
import opfunu
error!

Additional Information

No response

New feature: database API

I really like this repository and used it in my Computational Intelligence course back in university. However, I wish that it also included a database for each benchmark method.

This would be really useful if someone would like to use and compare benchmark methods, but want to know how to draw meaningful conclusions from their tests. For instance, knowing what tags a benchmark method has (e.g. continuous vs discontinuous, non-convex vs convex etc) and knowing the dimension of the benchmark on hand would speed up the process of say concluding whether an algorithm performs better in lower dimensions, on convex landscapes etc.

Would you be interested if I attempted to add such a thing? This can either be by csv or by physically adding a list of dictionaries.
Here is a preview of what I suggest:

api.py:

# this snippet only includes benchmarks from the multi_modal file for now
from opfunu.type_based import multi_modal

""" Links are retrieved from the following name spaces: 
    (ordered from most useful links to lease useful)
- https://www.sfu.ca/~ssurjano/optimization.html
- http://infinity77.net/global_optimization/test_functions.html
- https://github.com/mazhar-ansari-ardeh/BenchmarkFcns/blob/gh-pages/benchmarkfcns/
- http://benchmarkfcns.xyz
- https://www.indusmic.com/post/


A Literature Survey of Benchmark Functions For Global Optimization Problems (2013):
    https://arxiv.org/pdf/1308.4008.pdf
"""


data = [
    # Ackley
    dict(
        dimensions='d',
        domain=[-32.768, 32.768],
        latex=r"f(\textbf{x}) = f(x_1, ..., x_n)= -a.exp(-b\sqrt{\frac{1}{n}\sum_{i=1}^{n}x_i^2})-exp(\frac{1}{d}\sum_{i=1}^{n}cos(cx_i))+ a + exp(1)",
        links=[
            'http://benchmarkfcns.xyz/benchmarkfcns/ackleyfcn.html',
            'https://github.com/mazhar-ansari-ardeh/BenchmarkFcns/blob/gh-pages/benchmarkfcns/ackleyfcn.markdown',
            'https://www.sfu.ca/~ssurjano/ackley.html',
        ],
        method=multi_modal.Functions()._ackley__,
        minima=[dict(fx=0, x=0)],
        name='Ackley',
        references=[
            '''Adorio, E. P., & Diliman, U. P. MVF - Multivariate Test Functions Library in C for Unconstrained Global Optimization (2005). Retrieved June 2013, from http://http://www.geocities.ws/eadorio/mvf.pdf.''',
            '''Molga, M., & Smutnicki, C. Test functions for optimization needs (2005). Retrieved June 2013, from http://www.zsd.ict.pwr.wroc.pl/files/docs/functions.pdf.''',
            '''Back, T. (1996). Evolutionary algorithms in theory and practice: evolution strategies, evolutionary programming, genetic algorithms. Oxford University Press on Demand.''',
        ],
        tags=[
            'continuous',
            'non-convex',
            'differentiable',
        ],
    ),
    # Ackley N. 4
    dict(
        dimensions='d',
        domain=[-35, 35],
        latex=r"f(\textbf{x})=\sum_{i=1}^{n-1}\left( e^{-0.2}\sqrt{x_i^2+x_{i+1}^2} + 3\left( cos(2x_i) + sin(2x_{i+1}) \right) \right)",
        links=[
            'http://benchmarkfcns.xyz/benchmarkfcns/ackleyn4fcn.html',
            'https://github.com/mazhar-ansari-ardeh/BenchmarkFcns/blob/gh-pages/benchmarkfcns/ackleyn4fcn.markdown',
        ],
        method=multi_modal.Functions()._ackley_4__,
        minima=[dict(fx=-4.590101633799122, x=[-1.51, -0.755])],
        name='Ackley N. 4',
        references=[
            '''Momin Jamil and Xin-She Yang, A literature survey of benchmark functions for global optimization problems, Int. Journal of Mathematical Modelling and Numerical Optimisation}, Vol. 4, No. 2, pp. 150--194 (2013), arXiv:1308.4008''',
        ],
        tags=[
            'continuous',
            'differentiable',
            'non-separable',
            'scalable',
        ],
    ),
    # Alpine 1
    dict(
        dimensions='d',
        domain=[-10, 10],
        latex=r"f(\mathbf x)=f(x_1, ..., x_n)=\sum_{i=1}^{n}|x_i sin(x_i) + 0.1x_i|",
        links=[
            'http://benchmarkfcns.xyz/benchmarkfcns/alpinen1fcn.html'
            'https://github.com/mazhar-ansari-ardeh/BenchmarkFcns/blob/gh-pages/benchmarkfcns/alpinen1fcn.markdown',
            'http://infinity77.net/global_optimization/test_functions_nd_A.html#go_benchmark.Alpine01',
        ],
        method=multi_modal.Functions()._alpine_1__,
        minima=[dict(fx=0, x=0)],
        name='Alpine 1',
        references=[
            '''Momin Jamil and Xin-She Yang, A literature survey of benchmark functions for global optimization problems, Int. Journal of Mathematical Modelling and Numerical Optimisation}, Vol. 4, No. 2, pp. 150--194 (2013), arXiv:1308.4008''',
            '''M. Clerc, β€œThe Swarm and the Queen, Towards a Deterministic and Adaptive Particle Swarm Optimization, ” IEEE Congress on Evolutionary Computation, Washington DC, USA, pp. 1951-1957, 1999.''',
        ],
        tags=[
            'continuous',
            'non-differentiable',
            'separable',
            'non-scalable',
        ],
    ),
    # Alpine 2
    dict(
        dimensions='d',
        domain=[0, 10],
        latex=r"f(\mathbf x)=f(x_1, ..., x_n) = \prod_{i=1}^{n}\sqrt{x_i}sin(x_i)",
        links=[
            'http://infinity77.net/global_optimization/test_functions_nd_A.html#go_benchmark.Alpine02',
            'https://github.com/mazhar-ansari-ardeh/BenchmarkFcns/blob/gh-pages/benchmarkfcns/alpinen2fcn.markdown',

        ],
        method=multi_modal.Functions()._alpine_2__,
        minima=[dict(fx=-6.1295, x=7.917)],
        name='Alpine 2',
        references=[
            '''Momin Jamil and Xin-She Yang, A literature survey of benchmark functions for global optimization problems, Int. Journal of Mathematical Modelling and Numerical Optimisation}, Vol. 4, No. 2, pp. 150--194 (2013), arXiv:1308.4008''',
            '''M. Clerc, β€œThe Swarm and the Queen, Towards a Deterministic and Adaptive Particle Swarm Optimization, ” IEEE Congress on Evolutionary Computation, Washington DC, USA, pp. 1951-1957, 1999.''',
        ],
        tags=[
            'multi-modal'
            'differentiable',
            'non-convex',
            'non-separable',
        ],
    ),
    # Cosine Mixture
    dict(
        dimensions='d',
        domain=[-1, 1],
        latex=r"f(\mathbf{x})=-0.1\sum_{i=1}^n\cos(5\pix_i)-\sum_{i=1}^{n}x_i^2",
        links=[
            'http://infinity77.net/global_optimization/test_functions_nd_C.html#go_benchmark.CosineMixture',
        ],
        method=multi_modal.Functions()._cosine_mixture__,
        minima=[dict(fx=lambda x: 0.1*len(x), x=0)],
        name='Cosine Mixture',
        references=[
            'A Literature Survey of Benchmark Functions For Global Optimization Problems (2013)'
        ],
        tags=[
            'discontinuous',
            'non-differentiable',
            'separable',
            'scalable',
            'multi-modal',
        ],
    ),
    # Csendes
    dict(
        dimensions=2,
        domain=[-1, 1],
        latex=r"f(\mathbf{x})=\sum_{i=1}^n x_i^6\left[2+\sin\left(\frac{1}{x_i}\right)\right]",
        links=[
            'http://infinity77.net/global_optimization/test_functions_nd_C.html#go_benchmark.Csendes',
        ],
        method=multi_modal.Functions()._csendes__,
        minima=[dict(fx=0, x=0)],
        name='Csendes',
        references=[
            'A Literature Survey of Benchmark Functions For Global Optimization Problems (2013)'
        ],
        tags=[
            'continuous',
            'differentiable',
            'separable',
            'scalable',
            'multi-modal',
        ],
    ),


    # TODO: add the methods in benchmark2d.py
    # TODO: add the methods in benchmark3d.py
    # TODO: add the methods in benchmarknd.py
    # TODO: add the methods in multi_modal.py
    # TODO: add the methods in uni_modal.py

whereafter one would use the data list of dictionaries to build a dataframe for instance, using

import pandas as pd
df = pd.DataFrame(data)

[BUG]: A bug in cec2020.F82020(ndim=10)

Description of the bug

Dear Thieu
I hope to find you well.
cec2020.F82020(ndim=10) seems to have a bug that the fitness value may be smaller than 0
and in the official technical report, the minimum is 2100.
Best wishes

Steps To Reproduce

You can directly copy the following code:

from opfunu.cec_based import cec2020

func = cec2020.F82020(ndim=10)
print(func.evaluate([90.75118764, 97.00278372, 76.1721669, 99.96999972, -11.39271999, 89.5915097, 76.24025183, 83.30977968, 23.79283718, 37.22928422]))

where the 10-D solution [90.75118764, 97.00278372, 76.1721669, 99.96999972, -11.39271999, 89.5915097, 76.24025183, 83.30977968, 23.79283718, 37.22928422] is within the search space in [-100, 100]

Additional Information

No response

[BUG]: Dolan function has wrong default dimensionality

Description of the bug

The default dimensionality of the Dolan function is 2, but the function is only defined for a dimensionality of 5
Also the dim_interchangeable=True, but this should be False

Steps To Reproduce

g = opfunu.name_based.d_func.Dolan(ndim=None)
x = np.random.rand(g.ndim)
g.evaluate(x)

Gives

[476](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/d_func.py:476) self.check_solution(x)
    [477](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/d_func.py:477) self.n_fe += 1
--> [478](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/d_func.py:478) return (abs((x[0] + 1.7 * x[1]) * np.sin(x[0]) - 1.5 * x[2]
    [479](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/d_func.py:479)             - 0.1 * x[3] * np.cos(x[3] + x[4] - x[0]) + 0.2 * x[4] ** 2 - x[1] - 1))

IndexError: index 2 is out of bounds for axis 0 with size 2

Additional Information

No response

[BUG]: cec2021 F2 has abnormal optimal value.

Description of the bug

In short:

F22021 should have a global optimal value = 1100.0, but I found much more space that has even lower values.


In detail:

The plotted function of F22021 looked like this:
θž’εΉ•ζ“·ε–η•«ι’ 2023-12-15 155906
The very little red dot near the middle (located at (2.0990197e+01, -2.3188216e+01), right as provided) should have the global optimal value of 1100.0 (equals bias), but as the plot clearly showed, much more space has a value lower than 1100.0.
For example, the red dot located at (94.14767894, 2.33460048) near the right side solved for a value of 23.98, there even exists a point (99.31320785, -0.51136206) that solved for a value of -32.35

I suppose this is not the intended outcome?

In case I did something wrong that I couldn't find myself due to the lack of domain knowledge, here is the same plot from other angles:
εœ–η‰‡
θž’εΉ•ζ“·ε–η•«ι’ 2023-12-15 160801
θž’εΉ•ζ“·ε–η•«ι’ 2023-12-15 163427

Steps To Reproduce

I use this code to draw the plot:

import numpy as np
import matplotlib.pyplot as plt
import opfunu.cec_based


if __name__ == '__main__':
    dim = 2
    eval_func = opfunu.cec_based.F22021(ndim=2)
    bound = {"upper": 100.0,
             "lower": -100.0}

    # Create a meshgrid for visualization
    x = np.linspace(bound["lower"], bound["upper"], 300)
    y = np.linspace(bound["lower"], bound["upper"], 300)
    X, Y = np.meshgrid(x, y)

    Z = np.zeros_like(X)
    for i in range(len(x)):
        for j in range(len(y)):
            Z[i, j] = eval_func.evaluate([X[i, j], Y[i, j]])

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_surface(X, Y, Z, cmap='viridis')
    ax.set_xlabel('x')
    ax.set_ylabel('y')
    ax.set_zlabel('z')

    print("f_global = ", eval_func.f_global)

    ax.scatter(2.0990197e+01, -2.3188216e+01, 1100., color='red')

    plt.show()

Additional Information

The version of main packages:
Python 3.9.13
Cython 3.0.6
matplotlib 3.8.2
numpy 1.26.2
opfunu 1.0.1

using Windows 11 22H2

LennardJones raises Error when initialized without specified `ndim`

The problem

  • The LennardJones Function has a dim_default of 2, but an ValueError is raised when the dimensionality that is given upon construction is nog in `range(6, 61)
  • This check is specified right after construction, before setting the default dimensionality. Therefore providing no argument (ndim=None) will raise the ValueError. This is inconsistant with the interface of the other named functions.

self.dim_default = 2

Minimal reproducible example

from opfunu.name_based.l_func import LennardJones
f = LennardJones(ndim=None)

will raise:

ValueError                                Traceback (most recent call last)
Cell In[13], [line 3](vscode-notebook-cell:?execution_count=13&line=3)
      [1](vscode-notebook-cell:?execution_count=13&line=1) from opfunu.name_based.l_func import LennardJones
----> [3](vscode-notebook-cell:?execution_count=13&line=3) f = LennardJones(ndim=None)

File [~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:110](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:110), in LennardJones.__init__(self, ndim, bounds)
    [108](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:108) def __init__(self, ndim=None, bounds=None):
    [109](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:109)     if ndim not in range(6, 61):
--> [110](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:110)         raise ValueError("LennardJones dimensions must be in (6, 60)")
    [111](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:111)     super().__init__()
    [112](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:112)     self.dim_changeable = True

ValueError: LennardJones dimensions must be in (6, 60)

[BUG]: Function 14 from CEC2014

Description of the bug

Hi! I was using function 14 (F14: Shifted and Rotated HGBat Function) from CEC2014 and found that evaluating the x_global gives a different result from what is expected. So, this gives a False output when we use problem.is_succeed(problem.x_global).

The expected value of problem.evaluate(problem.x_global) is 1400 (based on the document from CEC2014), but it is giving 1400.5, which explains the abovementioned issue.

Steps To Reproduce

import opfunu

problem = opfunu.cec_based.F142014(ndim=10)
problem.evaluate(problem.x_global) # expected to be 1400.0
problem.is_succeed(problem.x_global) # expected to be True

Additional Information

No response

[BUG]: Mishra07 function: np has no method factorial

Description of the bug

The Mishra Function has an operation calling np.factorial. This method does not exist

Steps To Reproduce

  1. Create an instance of the opfunu.name_based.m_func.Mishra07 function
  2. evaluate the function

Additional Information

No response

[BUG]: check pip installation

Description of the bug

I made a clean installation with pip, but I got a library requirements message.

# ModuleNotFoundError: No module named 'requests'
# ModuleNotFoundError: No module named 'pandas'

Steps To Reproduce

in a clean environment, with this code:

from opfunu.cec_based.cec2022 import *
func = F12022(ndim=10)
func.evaluate(func.create_solution())

error:

# ModuleNotFoundError: No module named 'requests'
# ModuleNotFoundError: No module named 'pandas'

solution:
pip install requests
pip install pandas

Additional Information

No response

CEC 2017

Thank you for providing CEC benchmark.

I cant find the CEC 2017 benchmark. I appreciate it if you put it in the library. thank you so much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.