好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 如何建立一個超圖詳解

如何建立一個超圖詳解

熱門標簽:京華圖書館地圖標注 電話外呼系統招商代理 打印谷歌地圖標注 蘇州人工外呼系統軟件 電話機器人貸款詐騙 看懂地圖標注方法 淮安呼叫中心外呼系統如何 廣東旅游地圖標注 佛山通用400電話申請

1.圖和超圖

圖作為一種數據結構,由節點和邊組成,可由下圖表示。其中一個邊只能鏈接兩個節點。一個圖可表示為G=(v,e,w)

其中v表示節點,e表示邊,w表示節點的特征。關于圖的表示可參考,本文不再詳述。

對于超圖,其與圖結構最主要的區別就是一條邊可以連接多個節點,因此我們可以認為圖是一種特殊的超圖。超圖結構如下圖所示。

超圖可表示為G=(υ,ε,ω)。其中υ為節點集合,ε為超邊集合,ω為超邊權重的對稱矩陣。超圖G可以關聯矩陣H來表示,其詞條定義為:

改公式可解釋為如果某個節點屬于某個超邊,則關聯矩陣H的值為1,否則為0。

對于單個節點v可定義為:

可解釋為連接該節點的所有邊乘上權重向量的和。

Dₑ和Dᵥ由d(v)和s(e)分別表示為超邊和節點的對角矩陣。

單個邊可定義為:

可以理解為該邊包含的所有節點之和。

2.實例

下面舉出一個具體實例幫助理解超圖的構建。以該圖為例

圖中有8個節點,3個超邊。超邊的細化圖如下:

假設權重W為全1矩陣,因為它對構建超圖數據結果無影響,那么H為一個3行8列的矩陣,表示為:

h(1,1) = 0

h(2,1) = 1

h(3,1) = 0

h(4,1) = 1

h(5,1) = 0

h(6,1) = 0

h(7,1) = 0

h(8,1) = 1

h(1,2) = 1

h(2,2) = 0

h(3,2) = 0

h(4,2) = 0

h(5,2) = 0

h(6,2) = 1

h(7,2) = 1

h(8,2) = 0

h(1,3) = 0

h(2,3) = 0

h(3,3) = 1

h(4,3) = 0

h(5,3) = 1

h(6,3) = 0

h(7,3) = 1

h(8,3) = 0

De​表示為:

d(1) = 1

d(2) = 1

d(3) = 1

d(4) = 1

d(5) = 1

d(6) = 1

d(7) = 2

d(8) = 1

Dv​表示為:

s(1) = 3

s(2) = 3

s(3) = 3

3.代碼實現

下面我們用python代碼進行編程,我們的目標是在知道節點的特征W通過特征的距離來生成 G \mathcal{G} G矩陣。路線為:W,H, G \mathcal{G} G。主要代碼如下:

import numpy as np
#KNN生成H
x = np.array([[1,0,0,0,1,0,1,0,0,0],
        [1,1,1,0,0,0,1,1,1,0],
       [1,1,1,0,0,1,1,1,1,0],
       [0,1,0,0,0,0,1,0,1,0],
       [1,1,1,1,0,0,1,1,0,1],
       [1,0,1,0,0,1,0,1,1,0],
       [0,1,0,0,1,0,1,1,1,0],
       [0,1,1,0,1,0,1,0,1,1]])
def Eu_dis(x):
    """
    Calculate the distance among each raw of x
    :param x: N X D
                N: the object number
                D: Dimension of the feature
    :return: N X N distance matrix
    """
    x = np.mat(x)
    aa = np.sum(np.multiply(x, x), 1)
    ab = x * x.T
    dist_mat = aa + aa.T - 2 * ab
    dist_mat[dist_mat  0] = 0
    dist_mat = np.sqrt(dist_mat)
    dist_mat = np.maximum(dist_mat, dist_mat.T)
    return dist_mat
def hyperedge_concat(*H_list):
    """
    Concatenate hyperedge group in H_list
    :param H_list: Hyperedge groups which contain two or more hypergraph incidence matrix
    :return: Fused hypergraph incidence matrix
    """
    H = None
    for h in H_list:
        if h is not None and h != []:
            # for the first H appended to fused hypergraph incidence matrix
            if H is None:
                H = h
            else:
                if type(h) != list:
                    H = np.hstack((H, h))
                else:
                    tmp = []
                    for a, b in zip(H, h):
                        tmp.append(np.hstack((a, b)))
                    H = tmp
    return H
def construct_H_with_KNN_from_distance(dis_mat, k_neig, is_probH=True, m_prob=1):
    """
    construct hypregraph incidence matrix from hypergraph node distance matrix
    :param dis_mat: node distance matrix
    :param k_neig: K nearest neighbor
    :param is_probH: prob Vertex-Edge matrix or binary
    :param m_prob: prob
    :return: N_object X N_hyperedge
    """
    n_obj = dis_mat.shape[0]
    # construct hyperedge from the central feature space of each node
    n_edge = n_obj
    H = np.zeros((n_obj, n_edge))
    for center_idx in range(n_obj):
        dis_mat[center_idx, center_idx] = 0
        dis_vec = dis_mat[center_idx]
        nearest_idx = np.array(np.argsort(dis_vec)).squeeze()
        avg_dis = np.average(dis_vec)
        if not np.any(nearest_idx[:k_neig] == center_idx):
            nearest_idx[k_neig - 1] = center_idx
        for node_idx in nearest_idx[:k_neig]:
            if is_probH:
                H[node_idx, center_idx] = np.exp(-dis_vec[0, node_idx] ** 2 / (m_prob * avg_dis) ** 2)
            else:
                H[node_idx, center_idx] = 1.0
    return H
def construct_H_with_KNN(X, K_neigs=[10], split_diff_scale=False, is_probH=True, m_prob=1):
    """
    init multi-scale hypergraph Vertex-Edge matrix from original node feature matrix
    :param X: N_object x feature_number
    :param K_neigs: the number of neighbor expansion
    :param split_diff_scale: whether split hyperedge group at different neighbor scale
    :param is_probH: prob Vertex-Edge matrix or binary
    :param m_prob: prob
    :return: N_object x N_hyperedge
    """
    if len(X.shape) != 2:
        X = X.reshape(-1, X.shape[-1])
    if type(K_neigs) == int:
        K_neigs = [K_neigs]
    dis_mat = Eu_dis(X)
    H = []
    for k_neig in K_neigs:
        H_tmp = construct_H_with_KNN_from_distance(dis_mat, k_neig, is_probH, m_prob)
        if not split_diff_scale:
            H = hyperedge_concat(H, H_tmp)
        else:
            H.append(H_tmp)
    return H
H = construct_H_with_KNN(x)
#生成G
def generate_G_from_H(H, variable_weight=False):
    """
    calculate G from hypgraph incidence matrix H
    :param H: hypergraph incidence matrix H
    :param variable_weight: whether the weight of hyperedge is variable
    :return: G
    """
    if type(H) != list:
        return _generate_G_from_H(H, variable_weight)
    else:
        G = []
        for sub_H in H:
            G.append(generate_G_from_H(sub_H, variable_weight))
        return G
def _generate_G_from_H(H, variable_weight=False):
    """
    calculate G from hypgraph incidence matrix H
    :param H: hypergraph incidence matrix H
    :param variable_weight: whether the weight of hyperedge is variable
    :return: G
    """
    H = np.array(H)
    n_edge = H.shape[1]
    # the weight of the hyperedge
    W = np.ones(n_edge)
    # the degree of the node
    DV = np.sum(H * W, axis=1)
    # the degree of the hyperedge
    DE = np.sum(H, axis=0)
    invDE = np.mat(np.diag(np.power(DE, -1)))
    DV2 = np.mat(np.diag(np.power(DV, -0.5)))
    W = np.mat(np.diag(W))
    H = np.mat(H)
    HT = H.T
    if variable_weight:
        DV2_H = DV2 * H
        invDE_HT_DV2 = invDE * HT * DV2
        return DV2_H, W, invDE_HT_DV2
    else:
        G = DV2 * H * W * invDE * HT * DV2
        return G
G = generate_G_from_H(H)

實驗結果:

H

G

到此這篇關于如何建立一個超圖的文章就介紹到這了,希望對你有幫助,更多相關超圖內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章,希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • python opencv圖像處理(素描、懷舊、光照、流年、濾鏡 原理及實現)
  • Python+OpenCV圖像處理——實現輪廓發現
  • 解決python圖像處理圖像賦值后變為白色的問題
  • 基于python的opencv圖像處理實現對斑馬線的檢測示例

標簽:股票 駐馬店 中山 畢節 湖州 衡水 江蘇 呼和浩特

巨人網絡通訊聲明:本文標題《如何建立一個超圖詳解》,本文關鍵詞  如何,建立,一個,超圖,詳解,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《如何建立一個超圖詳解》相關的同類信息!
  • 本頁收集關于如何建立一個超圖詳解的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 亚洲 欧美 叧类人妖| 青久久| 麻豆成人久久精品一区二区三区| 人善交video另类hd欧| 综合福利网站| 王雪把双腿打开给老赵| 高潮vpswindows国产乱| 《隔壁的日本妻子》HD| 中文字幕久久综合伊人| 隔壁的女孩在线| 榴莲视频深夜释放自己| 欧美AAAAAA一片色情A片| 乌克兰少妇性做爰| 久久久久久精品免费免费wei | 国产美女精品在线观看| 色www精品视频在线观看| 国产做a爱片久久毛片A片漫画| 《边做饭边躁》无删减| 杨幂被艹视频| 大bbwbbwbbwbwvideos视频| 宝贝你又软又湿h| 大学情侣露脸国产在线一区| 伊大人香蕉久久网| 你把我的批日出水了| 范冰冰特黄xx大片| 国产学生无套内精在线观看| 国产午夜AAA片无码无片久久| 就色干综合| 蜜桃成熟33| 午夜精品视频在线观看| 女人做爰的全部视频播放| 天天爽夜夜春| 亚洲欧美日韩在线一区二区三区| 91福利国产| 最新国产露脸在线观看| AA片免费网站| 情趣内衣在线观看| 公愆憩止痒玉米地| 高辣h浪荡小说肥臀艳妇短篇| 《交换:完美的邻居》3| 国产19禁网站免费观看|