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

Feature request: layouts for weighted graphs #63

Open
vandenman opened this issue Jan 18, 2024 · 1 comment
Open

Feature request: layouts for weighted graphs #63

vandenman opened this issue Jan 18, 2024 · 1 comment

Comments

@vandenman
Copy link

If one has a weighted graph, would it make sense for the layout algorithm to account for the weights?

This is done in, for instance, the R package qgraph.

Perhaps I'm viewing this too simplistically, but I think that all that needs to be done is multiply by the weights at some point. For example, in the Spring layout, there is now

if adj_matrix[i, j] != zero(eltype(adj_matrix)) || adj_matrix[j, i] != zero(eltype(adj_matrix))
# F = d^2 / K - K^2 / d
F_d = d / K - K^2 / d^2
else
# Just repulsive
# F = -K^2 / d^
F_d = -K^2 / d^2
end

where, if I understand the code correctly, this line F_d = d / K - K^2 / d^2 could be changed to account for the weight of the edge. One option is to simply weigh the attraction by the (normalized) edge strength, which is I think what qgraph does (see https://github.com/cran/qgraph/blob/57d588ee05a554f9d1078914e05ce03662c610b2/src/layout_rcpp.cpp#L111).

Any thoughts? I'd be happy to open a draft PR for a single layout (e.g., spring).

@hexaeder
Copy link
Collaborator

Sounds reasonable! I think what you say is exactly right, you probably only need to add edgewights and nodeweights to the struct field and to the constructor, normalize and weight the forced accordingly. PRs welcome!

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