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

Fix issue on Ackley Function #22

Closed
ljvmiranda921 opened this issue Sep 3, 2017 · 1 comment
Closed

Fix issue on Ackley Function #22

ljvmiranda921 opened this issue Sep 3, 2017 · 1 comment
Assignees

Comments

@ljvmiranda921
Copy link
Owner

ljvmiranda921 commented Sep 3, 2017

  • PySwarms version: 0.1.5
  • Python version: 2.7
  • Operating System: Linux

Description

It seems that the Ackley function is not working on Python 2.7 version

def ackley_func(x):
    if not np.logical_and(x >= -32, x <= 32).all():
        raise ValueError('Input for Ackley function must be within [-32, 32].')

    d = x.shape[1]
    j = (-20.0 * np.exp(-0.2 * np.sqrt((1/d) * (x**2).sum(axis=1)))
        - np.exp((1/d) * np.cos(2 * np.pi * x).sum(axis=1))
        + 20.0
        + np.exp(1))

    return j

When given an input np.zeros([3,2]), most Python 3.X versions return something that isclose to np.zeros(3). But when ran against a Python 2.7.X version, we're getting [1.718, 1.718, 1.718]

@ljvmiranda921 ljvmiranda921 self-assigned this Sep 3, 2017
ljvmiranda921 pushed a commit that referenced this issue Sep 3, 2017
Turns out that you have to typecast the shape into float in order
to give you a float. Funny that I missed that difference between 2 and 3

Author: ljvmiranda921
@ljvmiranda921
Copy link
Owner Author

Fixed. Just change to float(d). Read more here

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