climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks package¶
Subpackages¶
- climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.bnn_models package
- Submodules
- climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.bnn_models.bayesian_mlp module
- climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.bnn_models.horseshoe_mlp module
- Module contents
Submodules¶
climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layer_utils module¶
Contains implementations of various utilities used by Horseshoe Bayesian layers
- class climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layer_utils.InvGammaHalfCauchyLayer(out_features, b)[source]¶
Bases:
ModuleUses the inverse Gamma parameterization of the half-Cauchy distribution. a ~ C^+(0, b) <==> a^2 ~ IGamma(0.5, 1/lambda), lambda ~ IGamma(0.5, 1/b^2), where lambda is an auxiliary latent variable. Uses a factorized variational approximation q(ln a^2)q(lambda) = N(mu, sigma^2) IGamma(ahat, bhat). This layer places a half Cauchy prior on the scales of each output node of the layer.
- class climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layer_utils.InvGammaLayer(a, b, out_features=1)[source]¶
Bases:
ModuleApproximates the posterior of c^2 with prior IGamma(c^2 | a , b) using a log Normal approximation q(ln c^2) = N(mu, sigma^2)
- climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layer_utils.diag_gaussian_entropy(log_std, D)[source]¶
climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layers module¶
Contains implementations of various Bayesian layers
- class climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layers.BayesianLinearLayer(in_features, out_features, cuda=False, init_weight=None, init_bias=None, prior_stdv=None)[source]¶
Bases:
ModuleAffine layer with N(0, v/H) or N(0, user specified v) priors on weights and fully factorized variational Gaussian approximation
- forward(x, do_sample=True, scale_variances=False)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layers.HorseshoeLayer(in_features, out_features, cuda=False, scale=1.0)[source]¶
Bases:
BayesianLinearLayerUses non-centered parametrization. w_k = v*tau_k*beta_k where k indexes an output unit and w_k and beta_k are vectors of all weights incident into the unit
- forward(x, do_sample=True, debug=False, eps_scale=None, eps_w=None)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layers.NodeSpecificRegularizedHorseshoeLayer(in_features, out_features, cuda=False, scale=1.0, c_a=2.0, c_b=6.0)[source]¶
Bases:
RegularizedHorseshoeLayerUses the regularized Horseshoe distribution. The regularized Horseshoe soft thresholds the tails of the Horseshoe. For all weights w_k incident upon node k in the layer we have: w_k ~ N(0, (tau_k * v)^2 I) N(0, c_k^2 I), c_k^2 ~ InverseGamma(a, b). c_k^2 controls the scale of the thresholding. As c_k^2 -> infinity, the regularized Horseshoe -> Horseshoe Note that we now have a per-node c_k.
- class climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.layers.RegularizedHorseshoeLayer(in_features, out_features, cuda=False, scale=1.0, c_a=2.0, c_b=6.0)[source]¶
Bases:
HorseshoeLayerUses the regularized Horseshoe distribution. The regularized Horseshoe soft thresholds the tails of the Horseshoe. For all weights w_k incident upon node k in the layer we have: w_k ~ N(0, (tau_k * v)^2 I) N(0, c^2 I), c^2 ~ InverseGamma(c_a, b). c^2 controls the scale of the thresholding. As c^2 -> infinity, the regularized Horseshoe -> Horseshoe.
- forward(x, do_sample=True, **kwargs)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.misc module¶
- climb.tool.impl.data_suite.third_party.uq360.models.bayesian_neural_networks.misc.compute_test_ll(y_test, y_pred_samples, std_y=1.0)[source]¶
Computes test log likelihoods = (1 / Ntest) * sum_n p(y_n | x_n, D_train) :param y_test: True y :param y_pred_samples: y^s = f(x_test, w^s); w^s ~ q(w). S x Ntest, where S is the number of samples q(w) is either a trained variational posterior or an MCMC approximation to p(w | D_train) :param std_y: True std of y (assumed known)