NetworkInference.jl
NetworkInference.jl copied to clipboard
How to get the weight matrix?
Hello!
I'm not very familiar with Julia, and I wonder after I get the inferred_network object, instead of obtaining the adjacency matrix with different thresholds, is there a way to get the full weight matrix between nodes?
Any suggestions?
Hi, thanks for the question. There's not currently a way to do that via the library, but it's a good idea for a feature request, so lets keep this issue open.
In the meantime, you could do something like the following, modified from get_adjacency_matrix:
number_of_nodes = length(inferred_network.nodes)
weight_matrix = zeros(number_of_nodes, number_of_nodes)
labels_to_ids = Dict{String,Int}()
ids_to_labels = Dict{Int,String}()
i = 1
for (i, node) in enumerate(inferred_network.nodes)
labels_to_ids[node.label] = i
ids_to_labels[i] = node.label
i += 1
end
for edge in inferred_network.edges
node1 = labels_to_ids[edge.nodes[1].label]
node2 = labels_to_ids[edge.nodes[2].label]
weight_matrix[node1, node2] = edge.weight
weight_matrix[node2, node1] = edge.weight
end
Note that this will give a symmetrical matrix with 0 along the leading diagonal.
Thank you very much. That's really helpful.