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

The Ackley function Bug #306

Open
mym92 opened this issue Apr 7, 2023 · 0 comments
Open

The Ackley function Bug #306

mym92 opened this issue Apr 7, 2023 · 0 comments

Comments

@mym92
Copy link

mym92 commented Apr 7, 2023

Hi, @thouska ,thank you and all contributors for the spotpy project. I have learnt a lot from your project.
I found a minor bug in the the Ackley function example:
your code in spot_setup_ackley.py:

def simulation(self, vector):
       firstSum = 0.0
       secondSum = 0.0
       for c in range(len(vector)):
            firstSum += c**2.0
            secondSum += np.cos(2.0 * np.pi * vector[c])
            n = float(len(vector))
       return [
            -20.0 * np.exp(-0.2 * np.sqrt(firstSum / n))
            - np.exp(secondSum / n)
            + 20
            + np.e
        ]
  1. The calculation of n's value does not require placement within the FOR loop body.
  2. On line five, direct use of the value of c in calculations is improper
    I think the right cods is:
def simulation(self, vector):
    firstSum = 0.0
    secondSum = 0.0
    for c in range(len(vector)):
        firstSum += vector[c]**2.0
        secondSum += np.cos(2.0 * np.pi * vector[c])
    n = float(len(vector))
    return [
            -20.0 * np.exp(-0.2 * np.sqrt(firstSum / n))
            - np.exp(secondSum / n)
            + 20
            + np.e
        ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant