根据边生成meta-path

def load_yelp():
    import scipy.sparse as sp
    import pickle
    path = "data/yelp_old/"
    with open(path + '/meta_data.pkl', 'rb') as f:
        data = pickle.load(f)
    with open(path + '/labels.pkl', 'rb') as f:
        labels = pickle.load(f)
    with open(path + '/edges.pkl', 'rb') as f:
        edges = pickle.load(f)

    BS = sparse_mx_to_torch_sparse_tensor(edges['b-s']).float()._indices()  # adj_list[0]._indices()
    SB = sparse_mx_to_torch_sparse_tensor(edges['s-b']).float()._indices()  # adj_list[1]._indices()
    BL = sparse_mx_to_torch_sparse_tensor(edges['b-l']).float()._indices()  # adj_list[0]._indices()
    LB = sparse_mx_to_torch_sparse_tensor(edges['l-b']).float()._indices()  # adj_list[1]._indices()
    BU = sparse_mx_to_torch_sparse_tensor(edges['b-u']).float()._indices()  # adj_list[0]._indices()
    UB = sparse_mx_to_torch_sparse_tensor(edges['u-b']).float()._indices()  # adj_list[1]._indices()
    BS = sp.coo_matrix((np.ones(BS.shape[1]), (BS[0,:], BS[1, :]-3900)),
                       shape=(max(BS[0])+1, max(BS[1])- min(BS[1]) +1),
                       dtype=np.float32)
    BL = sp.coo_matrix((np.ones(BL.shape[1]), (BL[0,:], BL[1, :]-3904)),
                       shape=(max(BL[0]) + 1, max(BL[1])- min(BL[1])  + 1), #- min(BL[1])
                       dtype=np.float32)
    BU = sp.coo_matrix((np.ones(BU.shape[1]), (BU[0,:], BU[1, :]-2614)),
                       shape=(max(BU[0]) + 1, max(BU[1])- min(BU[1])  + 1), #- min(BU[1])
                       dtype=np.float32)

    BSB = BS*BS.T
    BUB = BU*BU.T
    BLB = BL*BL.T#RB.transpose()*RU*RU.transpose()*RB
    # BRKRB = RB.transpose()*RK*RK.transpose()*RB

    BSB = pathsim(BSB)
    BUB = pathsim(BUB)
    BLB = pathsim(BLB)

    sp.save_npz("{}{}".format(path, 'BSB.npz'), BSB)
    sp.save_npz("{}{}".format(path, 'BUB.npz'), BUB)
    sp.save_npz("{}{}".format(path, 'BLB.npz'), BLB)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值