(X, y, mask, **kwargs)
return (1 - obrT) * Xmc + obrT * X
Perform matrix completion method in AFASMC.
    It will train a linear model to use the label information.

    Parameters
    ----------
    X: array
        The [n_samples, n_features] training matrix in which X_ij indicates j-th
        feature of i-th instance. The unobserved entries can be anything.

    y: array
        The The [n_samples] label vector.

    mask: {list, np.ndarray}
        The mask matrix of known elements. the matrix should have the shape [n_samples, n_features].
        There must be only 1 and 0 in the matrix, in which, 1 means the corresponding element is known,
        otherwise, it will be cheated as an unknown element.

    kwargs:
        lambda1  : The lambda1 trade-off parameter
        lambda2  : The lambda2 trade-off parameter
        max_in_iter : The maximal iterations of inner optimization
        max_out_iter : The maximal iterations of the outer optimization

    Returns
    -------
    Xmc: array
        The completed matrix.

    References
    ----------
    [1] Active feature acquisition with supervised matrix completion.
        Sheng-Jun Huang, Miao Xu, Ming-Kun Xie, Masashi Sugiyama, Gang Niu and Songcan Chen
        In: Proceedings of the 24th ACM SIGKDD Conference on Knowledge Discovery and Data Mining (KDD'18), 2018.
Perform matrix completion method in AFASMC.
    It will train a linear model to use the label information.
Perform matrix completion method in AFASMC . It will train a linear model to use the label information .
def AFASMC_mask_mc(X, y, mask, **kwargs):
    """Perform matrix completion method in AFASMC.
    It will train a linear model to use the label information.

    Parameters
    ----------
    X: array
        The [n_samples, n_features] training matrix in which X_ij indicates j-th
        feature of i-th instance. The unobserved entries can be anything.

    y: array
        The The [n_samples] label vector.

    mask: {list, np.ndarray}
        The mask matrix of known elements. the matrix should have the shape [n_samples, n_features].
        There must be only 1 and 0 in the matrix, in which, 1 means the corresponding element is known,
        otherwise, it will be cheated as an unknown element.

    kwargs:
        lambda1  : The lambda1 trade-off parameter
        lambda2  : The lambda2 trade-off parameter
        max_in_iter : The maximal iterations of inner optimization
        max_out_iter : The maximal iterations of the outer optimization

    Returns
    -------
    Xmc: array
        The completed matrix.

    References
    ----------
    [1] Active feature acquisition with supervised matrix completion.
        Sheng-Jun Huang, Miao Xu, Ming-Kun Xie, Masashi Sugiyama, Gang Niu and Songcan Chen
        In: Proceedings of the 24th ACM SIGKDD Conference on Knowledge Discovery and Data Mining (KDD'18), 2018.
    """
    X = np.asarray(X)
    y = np.asarray(y)
    n_samples, n_features = X.shape
    max_in_iter = kwargs.pop('max_in_iter', 100)
    max_out_iter = kwargs.pop('max_out_iter', 10)
    lambda1 = kwargs.pop('lambda1', 1)
    lambda2 = kwargs.pop('lambda2', 1)
    check_para = kwargs.pop('check_para', True)
    obrT = mask
    if check_para:
        obrT = np.asarray(mask)
        assert obrT.shape[0] == X.shape[0] and obrT.shape[1] == X.shape[1]
        ue = np.unique(obrT)
        assert len(ue) == 2
        assert 0 in ue
        assert 1 in ue
    X_obr = np.zeros((n_samples, n_features))
    X_obr += obrT * X
    n_samples, n_features = X.shape
    lambda2 /= n_samples
    theta0 = 1
    theta1 = 1
    Z0 = np.zeros((n_samples, n_features))
    Z1 = np.zeros((n_samples, n_features))
    ineqLtemp0 = np.zeros((n_samples, n_features))
    ineqLtemp1 = ineqLtemp0
    L = 2
    converge_out = np.zeros((max_in_iter, 1))

    for i in range(max_out_iter):
        # train a linear model whose obj function is min{norm(Xw-Y)}
        X_extend = np.hstack((X_obr, np.ones((n_samples, 1))))
        W = np.linalg.pinv(X_extend.T.dot(X_extend)).dot(X_extend.T).dot(y)
        w = W[0:-1].flatten()
        b = W[-1]

        convergence = np.zeros(max_in_iter)

        for k in range(max_in_iter):
            Y = Z1 + theta1 * (1 / theta0 - 1) * (Z1 - Z0)
            svd_obj_temp_temp = (theta1 * (1 / theta0 - 1) + 1) * ineqLtemp1 - theta1 * (
                    1 / theta0 - 1) * ineqLtemp0 - X_obr
            svd_obj_temp = svd_obj_temp_temp + 2 * lambda2 * (Y.dot(w) + b - y).reshape(-1, 1).dot(w.reshape((1, -1)))
            svd_obj = Y - 1 / L * svd_obj_temp
            Z0 = copy.copy(Z1)
            Z1, traceNorm = _svd_threshold(svd_obj, lambda1 / L)

            ineqLtemp0 = ineqLtemp1
            # do not know whether it is element wise or not
            ineqLtemp1 = Z1 * obrT
            ineqL = np.linalg.norm(ineqLtemp1 - X_obr, ord='fro') ** 2 / 2 + sum((Z1.dot(w) + b - y) ** 2) * lambda2

            ineqRtemp = sum(sum(svd_obj_temp_temp ** 2)) / 2 + sum(
                (Y.dot(w) + b - y) ** 2) * lambda2 - svd_obj_temp.flatten().dot(
                Y.flatten())
            ineqR = ineqRtemp + svd_obj_temp.flatten().dot(Z1.flatten()) + L / 2 * sum(sum((Z1 - Y) ** 2))

            while ineqL > ineqR:
                L = L * 2
                svd_obj = Y - 1 / L * svd_obj_temp
                Z1, traceNorm = _svd_threshold(svd_obj, lambda1 / L)

                ineqLtemp1 = Z1 * obrT
                ineqL = np.linalg.norm(ineqLtemp1 - X_obr, ord='fro') ** 2 / 2 + sum((Z1.dot(w) + b - y) ** 2) * lambda2
                ineqR = ineqRtemp + svd_obj_temp.flatten().dot(Z1.flatten()) + L / 2 * sum(sum((Z1 - Y) ** 2))

            theta0 = theta1
            theta1 = (np.sqrt(theta1 ** 4 + 4 * theta1 ** 2) - theta1 ** 2) / 2

            convergence[k] = ineqL + lambda1 * traceNorm

            # judge convergence
            if k == 0:
                minObj = convergence[k]
                X_mc = Z1
            else:
                if convergence[k] < minObj:
                    minObj = convergence[k]
                    X_mc = Z1
            if k > 0:
                if np.abs(convergence[k] - convergence[k - 1]) < ((1e-6) * convergence[k - 1]):
                    break

        converge_out[i] = minObj
        if i == 0:
            minObj_out = converge_out[k]
            Xmc = X_mc
        else:
            if converge_out[k] < minObj_out:
                minObj_out = converge_out[k]
                Xmc = X_mc
        if i > 0:
            if abs(converge_out[k] - converge_out[k - 1]) < (1e-4 * converge_out[k - 1]):
                break

    return (1 - obrT) * Xmc + obrT * X
def AFASMC_mask_mc ( X , y , mask , * * kwargs ) : X = np . asarray ( X ) y = np . asarray ( y ) n_samples , n_features = X . shape max_in_iter = kwargs . pop ( 'max_in_iter' , 100 ) max_out_iter = kwargs . pop ( 'max_out_iter' , 10 ) lambda1 = kwargs . pop ( 'lambda1' , 1 ) lambda2 = kwargs . pop ( 'lambda2' , 1 ) check_para = kwargs . pop ( 'check_para' , True ) obrT = mask if check_para : obrT = np . asarray ( mask ) assert obrT . shape [ 0 ] == X . shape [ 0 ] and obrT . shape [ 1 ] == X . shape [ 1 ] ue = np . unique ( obrT ) assert len ( ue ) == 2 assert 0 in ue assert 1 in ue X_obr = np . zeros ( ( n_samples , n_features ) ) X_obr += obrT * X n_samples , n_features = X . shape lambda2 /= n_samples theta0 = 1 theta1 = 1 Z0 = np . zeros ( ( n_samples , n_features ) ) Z1 = np . zeros ( ( n_samples , n_features ) ) ineqLtemp0 = np . zeros ( ( n_samples , n_features ) ) ineqLtemp1 = ineqLtemp0 L = 2 converge_out = np . zeros ( ( max_in_iter , 1 ) ) for i in range ( max_out_iter ) : # train a linear model whose obj function is min{norm(Xw-Y)} X_extend = np . hstack ( ( X_obr , np . ones ( ( n_samples , 1 ) ) ) ) W = np . linalg . pinv ( X_extend . T . dot ( X_extend ) ) . dot ( X_extend . T ) . dot ( y ) w = W [ 0 : - 1 ] . flatten ( ) b = W [ - 1 ] convergence = np . zeros ( max_in_iter ) for k in range ( max_in_iter ) : Y = Z1 + theta1 * ( 1 / theta0 - 1 ) * ( Z1 - Z0 ) svd_obj_temp_temp = ( theta1 * ( 1 / theta0 - 1 ) + 1 ) * ineqLtemp1 - theta1 * ( 1 / theta0 - 1 ) * ineqLtemp0 - X_obr svd_obj_temp = svd_obj_temp_temp + 2 * lambda2 * ( Y . dot ( w ) + b - y ) . reshape ( - 1 , 1 ) . dot ( w . reshape ( ( 1 , - 1 ) ) ) svd_obj = Y - 1 / L * svd_obj_temp Z0 = copy . copy ( Z1 ) Z1 , traceNorm = _svd_threshold ( svd_obj , lambda1 / L ) ineqLtemp0 = ineqLtemp1 # do not know whether it is element wise or not ineqLtemp1 = Z1 * obrT ineqL = np . linalg . norm ( ineqLtemp1 - X_obr , ord = 'fro' ) ** 2 / 2 + sum ( ( Z1 . dot ( w ) + b - y ) ** 2 ) * lambda2 ineqRtemp = sum ( sum ( svd_obj_temp_temp ** 2 ) ) / 2 + sum ( ( Y . dot ( w ) + b - y ) ** 2 ) * lambda2 - svd_obj_temp . flatten ( ) . dot ( Y . flatten ( ) ) ineqR = ineqRtemp + svd_obj_temp . flatten ( ) . dot ( Z1 . flatten ( ) ) + L / 2 * sum ( sum ( ( Z1 - Y ) ** 2 ) ) while ineqL > ineqR : L = L * 2 svd_obj = Y - 1 / L * svd_obj_temp Z1 , traceNorm = _svd_threshold ( svd_obj , lambda1 / L ) ineqLtemp1 = Z1 * obrT ineqL = np . linalg . norm ( ineqLtemp1 - X_obr , ord = 'fro' ) ** 2 / 2 + sum ( ( Z1 . dot ( w ) + b - y ) ** 2 ) * lambda2 ineqR = ineqRtemp + svd_obj_temp . flatten ( ) . dot ( Z1 . flatten ( ) ) + L / 2 * sum ( sum ( ( Z1 - Y ) ** 2 ) ) theta0 = theta1 theta1 = ( np . sqrt ( theta1 ** 4 + 4 * theta1 ** 2 ) - theta1 ** 2 ) / 2 convergence [ k ] = ineqL + lambda1 * traceNorm # judge convergence if k == 0 : minObj = convergence [ k ] X_mc = Z1 else : if convergence [ k ] < minObj : minObj = convergence [ k ] X_mc = Z1 if k > 0 : if np . abs ( convergence [ k ] - convergence [ k - 1 ] ) < ( ( 1e-6 ) * convergence [ k - 1 ] ) : break converge_out [ i ] = minObj if i == 0 : minObj_out = converge_out [ k ] Xmc = X_mc else : if converge_out [ k ] < minObj_out : minObj_out = converge_out [ k ] Xmc = X_mc if i > 0 : if abs ( converge_out [ k ] - converge_out [ k - 1 ] ) < ( 1e-4 * converge_out [ k - 1 ] ) : break return ( 1 - obrT ) * Xmc + obrT * X