GithubHelp home page GithubHelp logo

random state about harmony HOT 3 CLOSED

immunogenomics avatar immunogenomics commented on September 14, 2024
random state

from harmony.

Comments (3)

ilyakorsunsky avatar ilyakorsunsky commented on September 14, 2024 3

Dear @wangjiawen2013,

Great suggestions!

There have been several requests for scanpy support. I have not started this; I will look into what it would take.

For reproducibility, I'm working on this feature now. In the meantime, I've found that setting the random seed in R (e.g. set.seed(1)) before running Harmony gets you 90% of the way there. This is because Harmony now initializes clusters with base R kmeans. When these initial clusters are the same, the final Harmony answer is also often consistent.

Thanks for your patience!

Best,
Ilya

from harmony.

wangjiawen2013 avatar wangjiawen2013 commented on September 14, 2024

Thanks for you powerful tool. I integrated harmony into my scanpy pipeline in a customized manner now, however, I hope you can release a version that compatible well with scanpy.

from harmony.

ilyakorsunsky avatar ilyakorsunsky commented on September 14, 2024

Dear @wangjiawen2013,

In more recent tests, I've found that set.seed() works both initialization and Harmony clustering. This code demonstrates that. When you change either one of the seeds in cluster initialization or cluster updates, the result will be slightly different.

library(harmony)
data(cell_lines_small)

with(cell_lines_small, {    
    ## seed affects cluster initialization
    set.seed(1)
    res1 <<- HarmonyMatrix(
        scaled_pcs, meta_data, 'dataset', 
        do_pca=FALSE, verbose=FALSE, return_object=TRUE, max.iter.harmony=0
    )

    ## seed affects cluster initialization
    set.seed(1)
    res2 <<- HarmonyMatrix(
        scaled_pcs, meta_data, 'dataset', 
        do_pca=FALSE, verbose=FALSE, return_object=TRUE, max.iter.harmony=0
    )

})
max(abs(res1$Z_corr - res2$Z_corr))


## seed affects harmony updates in `update_R()`
set.seed(1)
.x <- harmony:::harmonize(res1, 10, FALSE)

## seed affects harmony updates in `update_R()`
set.seed(1)
.x <- harmony:::harmonize(res2, 10, FALSE)

max(abs(res1$Z_corr - res2$Z_corr))

Best,
Ilya

from harmony.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.