Giter VIP home page Giter VIP logo

Comments (13)

aphearin avatar aphearin commented on July 19, 2024 1

ahh, ok, my bad, got it.

from dhod.

aphearin avatar aphearin commented on July 19, 2024 1

Worst comes to worst, you could always use the scipy implementation to train a simple MLP surrogate.

from dhod.

EiffL avatar EiffL commented on July 19, 2024 1

Ok, so for future reference, here is the scipy implementation, they have a few fixes for several special cases, but they still admit it can fail to converge from time to time:
https://github.com/scipy/scipy/blob/master/scipy/special/lambertw.pxd
For now however, I'm happy with just limiting the number of iterations to 100, I'll make a proper PR to TFP to propose a better fix.
Can now sample without problems 10^6 radii and get perfect match compared to theory:
image

10^6 sample time:

  • numpy: 298ms
  • TF (GPU accelerated): 81.9ms

from dhod.

EiffL avatar EiffL commented on July 19, 2024

Also linked to the reference above, here is a cute python implementation:
https://github.com/CullanHowlett/NFWdist

from dhod.

EiffL avatar EiffL commented on July 19, 2024

This almost works, only one problem, the TFP implementation of the Lambert W function sometimes gets stuck in an infinite loop. I should look at the scipy implementation to figure out what the difference is, and how to avoid that loop

from dhod.

aphearin avatar aphearin commented on July 19, 2024

Hmm, I haven't noticed problems with this implementation, although I rewrote it myself so it's possible I wouldn't have. Do failures only happen for specific params?

from dhod.

EiffL avatar EiffL commented on July 19, 2024

apparently not related to specific parameters, I haven't done extensive testing, but it gets stuck pretty often when sampling like10^4 samples

from dhod.

EiffL avatar EiffL commented on July 19, 2024

and the code doesn't have a max number of iteration stopping criterion, so that doesnt seem safe ^^'

from dhod.

aphearin avatar aphearin commented on July 19, 2024

Stopping criteria? Are we talking about the rnfw function in this module? Where do stopping criteria come into this algorithm?

from dhod.

EiffL avatar EiffL commented on July 19, 2024

ahh no sorry, miscommunication I think. I'm saying the TensorFlow Probability implementation of the Lambert W function gets stuck from time to time. That function is implmented using an iterative solver, have a look here:

z0 = tf.while_loop(cond=lambda stop, *_: ~stop,

But they didn't include a max_iter or something like that, and apparently in practice it gets stuck from time to time in an infinite loop. I need to check the scipy implementation of lambertw to see how they achieve a more robust implementation.

The numpy code seems to be working great

from dhod.

EiffL avatar EiffL commented on July 19, 2024

Ok, this has been super useful @all-contributors please add @aphearin for ideas

from dhod.

allcontributors avatar allcontributors commented on July 19, 2024

@EiffL

I've put up a pull request to add @aphearin! 🎉

from dhod.

EiffL avatar EiffL commented on July 19, 2024

This has been merged to master, it now has tests that compare the results to halotools.

from dhod.

Related Issues (16)

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.