risk.py 文件源码

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

项目:operalib 作者: operalib 项目源码 文件源码
def __call__(self, coefs, ground_truth, Gram,
                 weight=None, zeronan=None):
        """Compute the Empirical OVK ridge risk.

        Parameters
        ----------
        coefs : {vector-like}, shape = [n_samples1 * n_targets]
            Coefficient to optimise

        ground_truth : {vector-like}
            Targets samples

        Gram : {LinearOperator}
            Gram matrix acting on the coefs

        weight: {LinearOperator}

        zeronan: {LinearOperator}

        Returns
        -------
        float : Empirical OVK ridge risk
        """
        np = ground_truth.size
        pred = Gram * coefs
        reg = inner(coefs, pred)  # reg in rkhs
        vgt = masked_invalid(ground_truth)
        vgt[where(vgt.mask)] = pred[where(vgt.mask)]
        if weight is None or zeronan is None:
            obj = norm(pred - vgt) ** 2 / (2 * np)
        else:
            wpred = weight * pred  # sup x identity | unsup x lbda_m x L
            res = zeronan * (wpred - vgt)
            wip = wpred - zeronan * wpred  # only unsup part of wpred
            lap = inner(wip, pred)  # Laplacian part x lambda_m

            obj = norm(zeronan * res) ** 2 / (2 * np)  # Loss
            obj += lap / (2 * np)  # Laplacian regularization
        obj += self.lbda * reg / (2 * np)  # Regulariation
        return obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号