CMA-ES / pycma

Python implementation of CMA-ES
Other
1.1k stars 178 forks source link

`feed_for_resume` does not always work as desired #240

Open nikohansen opened 1 year ago

nikohansen commented 1 year ago
import cma

es = cma.CMA(3 * [1], 1)
es2 = cma.CMA(3 * [1], 1)

while es.countiter < 5:
    X = es.ask()
    F = [cma.ff.elli(x) for x in X]
    es2.feed_for_resume(X, F)
    es.tell(X, F)

es.mean - es2.mean, es.pc - es2.pc, es.sm.C - es2.sm.C

gives various outputs, for example (as desired)

(array([0., 0., 0.]),
 array([0., 0., 0.]),
 array([[0., 0., 0.],
        [0., 0., 0.],
        [0., 0., 0.]]))

or

(array([0., 0., 0.]),
 array([-0.01003765, -0.00932539,  0.00022431]),
 array([[-3.00553023e-04,  1.62628230e-03, -3.18358657e-04],
        [ 1.62628230e-03,  2.95684916e-03, -5.22568484e-04],
        [-3.18358657e-04, -5.22568484e-04,  4.74778472e-05]]))

or

(array([0., 0., 0.]),
 array([0., 0., 0.]),
 array([[-4.00768307e-12, -2.87188329e-12,  8.28524749e-13],
        [-2.87186941e-12, -1.87161397e-12,  5.97299987e-13],
        [ 8.28545565e-13,  5.97286109e-13, -1.49491530e-13]]))

Sometimes also the mean is different.

Using a deep copy for feeding doesn't change the observation.