8. Fitting¶
- class lsqfitgp.empbayes_fit(hyperprior, gpfactory, data, raises=True, minkw={}, gpfactorykw={}, jit=False, method='gradient')¶
Maximum a posteriori fit.
Maximizes the marginal likelihood of the data with a Gaussian process model that depends on hyperparameters, multiplied by a prior on the hyperparameters.
- Parameters:
- hyperpriorscalar, array or dictionary of scalars/arrays
A collection of gvars representing the prior for the hyperparameters.
- gpfactorycallable
A function with signature gpfactory(hyperparams) -> GP object. The argument hyperparams has the same structure of the empbayes_fit argument hyperprior. gpfactory must be JAX-friendly, i.e., use jax.numpy and jax.scipy instead of plain numpy/scipy and avoid assignments to arrays.
- datadict, tuple or callable
Dictionary of data that is passed to GP.marginal_likelihood on the GP object returned by gpfactory. If a tuple, it contains the first two arguments to GP.marginal_likelihood. If a callable, it is called with the same arguments of gpfactory and must return the argument(s) for GP.marginal_likelihood.
- raisesbool, optional
If True (default), raise an error when the minimization fails. Otherwise, use the last point of the minimization as result.
- minkwdict, optional
Keyword arguments passed to scipy.optimize.minimize.
- gpfactorykwdict, optional
Keyword arguments passed to gpfactory, and also to data if it is a callable.
- jitbool
If True, use jax’s jit to compile the minimization target. Default False.
- methodstr
Minimization strategy. Options:
- ‘nograd’
Use a gradient-free method.
- ‘gradient’
Use a gradient-only method (default).
- ‘hessian’
Use a Newton method with the Hessian.
- ‘fisher’
Use a Newton method with the Fisher information matrix plus the hyperprior precision matrix.
- ‘hessmod’
Use a Newton method with a modified Hessian where the second derivatives of the prior covariance matrix w.r.t. the hyperparameters are assumed to be zero.
- Raises:
- RuntimeError
The minimization failed and raises is True.
- Attributes:
- pscalar, array or dictionary of scalars/arrays
A collection of gvars representing the hyperparameters that maximize the marginal likelihood. The covariance matrix is computed as the inverse of the hessian of the marginal likelihood. These gvars do not track correlations with the hyperprior or the data.
- minresultscipy.optimize.OptimizeResult
The result object returned by scipy.optimize.minimize.