Skip to content

CMAES index mismatch in update_distribution #474

@chengzi-1023

Description

@chengzi-1023

Hi team, thanks for the great library!
While testing CMA-ES, I found an index mismatch in update_distribution that corrupts the negative weight adaptation (Active CMA-ES) and leads to convergence failures.

The Bug: When calculating w_o, the code uses d.T to calculate the norm:

w_o = self._w*np.where(self._w >= 0, 1.0, self.ndim_problem/(np.square(
    np.linalg.norm(cm_minus_half @ d.T, axis=0)) + 1e-8))

However, self._w is rank-based (sorted), while d.T is chronologically ordered (unsorted). This means the norm of an unsorted individual is erroneously used to scale the ranked update, distorting the covariance matrix.

The Fix: Changing d.T to d[order].T.

Results: This single-line fix brings major improvements on functions like Ackley, Cigar, and Rosenbrock. The success rates now closely match the official pycma baseline.

Hope this helps! 😊

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