sigma_adaptation.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:pycma 作者: CMA-ES 项目源码 文件源码
def update(self, es, function_values, **kwargs):
        """the first and second value in ``function_values``
        must reflect two mirrored solutions.

        Mirrored solutions must have been sampled
        in direction / in opposite direction of
        the previous mean shift, respectively.
        """
        # On the linear function, the two mirrored samples lead
        # to a sharp increase of the condition of the covariance matrix,
        # unless we have negative weights (which we have now by default).
        # Otherwise they should not be used to update the covariance
        # matrix, if the step-size inreases quickly.
        if self.initialized is not True:  # try again
            self.initialize(es.N, es.opts)
        if self.initialized is not True:
            utils.print_warning("dimension not known, damping set to 4",
                'update', 'CMAAdaptSigmaTPA')
            self.initialized = True
        if 1 < 3:
            f_vals = function_values
            z = sum(f_vals < f_vals[1]) - sum(f_vals < f_vals[0])
            z /= len(f_vals) - 1  # z in [-1, 1]
        elif 1 < 3:
            # use the ranking difference of the mirrors for adaptation
            # damp = 5 should be fine
            z = np.nonzero(es.fit.idx == 1)[0][0] - np.nonzero(es.fit.idx == 0)[0][0]
            z /= es.popsize - 1  # z in [-1, 1]
        self.s = (1 - self.sp.c) * self.s + self.sp.c * np.sign(z) * np.abs(z)**self.sp.z_exponent
        if self.s > 0:
            es.sigma *= np.exp(self.s / self.sp.dampup)
        else:
            es.sigma *= np.exp(self.s / self.sp.dampdown)
        #es.more_to_write.append(10**z)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号