Norms#
Norms and likelihood functions for comparing observed and modeled values with
Inference.
- class LNorm(p: int)[source]#
Bases:
NormClass for L-norms.
- __init__(p: int)[source]#
Initialize the class with the provided parameters.
- Parameters:
p (
int) – The order of the norm. seenumpy.linalg.norm()for details.
-
p:
int# The order of the norm.
- class L2Norm[source]#
Bases:
LNormClass for L2-norm (Euclidean distance).
- compute(a: float | ndarray, b: float | ndarray)#
Compare two values.
- Parameters:
a (
float|ndarray) – A value.b (
float|ndarray) – Another value.
- Return type:
float|int- Returns:
A numerical value representing the difference between the two values.
-
p:
int# The order of the norm.
- class L1Norm[source]#
Bases:
LNormClass for L1-norm (Manhattan distance).
- compute(a: float | ndarray, b: float | ndarray)#
Compare two values.
- Parameters:
a (
float|ndarray) – A value.b (
float|ndarray) – Another value.
- Return type:
float|int- Returns:
A numerical value representing the difference between the two values.
-
p:
int# The order of the norm.
- class LInfNorm[source]#
Bases:
LNormClass for L-infinity norm (Chebyshev distance).
- compute(a: float | ndarray, b: float | ndarray)#
Compare two values.
- Parameters:
a (
float|ndarray) – A value.b (
float|ndarray) – Another value.
- Return type:
float|int- Returns:
A numerical value representing the difference between the two values.
-
p:
int# The order of the norm.
- class Likelihood[source]#
Bases:
Norm,ABCAbstract class for likelihoods.
- compute(a: Any, b: Any)#
Compare two values.
- Parameters:
a (
Any) – A value.b (
Any) – Another value.
- Return type:
float|int- Returns:
A numerical value representing the difference between the two values.
- class PoissonLikelihood[source]#
Bases:
LikelihoodClass for Poisson likelihoods. Site frequency spectra are often assumed to be independent Poisson random variables.
- compute(observed: Iterable | float, modelled: Iterable | float)[source]#
Return additive inverse of Poisson log-likelihood assuming independent entries. Note that the returned likelihood is a positive value which ought to be minimized.
- Parameters:
observed (
Union[Iterable,float]) – Observed value or values.modelled (
Union[Iterable,float]) – Modelled value or values.
- Return type:
float|int- Returns:
A numerical value representing the difference between the two values.
- class MultinomialLikelihood[source]#
Bases:
LikelihoodClass for Multinomial likelihoods. Used when modeling observed counts distributed across categories, given expected probabilities.
The modelled values are normalized to form a valid probability distribution (i.e., they sum to 1).
- compute(observed: Iterable, modelled: Iterable)[source]#
Return the additive inverse of the Multinomial log-likelihood. The result is a positive value that should be minimized.
- Parameters:
observed (
Iterable) – Observed counts per category.modelled (
Iterable) – Modelled values (will be normalized to probabilities).
- Return type:
float- Returns:
Negative log-likelihood as a float.