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

ScaleCoordinates gives an unexpected outcomes #279

Open
Landau1908 opened this issue Nov 16, 2024 · 3 comments
Open

ScaleCoordinates gives an unexpected outcomes #279

Landau1908 opened this issue Nov 16, 2024 · 3 comments

Comments

@Landau1908
Copy link

Hi,
Below is a toy example that confuses me. If no ScaleCoordinates is implemented, the result is right, but if it is implemented, the result has a bit difference from the expected.
Regards

import numpy as np
import cma
from cma.fitness_transformations import ScaleCoordinates

def objective_function(x):
    return sum(xi**2 for xi in x)

min_values = [-5., -3.0, -90.0]
max_values = [1.0, 10.0, 1000.0]

x0 = [1.]*3
sigma = 0.5
popsize = (4 + 3 * int(np.log(len(x0))))*2**0

scaled_objective = ScaleCoordinates(objective_function, upper=max_values, lower=min_values)
result = cma.fmin(objective_function, x0, sigma, options={"bounds":[min_values,max_values]})
#result = cma.fmin(scaled_objective, x0, sigma, options={'popsize':popsize})

While use non-ScaleCoordinates, executing result = cma.fmin(objective_function, x0, sigma, options={"bounds":[min_values,max_values]}), the outcomes as follows:

result = cma.fmin(objective_function, x0, sigma, options={"bounds":[min_values,max_values]})
(3_w,7)-aCMA-ES (mu_w=2.3,w_1=58%) in dimension 3 (seed=920413, Sat Nov 16 20:21:12 2024)
Iterat #Fevals   function value  axis ratio  sigma  min&max std  t[m:s]
    1      7 9.256576457964325e-01 1.0e+00 5.16e-01  5e-01  6e-01 0:00.0
    2     14 8.942005501052922e-01 1.3e+00 5.37e-01  5e-01  6e-01 0:00.0
    3     21 1.149100036298669e-01 1.4e+00 5.63e-01  5e-01  7e-01 0:00.0
   87    609 3.175444797697971e-15 1.6e+00 1.10e-05  5e-08  8e-08 0:00.3
termination on tolfun=1e-11 (Sat Nov 16 20:21:13 2024)
final/bestever f-value = 2.709817e-15 2.709817e-15 after 610/610 evaluations
incumbent solution: [-4.350586266957847e-08, -7.639240333223374e-11, 2.858409961559774e-08]
std deviation: [5.516615851554868e-08, 7.651271053286152e-08, 4.661592773435972e-08]

While use ScaleCoordinates, executing result = cma.fmin(scaled_objective, x0, sigma, options={'popsize':popsize}), the outcomes as follows:

result = cma.fmin(scaled_objective, x0, sigma, options={'popsize':popsize})
(3_w,7)-aCMA-ES (mu_w=2.3,w_1=58%) in dimension 3 (seed=893013, Sat Nov 16 20:35:37 2024)
Iterat #Fevals   function value  axis ratio  sigma  min&max std  t[m:s]
    1      7 2.922935931957261e+04 1.0e+00 6.02e-01  6e-01  7e-01 0:00.0
    2     14 2.582756871627401e+04 1.6e+00 6.02e-01  6e-01  7e-01 0:00.0
    3     21 8.082952119227459e+02 1.4e+00 5.54e-01  5e-01  6e-01 0:00.0
  100    700 2.865720965914941e-09 2.1e+02 2.14e-04  7e-08  1e-05 0:00.3
  137    959 1.141555637256842e-14 1.9e+02 2.49e-06  7e-11  1e-08 0:00.5
termination on tolfun=1e-11 (Sat Nov 16 20:35:39 2024)
final/bestever f-value = 4.063595e-15 4.012026e-15 after 960/938 evaluations
incumbent solution: [0.8333333278186403, 0.2307692269918536, 0.08256880736110907]
std deviation: [1.3134116534238395e-08, 5.417763022950125e-09, 6.802938878850222e-11]
@nikohansen
Copy link
Contributor

the outcomes as follows:
[...]

What is the expected outcome?

@Landau1908
Copy link
Author

the outcomes as follows:
[...]

What is the expected outcome?

What I interseted is the best solutions. If I understand correctly, the best solution from the outputs is the incumbent solution. non-ScaleCoordinates gives incumbent solution: [-4.350586266957847e-08, -7.639240333223374e-11, 2.858409961559774e-08], and ScaleCoordinates gives incumbent solution: [0.8333333278186403, 0.2307692269918536, 0.08256880736110907], and there is a bit different in between although the final/bestever f-value ~ 1e-15 is extremely good for both the cases. I don't know why this happens.

@nikohansen
Copy link
Contributor

ScaleCoordinates gives incumbent solution: [0.8333333278186403, 0.2307692269918536, 0.08256880736110907], and there is a bit different in between although the final/bestever f-value ~ 1e-15 is extremely good for both the cases. I don't know why this happens.

I suspect the incumbent is what you are interested in ("the best solution"): if you evaluate [0.8333333278186403, 0.2307692269918536, 0.08256880736110907] on the scaled function, scaled_objective, you will get about $10^{-15}$, which is what I would expect should happen, because you have run CMA-ES on scaled_objective.

The respective solution to the original function can be obtained as

scaled_objective.transform([0.8333333278186403, 0.2307692269918536, 0.08256880736110907])

giving the output

array([-3.30881575e-08, -4.91059035e-08,  2.36088783e-08])

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

2 participants