bnn_models_built_in_utils¶
Description of helper functions for Bayesian modeling:
bnn_for_14C_calibration.bnn_models_built_in_utils.gaussian_prior(kernel_size, bias_size, dtype=None, sigma=1.0)
¶
Define a Gaussian prior distribution over weights and biases of a Bayesian neural network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
int
|
Number of kernel weights in the layer. |
required |
bias_size
|
int
|
Number of bias terms in the layer. |
required |
dtype
|
DType
|
TensorFlow data type for the distribution (default None). |
None
|
sigma
|
float
|
Standard deviation of the Gaussian prior (default 1.0). |
1.0
|
Returns:
| Type | Description |
|---|---|
Sequential
|
Non-trainable prior distribution model. Each weight and bias is assumed independent and distributed according to a normal distribution N(0, sigma^2). |
Notes
- The prior distribution is non-trainable; its parameters are fixed.
bnn_for_14C_calibration.bnn_models_built_in_utils.independent_gaussian_posterior(kernel_size, bias_size, dtype=None)
¶
Define an independent Gaussian posterior distribution for variational inference in Bayesian neural networks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
int
|
Number of kernel weights in the layer. |
required |
bias_size
|
int
|
Number of bias terms in the layer. |
required |
dtype
|
DType
|
TensorFlow data type for the distribution (default None). |
None
|
Returns:
| Type | Description |
|---|---|
Sequential
|
Trainable posterior distribution model. Each weight and bias has a learnable mean and diagonal variance. Off-diagonal covariances are zero, implying independence among weights. |
Notes
- The parameters of the distribution (mean and diagonal variance) are trainable.
bnn_for_14C_calibration.bnn_models_built_in_utils.bnn_make_predictions_(bnn_model, X_test, iterations=100, batch_size=None)
¶
Generate predictions from a Bayesian neural network by repeated stochastic forward passes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bnn_model
|
Model
|
Trained Bayesian neural network. |
required |
X_test
|
ndarray or Tensor
|
Test input data. |
required |
iterations
|
int
|
Number of stochastic forward passes to perform (default 100). |
100
|
batch_size
|
int
|
Batch size to use during prediction. If None, defaults to full batch. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Concatenated predictions from all iterations. Shape: (n_samples, n_outputs, iterations) |
Notes
- Each call to the model produces a stochastic output due to the variational posterior.
bnn_for_14C_calibration.bnn_models_built_in_utils.bnn_load_predictions_(filepath)
¶
Load predictions generated by a Bayesian neural network from a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the CSV file containing predictions. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
predictions_array |
ndarray
|
Predictions as a float32 numpy array. |
nb_intervals |
int
|
Number of intervals (rows) in the predictions. |
nb_curves |
int
|
Number of curves (columns) in the predictions. |
Notes
- Intended for predictions generated by
bnn_make_predictions_for calibration purposes.