laser_cholera package¶
Subpackages¶
- laser_cholera.metapop package
Analyzer
Census
DerivedValues
EnvToHuman
EnvToHumanVax
Environmental
Exposed
HumanToHuman
HumanToHumanVax
Infectious
Parameters
Recorder
Recovered
Susceptible
Vaccinated
get_parameters()
- Submodules
- laser_cholera.metapop.analyzer module
- laser_cholera.metapop.census module
- laser_cholera.metapop.derivedvalues module
- laser_cholera.metapop.environmental module
- laser_cholera.metapop.envtohuman module
- laser_cholera.metapop.envtohumanvax module
- laser_cholera.metapop.exposed module
- laser_cholera.metapop.humantohuman module
- laser_cholera.metapop.humantohumanvax module
- laser_cholera.metapop.infectious module
- laser_cholera.metapop.logsetup module
- laser_cholera.metapop.model module
- laser_cholera.metapop.params module
- laser_cholera.metapop.recorder module
- laser_cholera.metapop.recovered module
- laser_cholera.metapop.scenario module
- laser_cholera.metapop.susceptible module
- laser_cholera.metapop.utils module
- laser_cholera.metapop.vaccinated module
Submodules¶
laser_cholera.cli module¶
Module that contains the command line app.
Why does this file exist, and why not put this in __main__?
You might be tempted to import things from __main__ later, but that will cause problems: the code will get executed twice:
When you run python -mlaser_cholera python will execute
__main__.py
as a script. That means there will not be anylaser_cholera.__main__
insys.modules
.When you import __main__ it will get executed again (as a module) because there”s no
laser_cholera.__main__
insys.modules
.Also see (1) from https://click.palletsprojects.com/en/stable/setuptools/
laser_cholera.core module¶
laser_cholera.iso_codes module¶
laser_cholera.likelihood module¶
- laser_cholera.likelihood.calc_log_likelihood(observed, estimated, family, weights=None, **kwargs)[source]¶
Calculate the log-likelihood of the observed data given the estimated data.
- Parameters:
observed (np.ndarray) – Observed data.
estimated (np.ndarray) – Estimated data.
family (str) – The family of the distribution (e.g., “poisson”, “negbin”).
weights (np.ndarray, optional) – Weights for the data. If None, all weights are set to 1.
**kwargs (dict) – Additional arguments for the likelihood calculation.
- Returns:
float – The log-likelihood of the observed data given the estimated data.
- laser_cholera.likelihood.calc_log_likelihood_beta(observed, estimated, mean_precision=True, weights=None, verbose=True)[source]¶
Calculate the log-likelihood for the Beta distribution.
- Parameters:
observed (np.ndarray) – Observed values (must be strictly between 0 and 1).
estimated (np.ndarray) – Estimated values (must be strictly between 0 and 1).
mean_precision (bool, optional) – Whether to use mean-precision parameterization. Default is True.
weights (np.ndarray, optional) – Weights for the observations. If None, all weights are set to 1.
verbose (bool, optional) – If True, print additional information.
- Returns:
float – The log-likelihood of the observed data given the estimated data.
- laser_cholera.likelihood.calc_log_likelihood_binomial(observed, estimated, trials, weights=None, verbose=True)[source]¶
Calculate the log-likelihood for the Binomial distribution.
- Parameters:
observed (np.ndarray) – Observed counts (must be integers between 0 and trials).
estimated (np.ndarray) – Estimated probabilities (must be strictly between 0 and 1).
trials (np.ndarray) – Number of trials (must be positive integers).
weights (np.ndarray, optional) – Weights for the observations. If None, all weights are set to 1.
verbose (bool, optional) – If True, print additional information.
- Returns:
float – The log-likelihood of the observed data given the estimated data.
- laser_cholera.likelihood.calc_log_likelihood_gamma(observed, estimated, weights=None, verbose=True)[source]¶
Calculate the log-likelihood for the Gamma distribution.
- Parameters:
observed (np.ndarray) – Observed values (must be strictly positive).
estimated (np.ndarray) – Estimated values (must be strictly positive).
weights (np.ndarray, optional) – Weights for the observations. If None, all weights are set to 1.
verbose (bool, optional) – If True, print additional information.
- Returns:
float – The log-likelihood of the observed data given the estimated data.
- laser_cholera.likelihood.calc_log_likelihood_negbin(observed, estimated, k=None, weights=None, verbose=True)[source]¶
Calculate the log-likelihood for the Negative Binomial distribution.
- Parameters:
observed (np.ndarray) – Observed counts (must be non-negative integers).
estimated (np.ndarray) – Estimated means (must be strictly positive).
k (float, optional) – Dispersion parameter. If None, it will be estimated from the data.
weights (np.ndarray, optional) – Weights for the observations. If None, all weights are set to 1.
verbose (bool, optional) – If True, print additional information.
- Returns:
float – The log-likelihood of the observed data given the estimated data.
- laser_cholera.likelihood.calc_log_likelihood_normal(observed, estimated, weights=None, verbose=True)[source]¶
Calculate the log-likelihood for the Normal distribution.
- Parameters:
observed (np.ndarray) – Observed values.
estimated (np.ndarray) – Estimated values.
weights (np.ndarray, optional) – Weights for the observations. If None, all weights are set to 1.
verbose (bool, optional) – If True, print additional information.
- Returns:
float – The log-likelihood of the observed data given the estimated data.
- laser_cholera.likelihood.calc_log_likelihood_poisson(observed, estimated, weights=None, verbose=True)[source]¶
Calculate the log-likelihood for the Poisson distribution.
- Parameters:
observed (np.ndarray) – Observed counts (must be non-negative integers).
estimated (np.ndarray) – Estimated means (must be strictly positive).
weights (np.ndarray, optional) – Weights for the observations. If None, all weights are set to 1.
verbose (bool, optional) – If True, print additional information.
- Returns:
float – The log-likelihood of the observed data given the estimated data.
- laser_cholera.likelihood.calc_log_likelihood_validation(observed, estimated, weights, trials=None, verbose=True)[source]¶
Validate and preprocess inputs for log-likelihood calculation. This function performs validation and preprocessing of input arrays for calculating log-likelihood. It removes NaN values, checks for consistency in array lengths, and ensures weights are non-negative. The function returns the processed inputs or raises errors for invalid inputs.
- Parameters:
observed (np.ndarray) – Array of observed values.
estimated (np.ndarray) – Array of estimated values.
weights (np.ndarray or None) – Array of weights. If None, defaults to an array of ones with the same shape as observed.
trials (np.ndarray or None, optional) – Array of trial counts. If provided, it is also validated and returned. Defaults to None.
verbose (bool, optional) – If True, prints warnings for empty or invalid inputs. Defaults to True.
- Returns:
tuple –
- A tuple containing the validated and preprocessed arrays:
(observed, estimated, weights) if trials is None.
(observed, estimated, trials, weights) if trials is provided.
- Raises:
ValueError – If the lengths of observed, estimated, and weights do not match after preprocessing.
ValueError – If any weight is negative.
ValueError – If all weights are zero.
Notes
If all input values are NaN after preprocessing, the function returns None and optionally prints a warning if verbose is True.
- laser_cholera.likelihood.get_model_likelihood(obs_cases, est_cases, obs_deaths, est_deaths, weight_cases=None, weight_deaths=None, weights_location=None, weights_time=None, verbose=False)[source]¶
Calculate the likelihood of the model given the observed and estimated cases and deaths.
- Parameters:
obs_cases (np.ndarray) – Observed cases.
est_cases (np.ndarray) – Estimated cases.
obs_deaths (np.ndarray) – Observed deaths.
est_deaths (np.ndarray) – Estimated deaths.
weight_cases (np.ndarray, optional) – Weights for the cases. If None, all weights are set to 1.
weight_deaths (np.ndarray, optional) – Weights for the deaths. If None, all weights are set to 1.
weights_location (np.ndarray, optional) – Weights for the locations. If None, all weights are set to 1.
weights_time (np.ndarray, optional) – Weights for the time. If None, all weights are set to 1.
verbose (bool, optional) – If True, print additional information.
- Returns:
float – The likelihood of the model given the observed and estimated cases and deaths.
laser_cholera.sc module¶
- laser_cholera.sc.color(s, fg=None, bg=None, style=None)[source]¶
Add ANSI colors and styles to a string.
- Parameters:
s (str) – String to format.
fg (str|int|tuple) – Foreground color specification.
bg (str|int|tuple( bg) – Background color specification.
style (str) – Style names, separated by ‘+’
- Returns:
Formatted string.