Coder Social home page Coder Social logo

dhod's Introduction

dhod's People

Contributors

eiffl avatar bhorowitz avatar allcontributors[bot] avatar changhoonhahn avatar modichirag avatar gitter-badger avatar

Stargazers

Yucheng Zhang avatar  avatar Alex Malz avatar  avatar Minas Karamanis avatar Song Huang avatar Nesar Ramachandra avatar  avatar

Watchers

James Cloos avatar  avatar  avatar  avatar Jamie Sullivan avatar

dhod's Issues

RelaxedBernoulli samples not differentiable

samples from tensorflow_probability.distributions.RelaxedBernoulli is not differentiable even when temperature is increased to 10^6. The gradients from the snippets below spits out nans.

Mhalo = tf.convert_to_tensor(np.random.uniform(10., 15., 1000), dtype=tf.float32)
siglogm = tf.convert_to_tensor(0.2, dtype=tf.float32)
temperature = 100

def Ncen(Mmin): 
    # mean occupation of centrals
    return 0.5 * (1+tf.math.erf((Mhalo - Mmin)/siglogm))

for temp in np.linspace(0.1, 1e6, 10).astype(np.float32): 
    def _hod(Mmin): 
        bern = tfp.distributions.RelaxedBernoulli(temp, probs=Ncen(Mmin))
        return bern.sample(seed=0)

    loss = lambda mm: _hod(mm)
    val, grad = tfp.math.value_and_gradient(loss, [_Mmin])
    print(grad)

Why not sampling all the things? HMC sampling of each individual galaxy activation

I'm not really convinced we are doing the right thing by using an HMC over the stochastically sampled power spectrum. The only correct way to do this would be to draw several power spectra, and then use the mean, i.e. using an estimator of the theoretical mean over N samples, and most likely N should be larger than 1. This is essentially the same age old problem of you can't sample cosmological parameters without sampling all of the latent variables as well.

So... why don't we bite the bullet and just sample all of the latent variables of the model, i.e. the "activation" (whether the galaxy is on or off) of every single galaxy in the mock, at the same time as we sample the HOD parameters. Turns out, that this has little extra cost compared to what we were doing before, because the computations of forward and backward pass are strictly the same, the only potential cost is storage of latent variables in th MCMC trace, but we can circumvent that.

Here is a proof of concept sampling only the centrals:
https://colab.research.google.com/drive/1jsYwqxvw05LmG6jmYzHa13t1kjhH8q0F?usp=sharing
And it works nicely:
image

The super nice thing about this approach is that I think you might not need a covariance matrix! only diagonal measurement errors on your power spectrum. Because we track all the latent variables.

Anyways, this looks tractable to me, curious to hear what other people think.

Remove heavy TF model from git history

@modichirag The folder models is too heavy to be stored directly on git, it makes downloading the project way too slow. I'm going to go ahead and erase it from history, we can always add this back as a git-lfs folder afterwards

New versions of TFP cause NaN gradients for RelaxedBernoulli near p=0 and p=1

I couldn't reproduce one of the figures of the paper (from this notebook: https://github.com/DifferentiableUniverseInitiative/DHOD/blob/master/nb/Zheng2007_demo.ipynb), specifically the figure comparing gradients.

Turns out, it's due to the RelaxedBernoulli being quite sensitive near 0 and 1 in newer versions of TFP, I'm trying to pin down exactly what changed, but checked that with previous versions (0.9) we can get nice gradients even close to the edges: https://colab.research.google.com/drive/1xkXYtC3ER1z0r25fkUa2pwV_b7OlQBnP?usp=sharing

Make all sampling functions batch capable

For now, the sampling functions from HOD components are not batch capable. we should change that so that we can sample several batches at once, for VI purposes ;-)

Compute a CIC density field from galaxy catalog

This issue to add a functionality to compute a 3d CIC mesh from a galaxy catalog, from which we can then try to compute the power spectrum.
@modichirag Do you want to take care of that? Essentially, this would involve using FlowPM to CIC paint a galaxy density field from a galaxy catalog

Implement and sample from Zheng2007

This issue is tracking the definition of a tensor-based structure for a halo catalog.

Halotools relies on astropy tables, here we can't use that, most likely a dictionary of tensors will be just as good.

Implementation of NFW radial distribution

Many thanks to @aphearin who pointed us to this reference:

This issue is to track comments during the implementation of this distribution.

I've started implementing it as a proper TensorFlow Probability distribution in u/EiffL/NFW. The good news is that approximately a month ago, the Lambert W function got added to TensorFlow Probability so we got most of the work cut out for us :-D : https://github.com/tensorflow/probability/blob/d3dc1d657bc2386a86c69c445a8ae087e212cd05/tensorflow_probability/python/math/special.py#L141

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.