Description of the class `Poisson`, and its helper `PoissonFitter`, which are used to parameterize log likelihood curves.

Author(s): Eric Wallace, Matthew Kerr, Toby Burnett

class Poisson[source]

Poisson(p:array of parameters)

This is a functor class which returns the log of a three-parameter Poisson-like function used to represent the flux likelihood. The parameters are, in order:

$s_p$ : flux at peak, the maximum likelihood, if positive; if negative, there is a limit

$e$ : normalization factor to convert flux to equivalent counts. must be >0

$b$ : background flux: must be >=0

This parameterization is equivalent to that described in William Tompkins' thesis (arxiv: astro-ph/0202141) and Nolan, et al., 2003, ApJ 597:615:627. The functional form is that of a Poisson distribution.

The log likelihood expression is for flux $s>=0$ $$w(s | s_p,e,b) = e\ \big[\ (s_p+b) \ \log( s+b ) - s\ \big] + \mathrm{const}$$ the const is conventionally defined such that $w=0$ at the peak.

for s_p >> b, the solution can be expressed as

$$ s = s_p \pm \sqrt{(s_p+b)/e}$$

A slightly more elegant expression, used in the cdf function, is to define $\beta = e b$, $\mu = e s_p + \beta$, and $x = e s$.

Then the log likelihood is

$$ f(x | \beta) = \mu \ \log( x + \beta) - x + \mathrm{const}$$

where the peak is at $x=x_p=\max(0, \mu-\beta)$, and the constant is defined so that $f(x_p)=0$.

Poisson.from_fit[source]

Poisson.from_fit(counts, flux, sig_flux, tol=5)

Create a Poisson instance using the fit parameters from an analysis of a likelihood function.

  • counts -- number of weights
  • flux -- peak value, in flux units
  • sig_flux -- its standard deviation, square root of the variance

This is relevant if the likelihood is not truncated by the Bayes requirement.

If $s$ and $v$ are the signal rate and its variance, determined by an optimization for $n$ measurements, so $s$ is large compared with $\sqrt{v}$, then the poisson-like parameters can be determined as follows.

We use the properties of the Poisson distribution $f(n;\lambda) = \exp(n \log\lambda - \lambda + \mathrm{const})$, where the parameter $\lambda$ is equal to the expected value of number of occurrences $n$ and to its variance, and that the function we want is shifted by the background $b$ and scaled by a factor $k$ so we use $f(k(s-b)| \lambda)$. This implies that for the expected value of $s$, $\lambda = n$, and $ k(s-b)= k^2 v = n$.

t = Poisson.from_fit(10000, 2, 0.02 )
assert str(t)=='2.000[1+0.010-0.010]', f'Fail: got {str(t)}'

Poisson.__call__[source]

Poisson.__call__(dom)

Return the value(s) of the fit function for the given domain.

Examples

Here we generate and plot several instances, all with the $e$ parameter set to one, so the flux is in counts.

The peak ($s_p$) and background ($b$) parameters are chosen from the following list:

[(10, 5), (10, 0), (-5, 5), (-5, 1), (0, 5)]

The first two, with the peak at 10, show the effect of background. The last two show an example with a peak less than zero, so that the Bayesian likelihood peaks at zero, and the effect of background on it.

Figure 1
Figure 1. Poisson-like plots

class PoissonFitter[source]

PoissonFitter(func, fmax=None, scale=None, tol=0.2, delta=0.0001, dd=-0.1, test_mode=False)

Helper class to fit a log likelihood function to the Poisson

parameters

  • func : function of one parameter
  • fmax : position of maximum value, or None
     if None, estimate using fmin
  • scale: float | None estimate for scale to use; if None, estimate from derivatime
  • tol : float absolute tolerance in probability amplitude for fit, within default domain out to delta L of 4
  • delta : float value to calculate numerical derivative at zero flux

Tests

Study tail when a limit

Check high statistics, no background