Git Product home page Git Product logo

Comments (10)

registerrier avatar registerrier commented on September 26, 2024 1

Thanks @moralejo . I remember that this changed at some point to be consistent (see e.g. #1936).
Let's put this on the list for the next release.

from gammapy.

moralejo avatar moralejo commented on September 26, 2024

Hi,

the code is correct, but it returns the Poisson parameter of the background in the OFF region

Whereas the same formula in the documentation:
https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html

is used to obtain the Poisson parameter of the background in the ON region - that is what mu_bkg means in the documentation. So probably only the docs are wrong.

Here:

mu_bkg = self.alpha.data * get_wstat_mu_bkg(
n_on=self.counts.data,
n_off=self.counts_off.data,
alpha=self.alpha.data,
mu_sig=self.npred_signal().data,
)

the return of the function (for the whole OFF region) is scaled by alpha, to get the value for the ON region, so it seems correct.
It would anyway be worth that an expert checks it. I also think it would be better to use, for the background Poisson parameters, variable names which make it clear straightaway whether they refer to the ON region or to the OFF region.

from gammapy.

adonath avatar adonath commented on September 26, 2024

Thanks @moralejo! Which modifications would you propose to https://docs.gammapy.org/1.1/user-guide/stats/index.html#notations, to make the description more clear?

from gammapy.

moralejo avatar moralejo commented on September 26, 2024

Thanks @moralejo! Which modifications would you propose to https://docs.gammapy.org/1.1/user-guide/stats/index.html#notations, to make the description more clear?

Hi,

I would say

"mu_bkg: predicted background counts in the ON region" ( this is what it means here, since below we have mu_off = mu_bkg / alpha)

Then, for consistency, the function get_wstat_mu_bkg should either be called get_wstat_mu_off , or be modified to return mu_bkg (and the code using the function should be changed as well).

In the current documentation https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html (not sure if everywhere else) mu_bkg has the same meaning as in the glossary - ok!
But then the formulae here:
https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html#profile-likelihood
need fixing (they were taken from a reference in which mu_bkg meant what in gammapy is called mu_noff). These would be the changes (crosscheck is welcome):

$\frac{\alpha,n_{\mathrm{on}}}{\mu_{\mathrm{sig}}+\alpha\mu_{\mathrm{bkg}}} + \frac{n_{\mathrm{off}}}{\mu_{\mathrm{bkg}}} - (\alpha+ 1) = 0 \longrightarrow \frac{\alpha \; n_{\mathrm{on}}}{\mu_{\mathrm{sig}}+\alpha\mu_{\mathrm{bkg}}} + \frac{\alpha \; n_{\mathrm{off}}}{\mu_{\mathrm{bkg}}} - (\alpha+ 1) = 0$

$\mu_{\mathrm{bkg}} = \frac{C + D}{2\alpha(\alpha + 1)} \longrightarrow \mu_{\mathrm{bkg}} = \frac{C + D}{2(\alpha + 1)}$
One can add $\mu_{bkg} = \alpha \mu_{off}$ for clarity, since in the code we will have: mu_bkg = alpha * get_wstat_mu_off(...)

from gammapy.

moralejo avatar moralejo commented on September 26, 2024

I think here:
https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html#special-cases

mu_bkg is used wrongly... it definitely should be mu_off in the likelihood formula.

Not sure if in the following lines it has consistently the same (wrong) meaning, I have to check it... Done, see below.

from gammapy.

moralejo avatar moralejo commented on September 26, 2024

There are also problems here:
https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html#goodness-of-fit

image

The Likelihood function is the same as before, with arguments:
image

So the correct arguments to get the absolute maximum likelihood are:
$L(n_{on}, n_{off}, \alpha, (n_{on} - \alpha \; n_{off}), \alpha \; n_{off})$

(and the same in the two formulae afterwards)

from gammapy.

moralejo avatar moralejo commented on September 26, 2024

In https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html#derivation-of-the-wstat-formula
image

Where it says "mu_src" it should be "mu_sig"

from gammapy.

moralejo avatar moralejo commented on September 26, 2024

https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html#final-result
image

https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html#special-cases
image

In the two formulae above, mu_bkg should become mu_bkg / alpha (or, equivalently, mu_off)

image
Should be: $L(0, n_{off}, \alpha, (0 - \alpha \; n_{off}), \alpha \; n_{off}) = ...$ (maximum absolute L in case n_on=0) The right side is correct.

from gammapy.

moralejo avatar moralejo commented on September 26, 2024

Last part...
Under https://docs.gammapy.org/1.1/user-guide/stats/wstat_derivation.html#special-cases:

image

Again, mu_bkg must be replaced above by mu_bkg / alpha

And
image

should become mu_bkg = [alpha / (alpha+1)] * n_off

image
(mu_bkg / alpha should replace mu_bkg above)

And the next one:
image

should rather be [alpha / (1+alpha)] n_on - mu_sig

After that, I think the rest is ok (the values of W)

from gammapy.

moralejo avatar moralejo commented on September 26, 2024

All that is just to make the doc page consistent with the meaning of mu_bkg in the glossary.

About the code: I saw no misuse of get_wstat_mu_bkg (the returned value is multiplied by alpha to get the actual mu_bkg). But I did not check anything else... it would be good if some expert can make sure that the computation of the goodness of fit is correct.

from gammapy.

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.