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
The implementation is not correct. It reads
I'm guessing the intention was
I suggest the following implementation which avoids loops (inefficient in numpy), and is IMO more readable (it does allocate a bigger array)