laplace.laplace
#
Laplace
#
Laplace(
model: Module,
likelihood: Likelihood | str,
subset_of_weights: (
SubsetOfWeights | str
) = SubsetOfWeights.LAST_LAYER,
hessian_structure: (
HessianStructure | str
) = HessianStructure.KRON,
*args,
functional_approximation: (
FunctionalApproximation | str
) = FunctionalApproximation.SOD,
**kwargs
) -> BaseLaplace
Simplified Laplace access using strings instead of different classes.
Parameters:
-
model(Module) –Pretrained network around which to approximate the posterior.
-
likelihood(Likelihood or str in {'classification', 'regression', 'reward_modeling'}) –Likelihood used for fitting. Reward modeling requires an estimator that supports pairwise preferences, such as ELLA or VaLLA.
-
subset_of_weights(SubsetOfWeights or {'last_layer', 'subnetwork', 'all'}, default:SubsetOfWeights.LAST_LAYER) –subset of weights to consider for inference
-
hessian_structure(HessianStructure or str in {'diag', 'kron', 'full', 'lowrank', 'gp'}, default:HessianStructure.KRON) –structure of the Hessian approximation (note that in case of 'gp', we are not actually doing any Hessian approximation, the inference is instead done in the functional space)
-
*args(Any, default:()) –Additional positional arguments passed to the selected estimator.
-
functional_approximation(FunctionalApproximation or {'sod', 'nystrom', 'variational'}, default:FunctionalApproximation.SOD) –Function-space method for
hessian_structure='gp'. The default usesFunctionalLaplacefor all weights orFunctionalLLLaplacefor the last layer, and requiresn_subset. Nyström selectsELLAand requiressubsample_sizeandn_eigenvalues. Variational selectsVaLLAand requiresinducing_locations; a strategy also needsnum_inducing. Nyström and variational methods requiresubset_of_weights='all'. -
**kwargs(Any, default:{}) –Additional keyword arguments passed to the selected estimator, including its method-specific configuration.
Returns:
-
laplace(BaseLaplace) –chosen subclass of BaseLaplace instantiated with additional arguments
Raises:
-
ValueError–If an approximation name or combination of weight subset, Hessian structure, and function-space method is unsupported.