Example #1
0
def QueryGen(queryPoint, S, T_cols):
    """
    用于用户输入的一个查询数据点,产生线性变换所需矩阵
    :param queryPoint:
    :return:
    """
    #对用户输入的queryPoint做特殊构造以便于后文的计算
    # print(queryPoint.shape)
    # print( queryPoint[0])
    dim = queryPoint.shape[0]  #注意数据维度的获取
    #对查询向量做特殊构造
    newQueryPoint = np.zeros((1, dim + 2), dtype=object)
    temp = queryPoint.dot(queryPoint.T)
    newQueryPoint[0][0] = temp
    newQueryPoint[0][1] = 1
    for j in range(dim):
        newQueryPoint[0][j + 2] = (-2) * queryPoint[j]
    dim = newQueryPoint.shape[1]  #更新dim
    newQueryPoint.resize((1, dim))  # 转换数据维度
    G = (np.copy(newQueryPoint))
    newPs, newPm = mvhe.getinvertiblematrix(1 + T_cols)
    newT = mvhe.getRandomMatrix(1, T_cols, mvhe.tBound)  # 产生新随机矩阵T
    newS = mvhe.getSecretKey(newT, newPs)  # 新密钥
    GS = G.dot(S)
    M = mvhe.KeySwicthMatrix(GS, newT, newPm)
    return M, newS
Example #2
0
def QueryGen(queryDataSet, S, T_cols):
    """
    用于用户输入的一个查询数据点,产生线性变换所需矩阵
    :param queryPoint:
    :return:
    """
    # 对用户输入的queryDataSet做特殊构造以便于后文的计算

    queryPoints, dim = queryDataSet.shape
    queryDataReshape = np.zeros((queryPoints, dim + 2), dtype=object)
    for i in range(queryPoints):
        temp = queryDataSet[i].dot(queryDataSet[i].T)
        queryDataReshape[i][0] = temp
        queryDataReshape[i][1] = 1
        for j in range(dim):
            queryDataReshape[i][j + 2] = (-2) * testData[i][j]

    dim = queryDataReshape.shape[1]  # 更新dim
    queryDataReshape.resize((queryPoints, dim))  # 转换数据维度
    G = (np.copy(queryDataReshape))
    newPs, newPm = mvhe.getinvertiblematrix(queryPoints + T_cols)
    newT = mvhe.getRandomMatrix(queryPoints, T_cols, mvhe.tBound)  # 产生新随机矩阵T
    newS = mvhe.getSecretKey(newT, newPs)  # 新密钥
    GS = G.dot(S)
    M = mvhe.KeySwicthMatrix(GS, newT, newPm)
    return M, newS