from kernel_hmc.mini_mcmc.mini_mcmc import mini_mcmc
from kernel_hmc.proposals.metropolis import StandardMetropolis,\
    AdaptiveMetropolis, KernelAdaptiveMetropolis
from kernel_hmc.tools.log import Log
import matplotlib.pyplot as plt
import numpy as np


# banana gradient depends on theano, which is an optional dependency
try:
    from kernel_hmc.densities.banana import Banana
    banana_available = True
except ImportError:
    banana_available = False

Log.set_loglevel(20)

if __name__ == '__main__':
    """
    This example shows how to run all Metropolis-Hastings sampler (including
    the Kernel Adaptive Metropolis-Hastings) from the paper on a simple target.
    """
    # possible to change
    D = 2
    N = 1000
    
    # target is banana density, fallback to Gaussian if theano is not present
    if banana_available:
        target = Banana(D=D)
    else:
        target = IsotropicZeroMeanGaussian(D=D)
예제 #2
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.
        """
예제 #3
0
from kernel_hmc.examples.plotting import visualise_trace
from kernel_hmc.mini_mcmc.mini_mcmc import mini_mcmc
from kernel_hmc.proposals.metropolis import StandardMetropolis,\
    AdaptiveMetropolis, KernelAdaptiveMetropolis
from kernel_hmc.tools.log import Log
import matplotlib.pyplot as plt
import numpy as np

# banana gradient depends on theano, which is an optional dependency
try:
    from kernel_hmc.densities.banana import Banana
    banana_available = True
except ImportError:
    banana_available = False

Log.set_loglevel(20)

if __name__ == '__main__':
    """
    This example shows how to run all Metropolis-Hastings sampler (including
    the Kernel Adaptive Metropolis-Hastings) from the paper on a simple target.
    """
    # possible to change
    D = 2
    N = 1000

    # target is banana density, fallback to Gaussian if theano is not present
    if banana_available:
        target = Banana(D=D)
    else:
        target = IsotropicZeroMeanGaussian(D=D)