predict_laplace

hybrid_learning.concepts.train_eval.train_eval_funs.predict_laplace(model, data, device=None, var0=None)[source]

Performs prediction with probit approximation of the Bayesian posterior. See [MacKay1992] for details.

Assumptions on the layers to process (currently:: layers are assumed to be named "concept_layer_{i}")

  • ALl layers are convolutional layers with attributes kernel and bias.

  • Hessian available for each layer as attribute layer.hessian

  • If var0 is unset, variance is available for each layer as attribute layer.var0

Note

Implementation note:: Currently, the kernel is flattened out for the calculation, leading to a considerable consumption of memory. Make sure enough memory is available.

MacKay1992

MacKay, David JC. “The evidence framework applied to classification networks.” Neural computation 4.5 (1992): 720-736. https://github.com/wiseodd/last_layer_laplace/blob/master/paper/laplace/llla_binary.py

Parameters
  • model (Module) – The pytorch model

  • data (Tensor) – The input data to predict for

  • device (Optional[Union[str, device]]) – The device to use for computations; defaults to model device

  • var0 (Optional[float]) – The var0 constant. If not given, uses layer.var0

Returns

The predictions