numbbo / coco

Numerical Black-Box Optimization Benchmarking Framework
https://numbbo.github.io/coco
Other
254 stars 85 forks source link

How to reproduce the coco problems #2285

Closed yedidyakfir closed 1 month ago

yedidyakfir commented 1 month ago

Hi, I am trying to recreate the step ellipsoid function with pytorch (I am conducting a research and I am trying to analyze the function to find some analytical properties).

Here is the code I came up with

R = generate_orthonormal_matrix(dim)
Q = generate_orthonormal_matrix(dim)

def step_elipsoid(x):
    lambda_10_matrix = torch.eye(dim) * (10 ** torch.arange(dim) / (dim - 1))
    z_hat = lambda_10_matrix @ R @ (x - x_best)
    z_telda_mask = z_hat.abs() > 0.5
    z_telda_less_than_point5 = torch.floor(0.5 + z_hat) * z_telda_mask
    z_telda_greater_than_point5 = (torch.floor(0.5 + 10 * z_hat) / 10) * (~z_telda_mask)
    z_telda = z_telda_less_than_point5 + z_telda_greater_than_point5
    z = Q @ z_telda
    sum_multipliers_power = 10 ** (2 * (torch.arange(z_hat.shape[-1]) / (z_hat.shape[-1] - 1)))

    return (
        0.1
        * torch.max(z_hat[..., 0].abs() * 1e-4, ((z**2) * sum_multipliers_power).sum())
        + f_best
    )

However, It seems function I print is vastly different from the one in the COCO dataset and much easier to solve. I added an image of the function I created in 2d [-5,5] image

Notice how wide the minimum area is, while in the real coco function, this space is very narrow, observe image

I tried to play around with the rotation matrix R and Q but nothing helped. Any ideas?

nikohansen commented 1 month ago

I am not sure I understand how you get the same matrices in both cases. If you don't, you can't expect to see the same?

From the picture it looks like some scaling is different, hence the second function is steeper. It could be x- or f-value scaling.

I suggest to evaluate the very same point(s) on the function from cocoex.Suite('bbob',... and on the implemented one. They should be identical, obviously. There exists also an old Python implementation to compare with which can be found here.

yedidyakfir commented 1 month ago

Thanks, the new function is much closer to the one in the library, but notice that the function is different from the one I found in the docs. image For example, you dont add 0.5, and you dont multiply with big lambda, is it possible the docs are deprecated? Thanks

nikohansen commented 1 month ago

For example, you dont add 0.5, and you dont multiply with big lambda, is it possible the docs are deprecated?

I don't quite understand, I just had a quick look at the Python code, and it seems to add 0.5 ($x\mapsto\lfloor 0.5 + x\rfloor$ is up to a nullset the round function) and to multiply with $\Lambda$ too in line 991. The documentation seemed to have been carefully reviewed repeatedly, I do still suspect it is correct and agrees with the implementations.

nikohansen commented 1 month ago

For a start, I don't think the lambda_10_matrix in the code of the OP, first line of the function, is computed correctly: there seem to be braces and a square root missing. 10 ** torch.arange(dim) / (dim - 1) must read (10 ** 0.5) ** (torch.arange(dim) / (dim - 1)), at least that seems to be closer to what I see in the original code and the documentation, but don't take for granted that this is fully correct too, I didn't triple check. Unfortunately, I don't think this fully explains the difference we see though, so I would suspect there are more discrepancies.