Skip to content

Mistake in Shubert function #7

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

Open
gbelouze opened this issue Sep 21, 2022 · 0 comments
Open

Mistake in Shubert function #7

gbelouze opened this issue Sep 21, 2022 · 0 comments

Comments

@gbelouze
Copy link

The implementation is not correct. It reads

d = X.shape[0]
for i in range(0,d):
    res = np.prod(np.sum([i * np.cos((j+1)*X[i] + j) for j in range(1, 5+1)]))
return res

I'm guessing the intention was

d = X.shape[0]
res = np.prod([
    np.sum([i * np.cos((j+1)*X[i] + j) for j in range(1, 5+1)]))
    for i in range(d)
])
return res

I suggest the following implementation which avoids loops (inefficient in numpy), and is IMO more readable (it does allocate a bigger array)

def f(self, X):
    j = np.arange(1, 6)[None, :]
    res = np.cos((j + 1) * X[:, None] + j) \
        .sum(axis=1) \
        .prod()
    return res
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