Bibat's python api
Bibat provides some Python classes and functions that you can use! This page describes them.
bibat.inference_configuration
The inference_configuration module.
This module provides the class InferenceConfiguration and the function
load_inference_configuration.
InferenceConfiguration
Configuration for a statistical inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
A name identifying the model configuration |
required | |
stan_file |
Path to a Stan program, with "/" even on windows |
required | |
prepared_data |
Name of the prepared data for this inference |
required | |
stan_input_function |
name of a function from src.stan_input_functions used to get a Stan input dictionary from a PreparedData object. |
required | |
sample_kwargs |
dictionary of keyword arguments to cmdstanpy.CmdStanModel.sample. |
required | |
modes |
which modes to run the model in. Choose one or more of the AVAILABLE_MODES. |
required | |
dims |
map from parameter names to lists of coordinate names. |
required | |
cpp_options |
valid choices for the |
required | |
stanc_options |
valid choices for the |
required |
Source code in bibat/inference_configuration.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
load_inference_configuration(path)
Load an inference configuration object from a toml file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
Path
|
Path to directory containing a suitable config.toml file |
required |
Source code in bibat/inference_configuration.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
bibat.fitting_mode
A general definition of a fitting mode, plus some mode instances.
FittingMode
A way of fitting a statistical model.
Inferences can be configured to use any of the fitting modes defined here by including them by name in the top-level list 'modes'. For example:
...
modes = ['prior', 'posterior', 'kfold']
...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
A string identifying the fitting mode |
required | |
idata_target |
A string identifying the |
required | |
fit |
A function that takes in an |
required |
Source code in bibat/fitting_mode.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
prior_mode = FittingMode(name='prior', idata_target=IdataTarget.prior, fit=sample_hmc_prior)
module-attribute
posterior_mode = FittingMode(name='posterior', idata_target=IdataTarget.posterior, fit=sample_hmc_posterior)
module-attribute
kfold_mode = FittingMode(name='kfold', idata_target=IdataTarget.log_likelihood, fit=sample_hmc_kfold)
module-attribute
bibat.util
A module that provides some Bayesian analysis oriented utility code.
validate_df_or_string(v)
Load a dataframe even if it is in json string form.
Source code in bibat/util.py
23 24 25 26 27 | |
returns_stan_input(func)
Decorate a function so it returns a json-serialisable dictionary.
Source code in bibat/util.py
39 40 41 42 43 44 45 46 47 48 | |
one_encode(s)
Replace a series's values with 1-indexed integer factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s |
Series
|
a pandas Series that you want to factorise. |
required |
Source code in bibat/util.py
51 52 53 54 55 56 57 | |
make_columns_lower_case(df)
Make a DataFrame's columns lower case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df |
DataFrame
|
a pandas DataFrame |
required |
Source code in bibat/util.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |