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

refactor: adapt to cut.prob's new handling of NULL in the C core #1602

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maelle
Copy link
Contributor

@maelle maelle commented Nov 28, 2024

Simpler default for the R interface

Fix #1570
Fix #1574

How to handle tests?

@maelle maelle requested a review from szhorvat November 28, 2024 09:12
Copy link
Contributor

aviator-app bot commented Nov 28, 2024

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 pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue label.


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.

@maelle
Copy link
Contributor Author

maelle commented Nov 28, 2024

@szhorvat for tests, is the idea simply to

  • use a fixed random seed for each of the tests that's currently failing
  • record the results as the new truth?

@szhorvat
Copy link
Member

  • use a fixed random seed for each of the tests that's currently failing

  • record the results as the new truth?

This would make the tests more robust to changes of the sort we made. I think it's a good approach.

@maelle maelle marked this pull request as ready for review November 28, 2024 10:04
@maelle
Copy link
Contributor Author

maelle commented Nov 28, 2024

@szhorvat in that case, this is now ready for review. There were actually already fixed seeds.

@szhorvat
Copy link
Member

I'm very tired, so expect some stupid comments from me, but I'll try to do a basic review.


if (!is.null(cut.prob)) cut.prob <- as.numeric(cut.prob)

if (!is.null(cut.prob) && length(cut.prob) != size) {
Copy link
Member

Choose a reason for hiding this comment

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

Please help me understand the code below. Is it repeating the last entry to fill up the vector until it reaches size?

What if it is longer than size? That should be an error (and I think the C core will take care of that, but I'd need to check).

Copy link
Member

Choose a reason for hiding this comment

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

This just errors:

motifs(make_ring(10), cut.prob=0.1)
Error in motifs(make_ring(10), cut.prob = 0.1) : 
  At vendor/cigraph/src/misc/motifs.c:156 : Cut probability vector size (0) must agree with motif size (3). Invalid value

Why does it not trigger the length(cut.prob) != size code path?

I think I'm just too tired for this right now :(

Copy link
Member

Choose a reason for hiding this comment

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

This code path is triggered, but it produces an incorrect vector.

I know this is not your code, but can you fix it @maelle ?

My recommendation is:

  1. Either go with what this code seems to intend, i.e. repeat the last element as many times as necessary to reach size.
  2. Or keep things simple and not repeat anything except a scalar. A scalar should be treated as a vector of identical elements of length size.

No preference as to which from my size (maybe 1 is a tiny bit nicer, but also overly complicated?)

Whatever you choose, can you document it? Also, can you make sure it's implemented in all motif functions, not just this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So do you mean

  • error if cut.prob is not of length either 1 or the same as size?
  • if it is of length 1, repeat it size times?

Copy link
Member

Choose a reason for hiding this comment

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

That is option 2.

Let me give examples for option 1 and option 2, assuming size == 4.

Option 1:

Input: 0.3, interpreted as 0.3 0.3 0.3 0.3

Input: 0.3 0.4, interpreted as 0.3 0.4 0.4 0.4

Input: 0.1 0.2 0.3 0.4 0.5 (longer than size 4), should trigger an error, which can be achieved by passing to the C core as-is

So, repeat the last entry to fill to size.

Option 2:

Input: 0.3, interpreted as 0.3 0.3 0.3 0.3

Input: 0.3 0.4, passed to the C core as-is, which will trigger an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@krlmlr any opinion here?

@@ -39,7 +39,7 @@ graph.motifs.no <- function(graph, size = 3, cut.prob = rep(0, size)) { # nocov
#' @inheritParams sample_motifs
#' @keywords internal
#' @export
graph.motifs.est <- function(graph, size = 3, cut.prob = rep(0, size), sample.size = vcount(graph) / 10, sample = NULL) { # nocov start
graph.motifs.est <- function(graph, size = 3, cut.prob = NULL, sample.size = vcount(graph) / 10, sample = NULL) { # nocov start
Copy link
Member

Choose a reason for hiding this comment

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

I think sample.size should default to NULL in this deprecated function as well, to match sample_motifs.

Do what you think is best, just drawing attention to this.

@szhorvat
Copy link
Member

  • use a fixed random seed for each of the tests that's currently failing

I meant, the only way this issue could have been avoided is if a seed is set before every call to motif functions. We have the unusual situation here where an internal change did not affect the output, but it did affect how the function propagates the random state.

Actually setting the seed before every call is overkill, and I do NOT recommend it. It's good as it is IMO.

@szhorvat
Copy link
Member

szhorvat commented Nov 28, 2024

I looked at the changes in this PR and I think they're good. Thank you @maelle ! The issues I commented about are not due to your changes, but should still be fixed.

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

Successfully merging this pull request may close these issues.

Change default value cut.prob to NULL in motif finding functions
2 participants