Norms#

Norms and likelihood functions for comparing observed and modeled values with Inference.

class Norm[source]#

Bases: ABC

Abstract class for norms.

compute(a: Any, b: Any)[source]#

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 LNorm(p: int)[source]#

Bases: Norm

Class for L-norms.

__init__(p: int)[source]#

Initialize the class with the provided parameters.

Parameters:

p (int) – The order of the norm. see numpy.linalg.norm() for details.

p: int#

The order of the norm.

compute(a: float | ndarray, b: float | ndarray)[source]#

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.

class L2Norm[source]#

Bases: LNorm

Class for L2-norm (Euclidean distance).

__init__()[source]#

Initialize the class.

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: LNorm

Class for L1-norm (Manhattan distance).

__init__()[source]#

Initialize the class.

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: LNorm

Class for L-infinity norm (Chebyshev distance).

__init__()[source]#

Initialize the class.

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, ABC

Abstract 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: Likelihood

Class 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: Likelihood

Class 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.