question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set a prior that maps are physical/non-negative?

See original GitHub issue

Is your feature request related to a problem? Please describe. When fitting lightcurves to spherical harmonics in some experiments, significant fractions of the posterior maps are unphysical with minimum fluxesintensities that are negative.

Describe the solution you’d like It would be nice if there is a way to put in a prior that a map be positive. Is there a way to do this already? It looks like it could be done with pymc3 priors using Luger et al. 2018 equation 40 for ell=1 but maybe not so easily for higher orders. It looks like earlier starry versions had .is_physical() but I can’t find that in newer starry versions.

Describe alternatives you’ve considered Perhaps one can look at the samples after the fact to see if they are physical with rendering on a course grid. Or go back to earlier versions of starry that use .is_physical() in emcee with the prior function.

Additional context

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rodlugercommented, Nov 16, 2021

@eas342 Sorry for my slow reply. In recent versions of starry there’s a minimize method that returns the value of the minimum intensity across the map. You could simply check if that’s less than zero and that would reproduce the behavior of is_physical in previous versions. But that’s quite inefficient. A better way, similar to what you suggested, can sometimes be to actually sample in the pixel intensities themselves. Then you can specify a pm.Uniform prior on those pixels directly. This is likely faster and easier for NUTS to sample than the example you provided. To compute the flux, simply apply the spherical harmonic transform matrix A to vector of pixel intensities as follows:

    _, _, _, A, _, _ = map.get_pixel_transforms(oversample=2)
    npix = A.shape[1]
    p = pm.Uniform("p", lower=0.0, upper=1.0, shape=(npix,))
    y = tt.dot(A, p)

Examples of this can be found here: https://starry.readthedocs.io/en/latest/notebooks/PixelSampling/

Let me know if this helps!

1reaction
eas342commented, Nov 6, 2021

I may have found a way to do this using Potential in pymc3 with the following lines inside the model.

import pymc3 as pm

b_map = starry.Map(ydeg=self.degree)

# Add another constraint that the map should be physical
map_evaluate = b_map.render(projection='rect',res=100)
## number of points that are less than zero
num_bad = pm.math.sum(pm.math.lt(map_evaluate,0))
## check if there are any "bad" points less than zero
badmap_check = pm.math.gt(num_bad, 0)
## Set log probability to negative infinity if there are bad points. Otherwise set to 0.
switch = pm.math.switch(badmap_check,-np.inf,0)
## Assign a potential to avoid these maps
nonneg_map = pm.Potential('nonneg_map', switch)
Read more comments on GitHub >

github_iconTop Results From Across the Web

A Unifying Perron--Frobenius Theorem for Nonnegative ...
This allows us to use the theory of multihomogeneous order-preserving maps to derive a new and unifying Perron--Frobenius theorem for nonnegative tensors ...
Read more >
Non-negative data-driven mapping of structural connections ...
We present the development of the above frameworks to map structural connectivity in the neonatal brain. We first give an overview of the...
Read more >
Nonnegative Matrix Factorization with Gaussian - ProQuest
We present a general method for including prior knowledge in a nonnegative matrix factorization (NMF), based on Gaussian process priors.
Read more >
Hierarchical Bayesian approach for estimating physical ...
We present a hierarchical Bayesian model to compute age maps from images in the ... Specifically we set uniform prior distributions for all...
Read more >
A Review on Initialization Methods for Nonnegative Matrix ...
Nonnegative Matrix Factorization (NMF) has acquired a relevant role in the ... need to be randomly set up before the clustering data matrix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found