8. Fitting¶
- class lsqfitgp.empbayes_fit(hyperprior, gpfactory, data, raises=True, minkw={}, gpfactorykw={})¶
Empirical bayes fit.
Maximizes the marginal likelihood of the data with a Gaussian process model that depends on 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 autograd-friendly, i.e., either use autograd.numpy, autograd.scipy, lsqfitgp.numpy, lsqfitgp.scipy or gvar instead of plain numpy/scipy.
- datadict or callable
Dictionary of data that is passed to GP.marginal_likelihood on the GP object returned by gpfactory. If a callable, it is called with the same arguments of gpfactory and must return either a dictionary or a pair of dictionaries where the second dictionary is passed as givencov argument to 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.
- 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.