Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
ziatdinovmax committed Nov 8, 2024
1 parent 3d2114d commit 56506e0
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions examples/pbnn_example1d.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Partially Bayesian Neural Networks - PBNNs\n",
"\n",
"*Prepared by Maxim Ziatdinov (October 2024)*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook compares active learning with a standard Gaussian process (GP) and with a partially Bayesian neural network (PBNN) on a dataset with discontinuities and non-stationarities."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -33,6 +49,13 @@
"## Data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a measurement function and view the ground truth:"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand Down Expand Up @@ -69,6 +92,13 @@
"## GP-based active learning"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run standard Gaussian process-based active learning:"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand Down Expand Up @@ -1054,6 +1084,13 @@
" y_measured = np.append(y_measured, y_next)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compute MSE and NLPD scores:"
]
},
{
"cell_type": "code",
"execution_count": 4,
Expand All @@ -1071,6 +1108,13 @@
"## Partial BNN-based active learning"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The ```PartialBNN``` combines deterministic and Bayesian layers. For untrained networks, it first performs MAP estimation using regularized SGD with stochastic weight averaging to find good deterministic weights. These MAP-optimized weights then serve as the means for the Gaussian priors in the Bayesian layers, around which MCMC sampling using No U-Turn Sampler explores the posterior distribution. Alternatively, pre-trained weights can be provided directly at the model initialization stage."
]
},
{
"cell_type": "code",
"execution_count": 6,
Expand Down Expand Up @@ -2368,6 +2412,13 @@
" y_measured = np.append(y_measured, y_next)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compute MSE and NLPD scores for PBNN:"
]
},
{
"cell_type": "code",
"execution_count": 7,
Expand All @@ -2382,7 +2433,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Compare results"
"## Compare results\n",
"\n",
"(the lower the better)"
]
},
{
Expand Down Expand Up @@ -2418,13 +2471,6 @@
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 56506e0

Please sign in to comment.