Exemplo n.º 1
0
from scipy.spatial.distance import cdist, squareform, pdist

from kernel_hmc.densities.gaussian import sample_gaussian, log_gaussian_pdf
from kernel_hmc.proposals.base import ProposalBase, standard_sqrt_schedule
from kernel_hmc.tools.log import Log
import numpy as np


logger = Log.get_logger()

# low rank update depends on "cholupdate" optional dependency
try:
    from choldate._choldate import cholupdate
    cholupdate_available = True
except ImportError:
    cholupdate_available = False
    logger.warning("Package cholupdate not available. Adaptive Metropolis falls back to (more expensive) re-estimation of covariance.")

if cholupdate_available:
    def rank_one_update_mean_covariance_cholesky_lmbda(u, lmbda=.1, mean=None, cov_L=None, nu2=1., gamma2=None):
        """
        Returns updated mean and Cholesky of sum of outer products following a
        (1-lmbda)*old + lmbda* step_size*uu^T+lmbda*gamm2*I
        rule
        
        Optional: If gamma2 is given, an isotropic term gamma2 * I is added to the uu^T part
        
        where old mean and cov_L=Cholesky(old) (lower Cholesky) are given.
        
        Performs efficient rank-one updates of the Cholesky directly.
        """