(models)
Increase the likelihood in case of Cholesky failures.

    This is similar to the use of jitchol in GPy. Default callback for BayesianOptimizer.
    Only usable on GPR models, other types are ignored.
Increase the likelihood in case of Cholesky failures.
Increase the likelihood in case of Cholesky failures .
def jitchol_callback(models):
    """
    Increase the likelihood in case of Cholesky failures.

    This is similar to the use of jitchol in GPy. Default callback for BayesianOptimizer.
    Only usable on GPR models, other types are ignored.
    """
    for m in np.atleast_1d(models):
        if isinstance(m, ModelWrapper):
            jitchol_callback(m.wrapped)  # pragma: no cover

        if not isinstance(m, GPR):
            continue

        s = m.get_free_state()
        eKdiag = np.mean(np.diag(m.kern.compute_K_symm(m.X.value)))
        for e in [0] + [10**ex for ex in range(-6,-1)]:
            try:
                m.likelihood.variance = m.likelihood.variance.value + e * eKdiag
                m.optimize(maxiter=5)
                break
            except tf.errors.InvalidArgumentError:  # pragma: no cover
                m.set_state(s)
def jitchol_callback ( models ) : for m in np . atleast_1d ( models ) : if isinstance ( m , ModelWrapper ) : jitchol_callback ( m . wrapped ) # pragma: no cover if not isinstance ( m , GPR ) : continue s = m . get_free_state ( ) eKdiag = np . mean ( np . diag ( m . kern . compute_K_symm ( m . X . value ) ) ) for e in [ 0 ] + [ 10 ** ex for ex in range ( - 6 , - 1 ) ] : try : m . likelihood . variance = m . likelihood . variance . value + e * eKdiag m . optimize ( maxiter = 5 ) break except tf . errors . InvalidArgumentError : # pragma: no cover m . set_state ( s )