constants Module#

Constants used throughout Episia, including statistical thresholds, default parameters, and configuration options.

Enumerations#

class episia.core.constants.ConfidenceLevel(value)[source]#

Bases: float, Enum

Common confidence levels.

P90 = 0.9#
P95 = 0.95#
P99 = 0.99#
P999 = 0.999#
__format__(format_spec)#

Returns format using actual value type unless __str__ has been overridden.

class episia.core.constants.AlphaLevel(value)[source]#

Bases: float, Enum

Common alpha levels for significance testing.

ALPHA_0001 = 0.001#
ALPHA_001 = 0.01#
ALPHA_005 = 0.05#
ALPHA_010 = 0.1#
__format__(format_spec)#

Returns format using actual value type unless __str__ has been overridden.

class episia.core.constants.PowerLevel(value)[source]#

Bases: float, Enum

Common statistical power levels.

POWER_080 = 0.8#
POWER_085 = 0.85#
POWER_090 = 0.9#
POWER_095 = 0.95#
__format__(format_spec)#

Returns format using actual value type unless __str__ has been overridden.

class episia.core.constants.ConfidenceIntervalMethod(value)[source]#

Bases: str, Enum

Methods for confidence interval calculation.

AGRESTI_COULL = 'agresti_coull'#
BOOTSTRAP = 'bootstrap'#
CLOPPER_PEARSON = 'clopper_pearson'#
DELTA = 'delta'#
JEFFREYS = 'jeffreys'#
WALD = 'wald'#
WILSON = 'wilson'#
__format__(format_spec)#

Returns format using actual value type unless __str__ has been overridden.

class episia.core.constants.RiskRatioMethod(value)[source]#

Bases: str, Enum

Methods for risk ratio calculation.

BOOTSTRAP = 'bootstrap'#
DELTA = 'delta'#
SCORE = 'score'#
WALD = 'wald'#
__format__(format_spec)#

Returns format using actual value type unless __str__ has been overridden.

class episia.core.constants.OddsRatioMethod(value)[source]#

Bases: str, Enum

Methods for odds ratio calculation.

CORNELL = 'cornell'#
EXACT = 'exact'#
FLEISS = 'fleiss'#
GART = 'gart'#
WALD = 'wald'#
__format__(format_spec)#

Returns format using actual value type unless __str__ has been overridden.

class episia.core.constants.PlotStyle(value)[source]#

Bases: str, Enum

Plot style presets.

COLORBLIND = 'colorblind'#
DARK = 'dark'#
MINIMAL = 'minimal'#
PRESENTATION = 'presentation'#
SCIENTIFIC = 'scientific'#
__format__(format_spec)#

Returns format using actual value type unless __str__ has been overridden.

class episia.core.constants.ColorPalette(value)[source]#

Bases: str, Enum

Color palette options.

CIVIDIS = 'cividis'#
DARK2 = 'dark2'#
INFERNO = 'inferno'#
MAGMA = 'magma'#
PLASMA = 'plasma'#
SET2 = 'set2'#
TAB10 = 'tab10'#
VIRIDIS = 'viridis'#
__format__(format_spec)#

Returns format using actual value type unless __str__ has been overridden.

Default Values#

episia.core.constants.DEFAULT_CONFIDENCE = ConfidenceLevel.P95#

Common confidence levels.

episia.core.constants.DEFAULT_ALPHA = AlphaLevel.ALPHA_005#

Common alpha levels for significance testing.

episia.core.constants.DEFAULT_POWER = PowerLevel.POWER_080#

Common statistical power levels.

episia.core.constants.EPSILON = 1e-10#

Convert a string or number to a floating point number, if possible.

episia.core.constants.MAX_ITERATIONS = 1000#

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

episia.core.constants.CONVERGENCE_TOL = 1e-06#

Convert a string or number to a floating point number, if possible.

episia.core.constants.CHI_SQUARE_SMALL_SAMPLE = 5#

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

episia.core.constants.FISHER_EXACT_THRESHOLD = 20#

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

episia.core.constants.NORMAL_APPROXIMATION_N = 30#

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

episia.core.constants.MEAN_INCUBATION_COVID = 5.2#

Convert a string or number to a floating point number, if possible.

episia.core.constants.MEAN_INFECTIOUS_PERIOD_COVID = 7.0#

Convert a string or number to a floating point number, if possible.

episia.core.constants.BASIC_REPRODUCTION_COVID = 2.5#

Convert a string or number to a floating point number, if possible.

episia.core.constants.WHO_STANDARD_POPULATION = array([1000,  900,  900,  900,  900,  800,  800,  700,  600,  500,  400,         400,  300,  200,  100,   50,   30,   20,   10,    5])#
ndarray(shape, dtype=float, buffer=None, offset=0,

strides=None, order=None)

An array object represents a multidimensional, homogeneous array of fixed-size items. An associated data-type object describes the format of each element in the array (its byte-order, how many bytes it occupies in memory, whether it is an integer, a floating point number, or something else, etc.)

Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array.

For more information, refer to the numpy module and examine the methods and attributes of an array.

Parameters:
  • below) ((for the __new__ method; see Notes)

  • shape (tuple of ints) – Shape of created array.

  • dtype (data-type, optional) – Any object that can be interpreted as a numpy data type.

  • buffer (object exposing buffer interface, optional) – Used to fill the array with data.

  • offset (int, optional) – Offset of array data in buffer.

  • strides (tuple of ints, optional) – Strides of data in memory.

  • order ({'C', 'F'}, optional) – Row-major (C-style) or column-major (Fortran-style) order.

episia.core.constants.T#

Transpose of the array.

Type:

ndarray

episia.core.constants.data#

The array’s elements, in memory.

Type:

buffer

episia.core.constants.dtype#

Describes the format of the elements in the array.

Type:

dtype object

episia.core.constants.flags#

Dictionary containing information related to memory use, e.g., ‘C_CONTIGUOUS’, ‘OWNDATA’, ‘WRITEABLE’, etc.

Type:

dict

episia.core.constants.flat#

Flattened version of the array as an iterator. The iterator allows assignments, e.g., x.flat = 3 (See ndarray.flat for assignment examples; TODO).

Type:

numpy.flatiter object

episia.core.constants.imag#

Imaginary part of the array.

Type:

ndarray

episia.core.constants.real#

Real part of the array.

Type:

ndarray

episia.core.constants.size#

Number of elements in the array.

Type:

int

episia.core.constants.itemsize#

The memory use of each array element in bytes.

Type:

int

episia.core.constants.nbytes#

The total number of bytes required to store the array data, i.e., itemsize * size.

Type:

int

episia.core.constants.ndim#

The array’s number of dimensions.

Type:

int

episia.core.constants.shape#

Shape of the array.

Type:

tuple of ints

episia.core.constants.strides#

The step-size required to move from one element to the next in memory. For example, a contiguous (3, 4) array of type int16 in C-order has strides (8, 2). This implies that to move from element to element in memory requires jumps of 2 bytes. To move from row-to-row, one needs to jump 8 bytes at a time (2 * 4).

Type:

tuple of ints

episia.core.constants.ctypes#

Class containing properties of the array needed for interaction with ctypes.

Type:

ctypes object

episia.core.constants.base#

If the array is a view into another array, that array is its base (unless that array is also a view). The base array is where the array data is actually stored.

Type:

ndarray

See also

array

Construct an array.

zeros

Create an array, each element of which is zero.

empty

Create an array, but leave its allocated memory unchanged (i.e., it contains “garbage”).

dtype

Create a data-type.

numpy.typing.NDArray

An ndarray alias generic w.r.t. its dtype.type <numpy.dtype.type>.

Notes

There are two modes of creating an array using __new__:

  1. If buffer is None, then only shape, dtype, and order are used.

  2. If buffer is an object exposing the buffer interface, then all keywords are interpreted.

No __init__ method is needed because the array is fully initialized after the __new__ method.

Examples

These examples illustrate the low-level ndarray constructor. Refer to the See Also section above for easier ways of constructing an ndarray.

First mode, buffer is None:

>>> import numpy as np
>>> np.ndarray(shape=(2,2), dtype=float, order='F')
array([[0.0e+000, 0.0e+000], # random
       [     nan, 2.5e-323]])

Second mode:

>>> np.ndarray((2,), buffer=np.array([1,2,3]),
...            offset=np.int_().itemsize,
...            dtype=int) # offset = 1*itemsize, i.e. skip first element
array([2, 3])
episia.core.constants.EUROPEAN_STANDARD_POPULATION = array([1000,  900,  900,  900,  800,  800,  800,  700,  700,  700,  700,         700,  600,  500,  400,  300,  200,  100,   50,   20])#
ndarray(shape, dtype=float, buffer=None, offset=0,

strides=None, order=None)

An array object represents a multidimensional, homogeneous array of fixed-size items. An associated data-type object describes the format of each element in the array (its byte-order, how many bytes it occupies in memory, whether it is an integer, a floating point number, or something else, etc.)

Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array.

For more information, refer to the numpy module and examine the methods and attributes of an array.

Parameters:
  • below) ((for the __new__ method; see Notes)

  • shape (tuple of ints) – Shape of created array.

  • dtype (data-type, optional) – Any object that can be interpreted as a numpy data type.

  • buffer (object exposing buffer interface, optional) – Used to fill the array with data.

  • offset (int, optional) – Offset of array data in buffer.

  • strides (tuple of ints, optional) – Strides of data in memory.

  • order ({'C', 'F'}, optional) – Row-major (C-style) or column-major (Fortran-style) order.

episia.core.constants.T#

Transpose of the array.

Type:

ndarray

episia.core.constants.data#

The array’s elements, in memory.

Type:

buffer

episia.core.constants.dtype#

Describes the format of the elements in the array.

Type:

dtype object

episia.core.constants.flags#

Dictionary containing information related to memory use, e.g., ‘C_CONTIGUOUS’, ‘OWNDATA’, ‘WRITEABLE’, etc.

Type:

dict

episia.core.constants.flat#

Flattened version of the array as an iterator. The iterator allows assignments, e.g., x.flat = 3 (See ndarray.flat for assignment examples; TODO).

Type:

numpy.flatiter object

episia.core.constants.imag#

Imaginary part of the array.

Type:

ndarray

episia.core.constants.real#

Real part of the array.

Type:

ndarray

episia.core.constants.size#

Number of elements in the array.

Type:

int

episia.core.constants.itemsize#

The memory use of each array element in bytes.

Type:

int

episia.core.constants.nbytes#

The total number of bytes required to store the array data, i.e., itemsize * size.

Type:

int

episia.core.constants.ndim#

The array’s number of dimensions.

Type:

int

episia.core.constants.shape#

Shape of the array.

Type:

tuple of ints

episia.core.constants.strides#

The step-size required to move from one element to the next in memory. For example, a contiguous (3, 4) array of type int16 in C-order has strides (8, 2). This implies that to move from element to element in memory requires jumps of 2 bytes. To move from row-to-row, one needs to jump 8 bytes at a time (2 * 4).

Type:

tuple of ints

episia.core.constants.ctypes#

Class containing properties of the array needed for interaction with ctypes.

Type:

ctypes object

episia.core.constants.base#

If the array is a view into another array, that array is its base (unless that array is also a view). The base array is where the array data is actually stored.

Type:

ndarray

See also

array

Construct an array.

zeros

Create an array, each element of which is zero.

empty

Create an array, but leave its allocated memory unchanged (i.e., it contains “garbage”).

dtype

Create a data-type.

numpy.typing.NDArray

An ndarray alias generic w.r.t. its dtype.type <numpy.dtype.type>.

Notes

There are two modes of creating an array using __new__:

  1. If buffer is None, then only shape, dtype, and order are used.

  2. If buffer is an object exposing the buffer interface, then all keywords are interpreted.

No __init__ method is needed because the array is fully initialized after the __new__ method.

Examples

These examples illustrate the low-level ndarray constructor. Refer to the See Also section above for easier ways of constructing an ndarray.

First mode, buffer is None:

>>> import numpy as np
>>> np.ndarray(shape=(2,2), dtype=float, order='F')
array([[0.0e+000, 0.0e+000], # random
       [     nan, 2.5e-323]])

Second mode:

>>> np.ndarray((2,), buffer=np.array([1,2,3]),
...            offset=np.int_().itemsize,
...            dtype=int) # offset = 1*itemsize, i.e. skip first element
array([2, 3])
episia.core.constants.DEFAULT_FIGSIZE = (10, 6)#

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.

episia.core.constants.DEFAULT_DPI = 100#

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

episia.core.constants.DEFAULT_FONTSIZE = 12#

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

episia.core.constants.DEFAULT_COLOR_PALETTE = ColorPalette.VIRIDIS#

Color palette options.

episia.core.constants.DEFAULT_PLOT_STYLE = PlotStyle.SCIENTIFIC#

Plot style presets.

Disease-Specific Parameters#

episia.core.constants.COVID19_PARAMS = {'basic_reproduction': {'mean': 2.5, 'range': (1.5, 3.5)}, 'case_fatality_rate': {'by_age': {'0-9': 0.001, '10-19': 0.001, '20-29': 0.002, '30-39': 0.004, '40-49': 0.01, '50-59': 0.035, '60-69': 0.095, '70-79': 0.18, '80+': 0.3}, 'global': 0.02}, 'incubation_period': {'distribution': 'lognormal', 'mean': 5.2, 'std': 3.5}, 'infectious_period': {'distribution': 'gamma', 'mean': 7.0, 'std': 3.0}}#

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

episia.core.constants.INFLUENZA_PARAMS = {'basic_reproduction': {'mean': 1.3, 'range': (1.1, 1.5)}, 'incubation_period': {'distribution': 'gamma', 'mean': 1.4, 'std': 0.8}, 'infectious_period': {'distribution': 'gamma', 'mean': 3.0, 'std': 1.0}}#

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

episia.core.constants.EBOLA_PARAMS = {'basic_reproduction': {'mean': 1.8, 'range': (1.5, 2.2)}, 'case_fatality_rate': 0.5, 'incubation_period': {'distribution': 'lognormal', 'mean': 9.0, 'std': 5.0}, 'infectious_period': {'distribution': 'gamma', 'mean': 10.0, 'std': 4.0}}#

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

Configuration#

episia.core.constants.EPISIA_CONFIG: Dict[str, Any] = {'computation': {'cache_size': 1000, 'n_jobs': 1, 'parallel_processing': False, 'use_cache': True}, 'output': {'decimal_places': 3, 'include_sample_sizes': True, 'pvalue_format': 'auto', 'show_confidence_intervals': True}, 'statistics': {'alpha_level': AlphaLevel.ALPHA_005, 'confidence_level': ConfidenceLevel.P95, 'convergence_tol': 1e-06, 'max_iterations': 1000, 'power_level': PowerLevel.POWER_080}, 'visualization': {'color_palette': ColorPalette.VIRIDIS, 'dpi': 100, 'figure_size': (10, 6), 'font_size': 12, 'plot_style': PlotStyle.SCIENTIFIC}}#

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

episia.core.constants.get_config(key=None)[source]#

Get configuration value(s).

Parameters:

key (str | None) – Configuration key (e.g., ‘statistics.confidence_level’)

Returns:

Configuration value or dictionary

Return type:

Any

episia.core.constants.set_config(key, value)[source]#

Set configuration value.

Parameters:
  • key (str) – Configuration key (e.g., ‘statistics.confidence_level’)

  • value (Any) – New value

Return type:

None