LaplaceDiscreteSurrogate
LaplaceDiscreteSurrogate(net, X, y, *, trainer=None, noise=None, batch_size=64)A Laplace-approximated network, trained on the data, as a surrogate.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| net | nn.Module | The network. A LoRARegressor, or any nn.Module; one with a prepare method gets the raw inputs through it. |
required |
| X | Any | The inputs: what net.prepare takes (a list of SMILES for a LoRARegressor), or a tensor [n, d] of features. |
required |
| y | Any | The outcomes, [n] or [n, m], as a tensor, a NumPy array or a list. |
required |
| trainer | Trainer | None | Trains the network and fits the Laplace approximation. None takes the network’s default_trainer, or PosthocMarglik(epochs=500, lr=0.01). |
None |
| noise | float | None | The noise variance of y, in its units, if known: one value for every outcome, so the outcomes must have the same spread. None leaves it to the trainer, which fixes it at 1e-3 times the variance of y by default. |
None |
| batch_size | int | Inputs per chunk in predict and sample. |
64 |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | There are fewer than 2 outcomes, or noise is given for outcomes whose standard deviations differ. |
Methods
| Name | Description |
|---|---|
| predict | The posterior mean and standard deviation at X. |
| sample | Functions drawn from the posterior, evaluated at X. |
predict
LaplaceDiscreteSurrogate.predict(X)The posterior mean and standard deviation at X.
The same X gives the same prediction every time. For a network that the exact computation does not support, the standard deviation is estimated from samples drawn with a fixed seed.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | Any | Inputs of the same kind as the training inputs. | required |
Returns
| Name | Type | Description |
|---|---|---|
| Prediction | The prediction, in the units of y. |
sample
LaplaceDiscreteSurrogate.sample(X, n_samples=1, *, generator=None)Functions drawn from the posterior, evaluated at X.
Each draw is one function, \(f(x; \mu) + J(x) \varepsilon\), with one weight draw \(\varepsilon\) for all of X, so the values are jointly distributed, as Thompson sampling needs.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | Any | Inputs of the same kind as the training inputs. | required |
| n_samples | int | The number of functions. | 1 |
| generator | torch.Generator | None | Seeds the draws; None uses torch’s global RNG. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| Tensor | The values, [n_samples, N] (or [n_samples, N, m]), in the units of y. |