Skip to content

fix: local (weighted) transitivity now produces a named vector#1057

Merged
aviator-app[bot] merged 2 commits intomainfrom
fix/transitivity-names
Jan 1, 2024
Merged

fix: local (weighted) transitivity now produces a named vector#1057
aviator-app[bot] merged 2 commits intomainfrom
fix/transitivity-names

Conversation

@szhorvat
Copy link
Copy Markdown
Member

Fixes #943. This was also a learning exercise for me after your VERTEX_QTY question, @krlmlr.

@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app Bot commented Dec 30, 2023

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged using Aviator.


See the real-time status of this PR on the Aviator webapp.

Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Dec 30, 2023

Thanks. What would it take to use autogenerated R code for transitivity()? Would that be more sustainable even in the short term?

@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Dec 30, 2023

How do we know that this does what it's supposed to, without a test?

@szhorvat
Copy link
Copy Markdown
Member Author

What would it take to use autogenerated R code for transitivity()?

This is a messy function that calls to one of several C functions. I'm not up for figuring out how to autogenerate this one right now.

But my personal preference would be to split this into three new functions, one for global clustering, one for local (weighted or unweighted), and one for average local (weighted or unweighted).

I'll add tests ...

@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Dec 30, 2023

We don't need to autogenerate all of it, just replace the .Call() with R-level calls to our own _impl() functions (after we generate wrappers for them).

@szhorvat
Copy link
Copy Markdown
Member Author

Alright, let's try that.

@szhorvat szhorvat marked this pull request as draft December 30, 2023 21:59
@szhorvat
Copy link
Copy Markdown
Member Author

To be fair, I don't know if I'd have time to do this properly. It also depends on igraph/igraph#2458 and there are issues to deal with like #1058 (comment)

I would recommend merging this as-is since it does fix a complaint. How do I know it works? I tested all four affected code paths. I can add a quick test if necessary.

@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Dec 31, 2023

A test would be great, thanks. We can merge as is, but should strive to automate as much as possible moving forward.

@szhorvat
Copy link
Copy Markdown
Member Author

szhorvat commented Dec 31, 2023

Well of course, in the longer term this, as most other functions, should be auto-generated. I just don't want to throw away this fix in case the autogen can't be implemented before Jan 12.

@szhorvat szhorvat marked this pull request as ready for review January 1, 2024 13:07
@szhorvat szhorvat requested a review from krlmlr January 1, 2024 13:07
@krlmlr krlmlr changed the title fix: local (weighted) transitivity now produces a named vector, fixes #943 fix: local (weighted) transitivity now produces a named vector Jan 1, 2024
Copy link
Copy Markdown
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

Comment on lines +36 to +46
t1 <- transitivity(g, type = "local")
t2 <- transitivity(g, type = "barrat")

vs <- c("a", "c")
t3 <- transitivity(g, type = "local", vids = vs)
t4 <- transitivity(g, type = "barrat", vids = vs)

expect_equal(names(t1), V(g)$name)
expect_equal(names(t2), V(g)$name)
expect_equal(names(t3), vs)
expect_equal(names(t4), vs)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference for

Suggested change
t1 <- transitivity(g, type = "local")
t2 <- transitivity(g, type = "barrat")
vs <- c("a", "c")
t3 <- transitivity(g, type = "local", vids = vs)
t4 <- transitivity(g, type = "barrat", vids = vs)
expect_equal(names(t1), V(g)$name)
expect_equal(names(t2), V(g)$name)
expect_equal(names(t3), vs)
expect_equal(names(t4), vs)
t1 <- transitivity(g, type = "local")
expect_equal(names(t1), V(g)$name)
t2 <- transitivity(g, type = "barrat")
expect_equal(names(t2), V(g)$name)
vs <- c("a", "c")
t3 <- transitivity(g, type = "local", vids = vs)
expect_equal(names(t3), vs)
t4 <- transitivity(g, type = "barrat", vids = vs)
expect_equal(names(t4), vs)

because this keeps input and output closer together. No need to act here.

@aviator-app aviator-app Bot force-pushed the fix/transitivity-names branch from 963ab6b to ba73fc7 Compare January 1, 2024 13:48
@aviator-app aviator-app Bot merged commit 92965af into main Jan 1, 2024
@aviator-app aviator-app Bot deleted the fix/transitivity-names branch January 1, 2024 14:18
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get the name of the vertex in the igraph::transitivity(graph, type = "local") function in R

2 participants