Skip to content

Mistake in Shubert function #7

Description

@gbelouze

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions