Julia 中的直接和、二元积Kronecker 积和 Hadamard 积

问题描述

目前我正在尝试在 Julia 中实现 Shapley 中介中心性算法,但我不确定如何计算直接和、二元积(Kronecker 积)和 Hadamard 积。该算法将加权图 (A) 和邻接矩阵 (A_2) 作为输入,并输出包含基于 Shapley 值的中介中心性值的向量。我附上了下面论文中描述的伪代码。到目前为止,这是我的代码:

using DataStructures
using LinearAlgebra
using SparseArrays


function ShapelyBetweennessWeighted(A,A_2)
    V = size(A,1) #number of vertices

    #Distance between nodes
    d = zeros(V,V)

    #list of predecessors on all node pairs
    Pred_s = [[] for i in 1:V]

    #Length of shortest path on each pair
    sigma = zeros(V,V)

    #One-side dependency of source node on target node
    delta = zeros(V,V)
    cSh = zeros(V)

    #Number of shortest paths from s to v with accuracy to the number of
    #vertices belonging to them in stored array
    T = zeros(V,V)

    #Sructs
    Q = PriorityQueue{Float64,Float64}()
    S = []

    
    for s in 1:V
        for v in 1:V
            Pred_s[v] = []; d[s,v] = Inf ; sigma[s,v] = 0
        end
        d[s,s] = 1; sigma[s,s] = 1;
        enqueue!(Q,s)
        while isempty(Q) == false
            for v in 1:V
                Q[v] = d[s,v] #extract v with minimal d[s,v]
            end
            v = dequeue!(Q)
            push!(S,v)
            for w in 1:V
                if A_2[v,w] == 1
                    if d[s,w] > d[s,v] + A[v,w]
                        d[s,w] = d[s,w]
                        #insert/update w → Q with d[s,w]
                        try
                            Q[w] = d[s,w]
                        catch y
                            Q[y] = d[s,w]
                        end
                        sigma[s,w] = 0; T[s,w] = 0
                        Pred_s[w] = []
                    if d[s,w] == d[s,w]
                        sigma[s,w] += sigma[s,v]
                        push!(Pred_s[w],v)
                        #T_sw = T_sw tensor product T_sv
                    end
                end
            end
        end
        for v in 1:V
            delta[s,v] = 0
        end
        while length(S) > 0
            w = pop!(S)
            for v in Pred_s[w]
                delta[s,v] += (sigma[s,v]/sigma[s,w])*(1/d[s,w] + delta[s,w])

                #tensor product 
            end
            if w != s
                cSh[w] += delta[s,w] + (2-d[s,w])/d[s,w]

                #tensor product 
            end
        end
    end
    for v in 1:V
        cSh[v] = cSh[v]/2
    end
end
    return cSh
end

我的代码中很可能存在其他错误,因此感谢有关如何实现论文中伪代码的任何帮助http://ifaamas.org/Proceedings/aamas2012/papers/1B_4.pdf。这是论文中使用的伪代码:

shapley_betweenness_centrality

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...