# PosthocMarglik

``` python
PosthocMarglik(
    epochs=1000,
    lr=0.1,
    weight_decay=0.001,
    batch_size=10,
    subset=lk.subsets.all,
    hessian_approx=lk.KFAC(),
    prior=lk.priors.Isotropic(),
    noise=0.001,
)
```

Train on the mean squared error, then tune the prior on the marginal likelihood.

The network trains with Adam and a cosine learning-rate schedule. `lk.laplace` then fits the parameters that `subset` picks with `hessian_approx`, and its default hyper tuner, `lk.MarginalLikelihood()`, tunes the prior precision. The noise stays fixed at `noise`, or at the surrogate’s `train_Yvar`; with `noise=None` and no `train_Yvar`, it is tuned along with the prior.

``` python
trainer = PosthocMarglik(epochs=500, subset=lk.subsets.last_layer)
model = LaplaceBoTorchSurrogate(make_net(), train_X, train_Y, trainer=trainer)
```

## Parameters

| Name | Type | Description | Default |
|----|----|----|----|
| epochs | int | Passes over the data. | `1000` |
| lr | float | Adam’s learning rate at the start of the schedule. | `0.1` |
| weight_decay | float | Adam’s weight decay. | `0.001` |
| batch_size | int | Examples per training step. | `10` |
| subset | Subset | The parameters the Laplace approximation covers. `lk.subsets.all` covers every weight; `lk.subsets.last_layer` gives a neural-linear model. | `lk.subsets.all` |
| hessian_approx | HessianApprox\[Any\] \| None | The curvature method, KFAC by default. `None` lets `lk.laplace` pick one per block. | `lk.KFAC()` |
| prior | Prior | The prior, whose precision the tune starts from. | `lk.priors.Isotropic()` |
| noise | float \| None | The fixed noise variance, as a fraction of the variance of the outcomes the trainer gets (so with standardized outcomes, the noise variance itself). A `train_Yvar` given to the surrogate takes its place. `None` tunes the noise. | `0.001` |

## Raises

| Name | Type | Description |
|----|----|----|
|  | ValueError | An option is not positive (`weight_decay` may be 0, and `noise` `None`). |
