Norms#

Norms and likelihoods for comparing two values.

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.