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 (sim… #1574

Closed
wants to merge 4 commits into from

Conversation

maelle
Copy link
Contributor

@maelle maelle commented Nov 7, 2024

…pler default for the R interface)

Fix #1570

Work needed in the tests.

Copy link
Contributor

aviator-app bot commented Nov 7, 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 PR is currently in state closed (PR closed manually).


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 maelle force-pushed the cut.prob branch 2 times, most recently from 5b76237 to b0d4610 Compare November 7, 2024 09:15
@maelle
Copy link
Contributor Author

maelle commented Nov 7, 2024

mmh this does not work at all currently.

@maelle
Copy link
Contributor Author

maelle commented Nov 7, 2024

@szhorvat actually, I think things are fine. What do you think of the tests

test_that("motif finding works", {
?

They're failing for small differences. Furthermore they do not make any sense to me, why are we testing for the value of the divisions?

── Failure ('test-motifs.R:11:3'): motif finding works ─────────────────────────
c(mno0/mno, mno1/mno, mno2/mno) (`actual`) not equal to c(0.654821903845065, 0.666289144345659, 0.668393831285275) (`expected`).

  `actual`: 0.67454 0.66614 0.66597
`expected`: 0.65482 0.66629 0.66839

@szhorvat
Copy link
Member

szhorvat commented Nov 7, 2024

I'm really tired today ... could you please help me by showing me a specific before/after example that changes output? Passing c(0,0,0) vs NULL should NOT change anything.

But as I'm writing this, I think I'm starting to remember what's going on:

I think passing NULL instead of c(0,0,0) vs will cause some (unnecessary) RNG calls to be omitted. This means that later calls that use different values than c(0,0,0), and therefore return stochastic results, should indeed be affected. And yes, this is not a bug, don't worry.

It'll be cleanest for each test to use its own random seed.

@szhorvat
Copy link
Member

szhorvat commented Nov 7, 2024

Yes, this is certainly what's going on. If you pass NULL or c(0,0,0,...), the result will be the exactly same. But the RNG state will be mutated differently, which means that any subsequent uses of the RNG are affected.

The results are approximately the same and everything is fine.

Adding a tolerance won't work very well here because the noise in the results is still quite high and will continue to be high unless we use large enough graphs and small enough cut probabilities that the computation time becomes too long for a test.

@szhorvat
Copy link
Member

szhorvat commented Nov 7, 2024

Furthermore they do not make any sense to me, why are we testing for the value of the divisions?

The interface is not very nice, unfortunately, but improvements are for a later version and for the C core.

If we give cut probabilities $p_1, p_2, \dots$, then only a fraction of the motifs will be sampled. This fraction is $\prod_i (1-p_i)$. This is the value you should see in the ratio of the counts obtained with a non-zero cut probability and the full counts (with no cuts). Since some motifs are rare, some entries in the result vector will fluctuate wildly.

So, if you give c(1/3, 0, 0), then the ratios should all be about $1-1/3 \approx 0.66$.

R/motifs.R Outdated Show resolved Hide resolved
@szhorvat
Copy link
Member

When you resolve conflicts, be sure that you don't accidentally re-add as.numeric to sample.

@maelle
Copy link
Contributor Author

maelle commented Nov 28, 2024

I'll make a new PR, thank you!!

R/motifs.R Outdated Show resolved Hide resolved
@maelle
Copy link
Contributor Author

maelle commented Feb 19, 2025

@szhorvat would you mind re-reviewing? thank you!

@maelle
Copy link
Contributor Author

maelle commented Feb 19, 2025

Errors in tests

══ Failed tests ════════════════════════════════════════════════════════════════
── Failure ('test-motifs.R:11:3'): motif finding works ─────────────────────────
c(mno0/mno, mno1/mno, mno2/mno) (`actual`) not equal to c(0.654821903845065, 0.666289144345659, 0.668393831285275) (`expected`).

  `actual`: 0.67454 0.66614 0.66597
`expected`: 0.65482 0.66629 0.66839
── Failure ('test-motifs.R:19:3'): motif finding works ─────────────────────────
c(mno3/mno, mno4/mno, mno5/mno) (`actual`) not equal to c(0.443959957465819, 0.441952797125797, 0.446004870037941) (`expected`).

  `actual`: 0.4417 0.4456 0.4405
`expected`: 0.4440 0.4420 0.4460
── Failure ('test-motifs.R:34:3'): motif finding works ─────────────────────────
m0/m (`actual`) not equal to c(...) (`expected`).

  `actual[1:15]`: NA NA 0.672 NA 0.675 0.633 0.676 0.699 NaN 0.785 and 5 more...
`expected[1:15]`: NA NA 0.654 NA 0.654 0.612 0.658 0.630 NaN 0.538           ...
── Failure ('test-motifs.R:35:3'): motif finding works ─────────────────────────
m1/m (`actual`) not equal to c(...) (`expected`).

     actual | expected               
 [1] NA     | NA       [1]           
 [2] NA     | NA       [2]           
 [3] 0.6665 - 0.6696   [3]           
 [4] NA     | NA       [4]           
 [5] 0.6663 - 0.6681   [5]           
 [6] 0.6327 - 0.7347   [6]           
 [7] 0.6685 - 0.6708   [7]           
 [8] 0.6712 - 0.6575   [8]           
 [9] NaN    | NaN      [9]           
[10] 0.6000 - 0.7692   [10]          
 ... ...      ...      and 5 more ...
── Failure ('test-motifs.R:36:3'): motif finding works ─────────────────────────
m2/m (`actual`) not equal to c(...) (`expected`).

     actual  | expected               
 [1] NA      | NA       [1]           
 [2] NA      | NA       [2]           
 [3] 0.66327 - 0.66645  [3]           
 [4] NA      | NA       [4]           
 [5] 0.66744 - 0.66529  [5]           
 [6] 0.65306 - 0.59184  [6]           
 [7] 0.66628 - 0.66668  [7]           
 [8] 0.65753 - 0.67123  [8]           
 [9] NaN     | NaN      [9]           
[10] 0.66154 - 0.75385  [10]          
 ... ...       ...      and 5 more ...
── Failure ('test-motifs.R:41:3'): motif finding works ─────────────────────────
m3/m (`actual`) not equal to c(...) (`expected`).

     actual  | expected               
 [1] NA      | NA       [1]           
 [2] NA      | NA       [2]           
 [3] 0.43906 - 0.44561  [3]           
 [4] NA      | NA       [4]           
 [5] 0.44174 - 0.44279  [5]           
 [6] 0.40816 - 0.44898  [6]           
 [7] 0.44432 - 0.44470  [7]           
 [8] 0.43836 - 0.42466  [8]           
 [9] NaN     | NaN      [9]           
[10] 0.41538 - 0.36923  [10]          
 ... ...       ...      and 5 more ...
── Failure ('test-motifs.R:43:3'): motif finding works ─────────────────────────
m4/m (`actual`) not equal to c(...) (`expected`).

     actual  | expected               
 [1] NA      | NA       [1]           
 [2] NA      | NA       [2]           
 [3] 0.43977 - 0.43925  [3]           
 [4] NA      | NA       [4]           
 [5] 0.44104 - 0.43928  [5]           
 [6] 0.22449 - 0.73469  [6]           
 [7] 0.43875 - 0.44509  [7]           
 [8] 0.53425 - 0.46575  [8]           
 [9] NaN     | NaN      [9]           
[10] 0.43077 - 0.63077  [10]          
 ... ...       ...      and 5 more ...
── Failure ('test-motifs.R:45:3'): motif finding works ─────────────────────────
m5/m (`actual`) not equal to c(...) (`expected`).

     actual      | expected                  
 [1] NA          | NA          [1]           
 [2] NA          | NA          [2]           
 [3] 0.444436015 - 0.439985333 [3]           
 [4] NA          | NA          [4]           
 [5] 0.445736750 - 0.440288167 [5]           
 [6] 0.489795918 - 0.346938776 [6]           
 [7] 0.445353602 - 0.441597531 [7]           
 [8] 0.575342466 - 0.452054795 [8]           
 [9] NaN         | NaN         [9]           
[10] 0.415384615 - 0.323076923 [10]          
 ... ...           ...         and 3 more ...
── Error ('test-motifs.R:54:3'): sample_motifs works ───────────────────────────
Error in `sample_motifs(g)`: At vendor/cigraph/src/misc/motifs.c:604 : The number of vertices to use as a sample for motif count estimation must be at least one, got 0. Invalid value
Backtrace:1. └─igraph::sample_motifs(g) at test-motifs.R:54:3

[ FAIL 9 | WARN 0 | SKIP 5 | PASS 5059 ]
Error: Test failures
Execution halted

@maelle
Copy link
Contributor Author

maelle commented Feb 19, 2025

there's a second PR which I had forgotten

@maelle maelle closed this Feb 19, 2025
@szhorvat
Copy link
Member

@szhorvat would you mind re-reviewing? thank you!

there's a second PR which I had forgotten

I assume you don't need a re-review on the 2nd PR. If you still need one, please ping me there.

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

Successfully merging this pull request may close these issues.

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