ELLA#
laplace.baselaplace.ELLA
#
ELLA(
model: Module,
likelihood: Likelihood | str,
subsample_size: int,
n_eigenvalues: int,
sigma_noise: float | Tensor = 1.0,
prior_precision: float | Tensor = 1.0,
prior_mean: float | Tensor = 0.0,
temperature: float = 1.0,
enable_backprop: bool = False,
dict_key_x: str = "input_ids",
dict_key_y: str = "labels",
backend: type[CurvatureInterface] | None = None,
backend_kwargs: dict[str, Any] | None = None,
seed: int = 1234,
)
Bases: BaseFunctionalLaplace
Accelerated linearized Laplace using a rank-limited Nyström feature map.
The pretrained model stays fixed. Fitting selects a subset of training inputs, builds parameter-Jacobian features, and accumulates projected GGN curvature. A numerically rank-deficient subset cannot supply the requested number of features.
Parameters:
-
model(Module) –Pretrained network to linearize.
-
likelihood(Likelihood or str) –"classification","regression", or"reward_modeling". -
subsample_size(int) –Number of training inputs used to construct the Nyström basis.
-
n_eigenvalues(int) –Number of positive kernel directions retained, at most
subsample_size. -
sigma_noise(float or Tensor, default:1.0) –Observation standard deviation for regression.
-
prior_precision(float or Tensor, default:1.0) –Scalar parameter-prior precision.
-
prior_mean(float or Tensor, default:0.0) –Prior mean; only zero is supported.
-
temperature(float, default:1.0) –Positive scale of the likelihood curvature.
-
enable_backprop(bool, default:False) –Retain derivatives through predictive moments.
-
dict_key_x(str, default:"input_ids") –Input key for mapping-style batches.
-
dict_key_y(str, default:"labels") –Target key for mapping-style batches.
-
backend(type[CurvatureInterface] or None, default:None) –Curvature backend used to compute parameter Jacobians.
-
backend_kwargs(dict[str, Any] or None, default:None) –Additional curvature backend options.
-
seed(int, default:1234) –Seed for selecting basis inputs and output coordinates.
Attributes:
-
fit_history_(dict[str, list[Any]]) –processed_examplesrecords cumulative curvature-pass counts,val_nllrecords validation scores, andtuningrecords candidate hyperparameters and their validation scores. -
dual_directions(Tensor or None) –Fitted parameter-space basis shaped
[parameters, n_eigenvalues]. -
feature_gram(Tensor or None) –Accumulated projected curvature shaped
[n_eigenvalues, n_eigenvalues]before noise and temperature scaling. -
chol_precision(Tensor or None) –Lower Cholesky factor of the feature-space posterior precision.
Notes
fit returns None. fit_history_ stores processed example counts,
validation NLL, and prior-grid scores when those options are used.
Source code in laplace/baselaplace.py
_backend_kwargs
#
_asdl_fisher_kwargs
#
_asdl_fisher_kwargs: dict[str, Any] = (
dict()
if asdl_fisher_kwargs is None
else asdl_fisher_kwargs
)
prior_precision_diag
#
Obtain the diagonal prior precision \(p_0\) constructed from either a scalar, layer-wise, or diagonal prior precision.
Returns:
-
prior_precision_diag(Tensor) –
_uses_backpack_backend
#
_uses_backpack_backend: bool
Whether the curvature backend extends modules using BackPACK.
_uses_asdl_backend
#
_uses_asdl_backend: bool
Whether the curvature backend computes Jacobians using ASDL.
fit_history_
#
log_likelihood
#
Reject access to an untracked training log likelihood.
Raises:
-
NotImplementedError–Always raised because ELLA accumulates curvature without tracking the training log likelihood.
_curv_closure
#
_curv_closure(
X: Tensor | MutableMapping[str, Tensor | Any],
y: Tensor,
N: int,
) -> tuple[Tensor, Tensor]
__call__
#
__call__(
x: Tensor | MutableMapping,
pred_type: PredType | str = PredType.GP,
joint: bool = False,
link_approx: LinkApprox | str = LinkApprox.PROBIT,
n_samples: int = 100,
diagonal_output: bool = False,
generator: Generator | None = None,
fitting: bool = False,
**model_kwargs: dict[str, Any]
) -> Tensor | tuple[Tensor, Tensor]
Predict from the fitted function-space posterior.
Parameters:
-
x(Tensor or MutableMapping) –Batched model inputs.
-
pred_type(PredType or str, default:PredType.GP) –Prediction type. Function-space estimators support only
"gp". -
joint(bool, default:False) –Retain cross-input covariance for regression predictions.
-
link_approx(LinkApprox or str, default:LinkApprox.PROBIT) –Approximation for the classification probability link.
-
n_samples(int, default:100) –Number of draws for a Monte Carlo classification link.
-
diagonal_output(bool, default:False) –Return only output variances for regression when supported.
-
generator(Generator or None, default:None) –Random generator for Monte Carlo classification predictions.
-
fitting(bool, default:False) –Evaluate reward-model preference pairs as classification inputs.
-
**model_kwargs(Any, default:{}) –Accepted for compatibility with the base prediction interface; these arguments are not forwarded to the model.
Returns:
-
Tensor or tuple[Tensor, Tensor]–Classification probabilities
[B, C], or regression/reward latent mean and covariance. Withjoint=True, the regression mean is flattened and covariance has shape[B*O, B*O].
Raises:
-
RuntimeError–If the posterior has not been fitted.
-
ValueError–If the input batch is empty, the prediction type or link is unsupported, or the generator has an incompatible type or device.
Notes
Regression and individual reward predictions exclude observation
noise. Their marginal mean is [B, O] and covariance is
[B, O, O], or variance [B, O] with diagonal_output=True.
Source code in laplace/baselaplace.py
2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 | |
predictive
#
predictive(
x: Tensor,
pred_type: PredType | str,
link_approx: LinkApprox | str,
n_samples: int,
) -> Tensor | tuple[Tensor, Tensor]
Source code in laplace/baselaplace.py
_check_jacobians
#
Source code in laplace/baselaplace.py
_gridsearch
#
_gridsearch(
loss: Metric | Callable[[Tensor], Tensor | float],
interval: Tensor,
val_loader: DataLoader,
pred_type: PredType | str,
link_approx: LinkApprox | str = LinkApprox.PROBIT,
n_samples: int = 100,
progress_bar: bool = False,
) -> Tensor
Source code in laplace/baselaplace.py
_glm_forward_call
#
_glm_forward_call(
x: Tensor | MutableMapping,
likelihood: Likelihood | str,
joint: bool = False,
link_approx: LinkApprox | str = LinkApprox.PROBIT,
n_samples: int = 100,
diagonal_output: bool = False,
) -> Tensor | tuple[Tensor, Tensor]
Compute the posterior predictive on input data x for "glm" pred type.
Parameters:
-
x(Tensor or MutableMapping) –(batch_size, input_shape)if tensor. If MutableMapping, must contain the said tensor. -
likelihood(Likelihood or str in {'classification', 'regression', 'reward_modeling'}) –determines the log likelihood Hessian approximation.
-
link_approx(('mc', 'probit', 'bridge', 'bridge_norm'), default:'mc') –how to approximate the classification link function for the
'glm'. Forpred_type='nn', only 'mc' is possible. -
joint(bool, default:False) –Whether to output a joint predictive distribution in regression with
pred_type='glm'. If set toTrue, the predictive distribution has the same form as GP posterior, i.e. N([f(x1), ...,f(xm)], Cov[f(x1), ..., f(xm)]). IfFalse, then only outputs the marginal predictive distribution. Only available for regression and GLM predictive. -
n_samples(int, default:100) –number of samples for
link_approx='mc'. -
diagonal_output(bool, default:False) –whether to use a diagonalized posterior predictive on the outputs. Only works for
pred_type='glm'andlink_approx='mc'.
Returns:
-
predictive(Tensor or tuple[Tensor]) –For
likelihood='classification', a torch.Tensor is returned with a distribution over classes (similar to a Softmax). Forlikelihood='regression', a tuple of torch.Tensor is returned with the mean and the predictive variance. Forlikelihood='regression'andjoint=True, a tuple of torch.Tensor is returned with the mean and the predictive covariance.
Source code in laplace/baselaplace.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | |
sample
#
sample(
n_samples: int = 1, generator: Generator | None = None
) -> Tensor
Sample from the Laplace posterior approximation, i.e., \( \theta \sim \mathcal{N}(\theta_{MAP}, P^{-1})\).
Parameters:
-
n_samples(int, default:100) –number of samples
-
generator(Generator, default:None) –random number generator to control the samples
Returns:
-
samples(Tensor) –
Source code in laplace/baselaplace.py
functional_samples
#
functional_samples(
x: Tensor | MutableMapping,
pred_type: PredType | str = PredType.GLM,
n_samples: int = 100,
diagonal_output: bool = False,
generator: Generator | None = None,
joint: bool = False,
) -> Tensor
Draw latent outputs; use joint=True to retain cross-input covariance.
Parameters:
-
x(Tensor or MutableMapping) –Batched model inputs.
-
pred_type(PredType or str, default:PredType.GLM) –Accepted for API compatibility. Every value draws from the function-space posterior;
"nn"does not draw model weights. -
n_samples(int, default:100) –Number of draws.
-
diagonal_output(bool, default:False) –Drop cross-output covariance before sampling.
-
generator(Generator or None, default:None) –Random generator on the model device.
-
joint(bool, default:False) –Retain covariance between input rows.
Returns:
-
Tensor–Latent draws shaped
[n_samples, B, O].
Raises:
-
RuntimeError–If the posterior has not been fitted.
-
ValueError–If the input batch is empty, the sampling type is unsupported, or
n_samplesis not positive.
Source code in laplace/baselaplace.py
2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 | |
_glm_functional_samples
#
_glm_functional_samples(
f_mu: Tensor,
f_var: Tensor,
n_samples: int,
diagonal_output: bool = False,
generator: Generator | None = None,
) -> Tensor
Draw per-input latent samples from supplied Gaussian moments.
Parameters:
-
f_mu(Tensor) –Latent means shaped
[B, O]. -
f_var(Tensor) –Per-input covariance shaped
[B, O, O]. -
n_samples(int) –Number of draws.
-
diagonal_output(bool, default:False) –Drop covariance between output coordinates before sampling.
-
generator(Generator or None, default:None) –Random generator for the draws.
Returns:
-
Tensor–Latent draws shaped
[n_samples, B, O].
Source code in laplace/baselaplace.py
_glm_predictive_samples
#
_glm_predictive_samples(
f_mu: Tensor,
f_var: Tensor,
n_samples: int,
diagonal_output: bool = False,
generator: Generator | None = None,
) -> Tensor
Sample from the posterior predictive on input data x using "glm" prediction
type. I.e., the inverse-link function correponding to the likelihood is applied
on top of the functional sample.
Parameters:
-
f_mu(Tensor or MutableMapping) –glm predictive mean
(batch_size, output_shape) -
f_var(Tensor or MutableMapping) –glm predictive covariances
(batch_size, output_shape, output_shape) -
n_samples(int) –number of samples
-
diagonal_output(bool, default:False) –whether to use a diagonalized glm posterior predictive on the outputs.
-
generator(Generator, default:None) –random number generator to control the samples (if sampling used)
Returns:
-
samples(Tensor) –samples
(n_samples, batch_size, output_shape)
Source code in laplace/baselaplace.py
_checkpoint_configuration
#
Record input keys and backend options required by a checkpoint.
Returns:
Source code in laplace/baselaplace.py
_validate_checkpoint_configuration
#
Reject a checkpoint created with different input or backend settings.
Parameters:
Raises:
-
ValueError–If a required setting differs from the current estimator.
Source code in laplace/baselaplace.py
_check_fitted
#
Refresh a fitted posterior or reject predictions before fitting.
Raises:
-
RuntimeError–If
fithas not completed.
Source code in laplace/baselaplace.py
_check_nonempty_inputs
#
_check_nonempty_inputs(x: Tensor | MutableMapping) -> None
Require at least one input row for a function-space prediction.
Parameters:
-
x(Tensor or MutableMapping) –Batched model inputs.
Raises:
-
ValueError–If the input batch is empty.
Source code in laplace/baselaplace.py
predictive_moments
#
predictive_moments(
x: Tensor | MutableMapping, *, joint: bool = False
) -> tuple[Tensor, Tensor]
Return latent predictive moments without observation noise.
Parameters:
-
x(Tensor or MutableMapping) –Batched model inputs.
-
joint(bool, default:False) –Include covariance between input rows when
True.
Returns:
-
tuple[Tensor, Tensor]–Mean
[B, O]and covariance[B, O, O]by default. Withjoint=True, the mean is flattened and covariance has shape[B*O, B*O].
Raises:
-
RuntimeError–If the posterior has not been fitted.
-
ValueError–If the input batch is empty.
Source code in laplace/baselaplace.py
_classification_validation_nll
#
_classification_validation_nll(
x: Tensor | MutableMapping, targets: Tensor
) -> Tensor
Compute summed classification NLL using the probit logit scale.
Parameters:
-
x(Tensor or MutableMapping) –Validation inputs.
-
targets(Tensor) –Class targets for those inputs.
Returns:
-
Tensor–Summed negative log likelihood for the batch.
Source code in laplace/baselaplace.py
predictive_samples
#
predictive_samples(
x: Tensor | MutableMapping,
pred_type: PredType | str = PredType.GLM,
n_samples: int = 100,
diagonal_output: bool = False,
generator: Generator | None = None,
fitting: bool = False,
joint: bool = False,
) -> Tensor
Draw outputs and apply the classification link when appropriate.
Parameters:
-
x(Tensor or MutableMapping) –Batched model inputs.
-
pred_type(PredType or str, default:PredType.GLM) –Accepted for function-space sampling API compatibility.
-
n_samples(int, default:100) –Number of draws.
-
diagonal_output(bool, default:False) –Drop cross-output covariance before sampling.
-
generator(Generator or None, default:None) –Random generator on the model device.
-
fitting(bool, default:False) –Interpret reward-model inputs as preference pairs.
-
joint(bool, default:False) –Retain covariance between input rows.
Returns:
-
Tensor–Predictive draws shaped
[n_samples, B, O].
Raises:
-
RuntimeError–If the posterior has not been fitted.
-
ValueError–If the input batch is empty, the sampling type is unsupported, or
n_samplesis not positive.
Notes
Classification draws are class probabilities obtained by applying softmax to latent samples. Regression and individual reward draws are latent function values without observation noise.
Source code in laplace/baselaplace.py
_batch
#
Move a training batch and its targets to the model device.
Parameters:
-
batch(Any) –(inputs, targets)or a mapping containingdict_key_y.
Returns:
-
tuple[Any, Tensor]–Model inputs and targets on the model device. Floating-point inputs use the model dtype; target dtypes are preserved.
Source code in laplace/baselaplace.py
_indices
#
_indices(loader: DataLoader, balanced: bool) -> Tensor
Select reproducible basis rows, optionally balanced across classes.
Parameters:
-
loader(DataLoader) –Training data from which basis rows are selected.
-
balanced(bool) –Round-robin sample classes when true.
Returns:
-
Tensor–Selected dataset indices of length
subsample_size.
Source code in laplace/baselaplace.py
_build_basis
#
Build the Nyström directions from selected parameter Jacobians.
Parameters:
-
loader(DataLoader) –Training loader used to retrieve selected inputs.
-
indices(Tensor) –Dataset indices selected for the subset kernel.
Raises:
-
ValueError–If the subset kernel has fewer usable directions than requested.
Source code in laplace/baselaplace.py
_features
#
_features(
x: Tensor | MutableMapping,
) -> tuple[Tensor, Tensor]
Project model Jacobians onto the Nyström basis and return outputs.
Parameters:
-
x(Tensor or MutableMapping) –Batched inputs on the model device.
Returns:
-
features(Tensor) –Projected Jacobians shaped
[batch, outputs, n_eigenvalues]. -
outputs(Tensor) –Network outputs shaped
[batch, outputs].
Raises:
-
RuntimeError–If the basis is uninitialized, or differentiable Jacobians are requested but unavailable for the model and backend.
Notes
Uses Jacobian-vector products when supported, otherwise projects parameter Jacobians obtained from the curvature backend.
Source code in laplace/baselaplace.py
3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 | |
_refresh_posterior
#
_build_precision
#
Factor the feature-space posterior precision.
Source code in laplace/baselaplace.py
fit
#
fit(
train_loader: DataLoader,
*,
val_loader: DataLoader | None = None,
val_steps: int | None = None,
balanced: bool = False,
progress_bar: bool = False
) -> None
Fit the ELLA posterior with projected training curvature.
Parameters:
-
train_loader(DataLoader) –Training batches for basis selection and curvature accumulation.
-
val_loader(DataLoader or None, default:None) –Optional validation data for predictive negative log likelihood.
-
val_steps(int or None, default:None) –Evaluate validation NLL every
val_stepsbatches when given. -
balanced(bool, default:False) –Balance class labels in the Nyström subset.
-
progress_bar(bool, default:False) –Show a fitting progress bar.
Raises:
-
ValueError–If sampling or validation-step settings are invalid, or the curvature pass processes no examples.
Notes
Basis selection and curvature accumulation sample the loader
independently. Stochastic samplers may select different rows for each
pass. n_data counts examples processed during curvature accumulation.
Source code in laplace/baselaplace.py
4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 | |
_feature_variance
#
Return per-input output covariance from projected features.
Parameters:
-
features(Tensor) –Projected Jacobians shaped
[batch, outputs, n_eigenvalues].
Returns:
-
Tensor–Latent covariance shaped
[batch, outputs, outputs]without observation noise, using the current posterior precision factor.
Source code in laplace/baselaplace.py
_feature_covariance
#
Return joint output covariance from projected features.
Parameters:
-
features(Tensor) –Projected Jacobians shaped
[batch, outputs, n_eigenvalues].
Returns:
-
Tensor–Latent covariance shaped
[batch * outputs, batch * outputs]without observation noise. Coordinates are ordered by input, then output.
Source code in laplace/baselaplace.py
functional_variance
#
Return per-input latent covariance from parameter Jacobians.
Parameters:
-
jacobians(Tensor) –Parameter Jacobians shaped
[batch, outputs, parameters].
Returns:
-
Tensor–Per-input covariance shaped
[batch, outputs, outputs].
Source code in laplace/baselaplace.py
functional_covariance
#
Return joint latent covariance from parameter Jacobians.
Parameters:
-
jacobians(Tensor) –Parameter Jacobians shaped
[batch, outputs, parameters].
Returns:
-
Tensor–Joint covariance shaped
[batch * outputs, batch * outputs].
Source code in laplace/baselaplace.py
_glm_predictive_distribution
#
_glm_predictive_distribution(
x: Tensor | MutableMapping, joint: bool = False
) -> tuple[Tensor, Tensor]
Compute model outputs and ELLA latent covariance for inputs.
Parameters:
-
x(Tensor or MutableMapping) –Batched model inputs.
-
joint(bool, default:False) –Retain covariance between input rows.
Returns:
-
mean(Tensor) –Network outputs shaped
[batch, outputs], flattened to[batch * outputs]whenjoint=True. -
covariance(Tensor) –Latent covariance shaped
[batch, outputs, outputs], or[batch * outputs, batch * outputs]whenjoint=True. Observation noise is excluded.
Source code in laplace/baselaplace.py
_validation_nll
#
Return mean predictive negative log likelihood on a loader.
Parameters:
-
loader(DataLoader) –Nonempty validation loader with regression targets or class labels.
Returns:
-
Tensor–Scalar NLL averaged over examples, summing over regression output coordinates. Regression includes observation noise; classification uses the probit approximation.
Source code in laplace/baselaplace.py
optimize_prior_precision
#
optimize_prior_precision(
pred_type: PredType | str = PredType.GP,
method: TuningMethod | str = TuningMethod.GRIDSEARCH,
n_steps: int = 100,
lr: float = 0.1,
init_prior_prec: float | Tensor = 1.0,
prior_structure: (
PriorStructure | str
) = PriorStructure.SCALAR,
val_loader: DataLoader | None = None,
loss: Any = None,
log_prior_prec_min: float = -4,
log_prior_prec_max: float = 4,
grid_size: int = 100,
link_approx: LinkApprox | str = LinkApprox.PROBIT,
n_samples: int = 100,
verbose: bool = False,
progress_bar: bool = False,
) -> None
Choose scalar prior precision by validation grid search.
Parameters:
-
pred_type(PredType or str, default:PredType.GP) –Must be
"gp". -
method(TuningMethod or str, default:TuningMethod.GRIDSEARCH) –Must be
"gridsearch". -
n_steps(int, default:100) –Compatibility argument; only the default is supported and it does not determine grid size.
-
lr(float, default:0.1) –Compatibility argument; only the default is supported.
-
init_prior_prec(float or Tensor, default:1.0) –Compatibility argument; must be the scalar default. Grid search evaluates the specified precision range instead.
-
prior_structure(PriorStructure or str, default:PriorStructure.SCALAR) –Only scalar prior precision is supported.
-
val_loader(DataLoader or None, default:None) –Validation data; required for grid search.
-
loss(Any, default:None) –Must be
None; candidates are scored by predictive NLL. -
log_prior_prec_min(float, default:-4) –Base-10 logarithm of the smallest grid precision.
-
log_prior_prec_max(float, default:4) –Base-10 logarithm of the largest grid precision.
-
grid_size(int, default:100) –Number of candidate precisions.
-
link_approx(LinkApprox or str, default:LinkApprox.PROBIT) –Classification validation link; only probit is supported.
-
n_samples(int, default:100) –Compatibility argument; only the default is supported. Validation scoring does not use Monte Carlo samples.
-
verbose(bool, default:False) –Compatibility argument; must be false.
-
progress_bar(bool, default:False) –Compatibility argument; must be false.
Raises:
-
RuntimeError–If the posterior has not been fitted.
-
ValueError–If the prediction type is not
"gp", validation data are missing, or the grid size or candidate precisions are invalid. -
NotImplementedError–If marginal-likelihood tuning or nondefault compatibility arguments are requested.
Notes
Other arguments are accepted for interface compatibility but only their defaults are supported by ELLA.
Source code in laplace/baselaplace.py
4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 | |
optimize_hyperparameters
#
Select the prior (and optionally noise) with lowest validation NLL.
Parameters:
-
val_loader(DataLoader) –Validation data used to score every candidate.
-
grid(iterable) –Candidate prior precisions or
(prior_precision, sigma_noise)pairs for regression.
Raises:
-
ValueError–If the grid is empty or all candidate scores are nonfinite.
Source code in laplace/baselaplace.py
log_marginal_likelihood
#
Reject marginal-likelihood evaluation for the ELLA approximation.
Parameters:
-
*args(Any, default:()) –Positional arguments accepted for compatibility with BaseLaplace.
-
**kwargs(Any, default:{}) –Keyword arguments accepted for compatibility with BaseLaplace.
Raises:
-
NotImplementedError–Always raised. ELLA does not define the subset-of-data GP marginal likelihood; use validation-based hyperparameter tuning.
Source code in laplace/baselaplace.py
state_dict
#
Return a checkpoint containing the fitted ELLA posterior.
Returns:
-
dict[str, Any]–Basis directions, projected curvature, hyperparameters, fitting history, seed, model fingerprint, and backend/input settings. The posterior precision factor is rebuilt when loading.
Raises:
-
RuntimeError–If the posterior has not been fitted.
Notes
Loading validates the pretrained model against the saved fingerprint; it does not restore model parameters or buffers. Construct the receiving estimator with the same pretrained model and configuration.
Source code in laplace/baselaplace.py
load_state_dict
#
Restore a fitted ELLA checkpoint for the same pretrained model.
Parameters:
Raises:
-
ValueError–If the checkpoint is unfitted or incompatible with this model.