Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the weight matrix? #30

Open
Vivianstats opened this issue Oct 30, 2019 · 3 comments
Open

How to get the weight matrix? #30

Vivianstats opened this issue Oct 30, 2019 · 3 comments

Comments

@Vivianstats
Copy link

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?

@Vivianstats
Copy link
Author

Any suggestions?

@Tchanders
Copy link
Owner

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.

@Vivianstats
Copy link
Author

Thank you very much. That's really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants