Utils

Date published: 21/09/23

behaviour_tests.features.steps.utils.bvbgm(l_inf: float, k: float, t_0: float, h: float, t_h: float, t: ndarray) ndarray[source]

Fit a biphasic von Bertalanffy growth model.

Args:
l_inf (float):

The asymptotic size.

k (float):

The growth coefficient.

t_0 (float):

The theoretical age when size is zero.

h (float):

The magnitude of the maximum difference in the size-at-age between monophasic and biphasic parameterisations.

t_h (float):

The time of the phasic shift.

t (np.ndarray):

The age.

Returns:
np.ndarray:

The size at time t.

behaviour_tests.features.steps.utils.fit_linear_model(model: Model, priors: dict, x, y, resp: str, likelihood: str, factors: list[str], factor_data: dict[MutableData] = {}, parameter_factors: dict[list[str]] = {}) None[source]

Fit a linear Bayesian model.

Args:
model (pm.Model):

The PyMC model.

priors (dict):

The model priors.

x (np.ndarray):

The explanatory variable data.

y (np.ndarray):

The response variable data.

resp (str):

The model response.

likelihood (str):

The model likelihood.

factors (list):

The list of model factors.

factor_data: (dict, optional):

The factor level data. Defaults to {}.

parameter_factors (dict[list[str]], optional):

The map between parameters and factors. Defaults to {}.

behaviour_tests.features.steps.utils.fit_model(model_type: str, model: Model, priors: dict, x: ndarray, y: ndarray, resp: str, likelihood: str, factors: list[str], growth_curve: str = '', factor_data: dict[MutableData] = {}, parameter_factors: dict[list[str]] = {}) None[source]

Fit a Bayesian model.

Args:
model_type (str):

The model type.

model (pm.Model):

The PyMC model.

priors (dict):

The model priors.

x (np.ndarray):

The explanatory variable data.

y (np.ndarray):

The response variable data.

resp (str):

The model response.

likelihood (str):

The model likelihood.

factors (list):

The list of model factors.

growth_curve: (str, optional):

The nonlinear growth curve. Defaults to “”.

factor_data: (dict, optional):

The factor level data. Defaults to {}.

parameter_factors (dict[list[str]], optional):

The map between parameters and factors. Defaults to {}.

behaviour_tests.features.steps.utils.fit_nonlinear_model(model: Model, priors: dict, x, y, resp: str, likelihood: str, factors: list[str], growth_curve: str = '', factor_data: dict[MutableData] = {}, parameter_factors: dict[list[str]] = {}) None[source]

Fit a nonlinear Bayesian growth model.

Args:
model (pm.Model):

The PyMC model.

priors (dict):

The model priors.

x (np.ndarray):

The explanatory variable data.

y (np.ndarray):

The response variable data.

resp (str):

The model response.

likelihood (str):

The model likelihood.

factors (list):

The list of model factors.

growth_curve: (str, optional):

The nonlinear growth curve. Defaults to “”.

factor_data: (dict, optional):

The factor level data. Defaults to {}.

parameter_factors (dict[list[str]], optional):

The map between parameters and factors. Defaults to {}.

behaviour_tests.features.steps.utils.get_df(data_dir: str, data_file: str, year_interval: list[str], sex: str, locations: str, response_var: str, explanatory_var: str) DataFrame[source]

Get the input dataframe.

Args:
data_dir (str):

The input data directory.

data_file (str):

The input data file.

year_interval (list[str]):

The lower and upper bound for years.

sex (str):

The sex of the sample.

locations (str):

The locations of the sample.

response_var (str):

The model response variable.

explanatory_var (str):

The model explanatory variable.

Returns:
pd.DataFrame:

The loaded input dataframe.

behaviour_tests.features.steps.utils.get_dir_path(base_dir: str, class_name: str, order: str, species: str) str[source]

Get the combined directory path.

Args:
base_dir (str):

The base directory.

class_name (str):

The taxonomic class.

order (str):

The taxonomic order.

species (str):

The taxonomic species.

Returns:

str: The combined directory path.

behaviour_tests.features.steps.utils.get_mu_pp(trace, model_type: str, x: ndarray, priors: dict, growth_curve: str = '') DataArray[source]

Get the mean posterior predictions.

Args:
trace (Trace):

The model trace.

model_type (str):

The model type.

x (np.ndarray):

The explanatory variable values.

priors (dict):

The model priors.

growth_curve: (str):

The nonlinear growth curve.

Returns:

xr.DataArray: The mean posterior predictions.

behaviour_tests.features.steps.utils.get_trace_dict_key(class_type: str, order: str, species: str, sex: str, model_type: str, growth_curve: str) str[source]

Get the dictionary key for the Bayesian model trace.

Args:
class_type (str):

The taxonomic class.

order (str):

The taxonomic order.

species (str):

The taxonomic species.

sex (str):

The sex of the animal.

model_type (str):

The type of model being fitted.

growth_curve (str):

The type of growth curve being fitted.

Returns:
str:

The dictionary key

behaviour_tests.features.steps.utils.parse_comma_list(text: str) list[source]

Parse a comma-delimited string into a list.

Args:
text (str):

The input text.

Returns:

list: The parsed list.

behaviour_tests.features.steps.utils.plot_bayes_model(trace, out_dir: str, hdi_prob: float = 0.95)[source]

Plot Bayesian modelling results.

Args:
trace (Trace):

The model trace.

out_dir (str):

The output directory.

hdi_prob (float, optional):

The highest density interval probability. Defaults to 0.95.

Returns:

Trace: The model trace.

behaviour_tests.features.steps.utils.plot_preds(mu_pp, out_dir: str, observed_data, posterior_predictive, x: ndarray, response_var: str, explanatory_var: str, hdi_prob: float = 0.95) str[source]

Plot predicted values over the observations.

Args:
mu_pp (DataArray):

The mean posterior predictions.

out_dir (str):

The output directory.

observed_data (DataArray):

The observed data.

posterior_predictive (DataArray):

The posterior predictions.

x (np.ndarray):

The explanatory variable values.

response_var (str):

The response variable.

explanatory_var (str):

The explanatory variable

hdi_prob (float, optional):

The highest density interval probability. Defaults to 0.95.

Returns:

str: The output file.

behaviour_tests.features.steps.utils.snake_case_string(text: str) str[source]

Apply some processing to convert a string to snakecase.

Args:
text (str):

The input text.

Returns:

str: The snakecase string.

behaviour_tests.features.steps.utils.vbgm(l_inf: float, k: float, t_0: float, t: ndarray) ndarray[source]

Fit a von Bertalanffy growth model.

Args:
l_inf (float):

The asymptotic size.

k (float):

The growth coefficient.

t_0 (float):

The theoretical age when size is zero.

t (np.ndarray):

The age.

Returns:
np.ndarray:

The size at time t.