hawc_hal.log_likelihood.log_likelihood()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 23
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 23
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
from numba import jit
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import numpy as np
3
4
5
# This function has two signatures in numba because if there are no sources in the likelihood model,
6
# then expected_model_counts is 0.0
7
@jit(["float64(float64[:], float64[:], float64[:])", "float64(float64[:], float64[:], float64)"],
8
     nopython=True, parallel=False)
9
def log_likelihood(observed_counts, expected_bkg_counts, expected_model_counts):  # pragma: no cover
10
    """
11
    Poisson log-likelihood minus log factorial minus bias. The bias migth be needed to keep the numerical value
12
    of the likelihood small enough so that there aren't numerical problems when computing differences between two
13
    likelihood values.
14
15
    :param observed_counts:
16
    :param expected_bkg_counts:
17
    :param expected_model_counts:
18
    :param bias:
19
    :return:
20
    """
21
22
    predicted_counts = expected_bkg_counts + expected_model_counts
23
24
    # Remember: because of how the DataAnalysisBin in map_tree.py initializes the maps,
25
    # observed_counts > 0 everywhere
26
27
    log_likes = observed_counts * np.log(predicted_counts) - predicted_counts
28
29
    return np.sum(log_likes)
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...