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

Remove default seed from runNMF #219

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

jashapiro
Copy link
Contributor

When working with the calculateNMF() function (with the release version of scater), I realized that the default arguments result in resetting the system seed, which seems like undesired behavior, both because it means that repeated runs do not vary as would be expected (and as the docs seem to indicate).

For example:

sce <- mockSCE() |> logNormCounts()

set.seed(100)
nmf1 <- calculateNMF(sce)
runif(1)
#> [1] 0.5308088
nmf2 <- calculateNMF(sce)
runif(1)
#> [1] 0.5308088
all(nmf1==nmf2)
#> [1] TRUE

Setting the default seed as NULL seems to correctly alleviate the issue (and this is the default seed value for the underlying RccpML::nmf()):

set.seed(100)
nmf1 <- calculateNMF(sce, seed = NULL)
runif(1)
#> [1] 0.0740483

# second run is different and not in the same RNG position
nmf2 <- calculateNMF(sce, seed = NULL)
runif(1)
#> [1] 0.7676133
all(nmf1==nmf2)
#> [1] FALSE

# resetting the seed does result in identical values, as expected
set.seed(100)
nmf3 <- calculateNMF(sce, seed = NULL)
runif(1)
#> [1] 0.0740483
all(nmf1==nmf3)
#> [1] TRUE

Created on 2025-02-28 with reprex v2.1.1

Since the pattern from other similar functions like calculateUMAP() is to not include seed as a default argument, the simplest solution seemed to me to be to simply remove the argument, allowing the default value for RcppML::nmf() to be used. That is what I have done here.

I also fixed a small error in the docs which referred to passing additional arguments to Rtsne.

If you would like to pursue a different solution (or leave it as is), please let me know.

Update docs and fix a docs error
@alanocallaghan
Copy link
Owner

Looks sensible, I have no idea why I exposed the seed argument in particular

@alanocallaghan alanocallaghan merged commit 0e0f18d into alanocallaghan:devel Mar 3, 2025
1 check passed
@alanocallaghan
Copy link
Owner

Thanks for this!

@LTLA
Copy link
Collaborator

LTLA commented Mar 3, 2025

Looks sensible, I have no idea why I exposed the seed argument in particular

Might have been me. But I too have no idea why that was done.

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.

3 participants