def __init__(self, gamma): Kernel.__init__(self) if type(gamma) is not float: raise TypeError("Gamma must be float") self.gamma = gamma
def __init__(self, rho, nu=1.5, sigma=1.0): Kernel.__init__(self) #GenericTests.check_type(rho,'rho',float) GenericTests.check_type(nu, 'nu', float) GenericTests.check_type(sigma, 'sigma', float) self.rho = rho self.nu = nu self.sigma = sigma
def __init__(self, rho, nu=1.5, sigma=1.0): Kernel.__init__(self) #GenericTests.check_type(rho,'rho',float) GenericTests.check_type(nu,'nu',float) GenericTests.check_type(sigma,'sigma',float) self.rho = rho self.nu = nu self.sigma = sigma
def __str__(self): s = self.__class__.__name__ + "=[" s += "p=" + str(self.p) s += "alpha=" + str(self.alpha) s += ", " + Kernel.__str__(self) s += "]" return s
def compute_constants(self, y): """ Precomputes constants of the log density of the proposal distribution, which is Gaussian as p(x|y) ~ N(mu, R) where mu = y -a a = 0 R = gamma^2 I + M M^T M = 2 [\nabla_x k(x,z_i]|_x=y Returns (mu,L_R), where L_R is lower Cholesky factor of R """ assert(len(shape(y))==1) # M = 2 [\nabla_x k(x,z_i]|_x=y if self.Z is None: R = self.gamma ** 2 * eye(len(y)) else: M = 2 * self.kernel.gradient(y, self.Z) # R = gamma^2 I + \nu^2 * M H M^T H = Kernel.centring_matrix(len(self.Z)) R = self.gamma ** 2 * eye(len(y)) + self.nu2 * M.T.dot(H.dot(M)) L_R = cholesky(R) return y.copy(), L_R
def __str__(self): s=self.__class__.__name__+ "=[" s += "p="+ str(self.p) s += "alpha="+ str(self.alpha) s += ", " + Kernel.__str__(self) s += "]" return s
def __str__(self): s = self.__class__.__name__ + "=[" s += "rho=" + str(self.rho) s += "nu=" + str(self.nu) s += "sigma=" + str(self.sigma) s += ", " + Kernel.__str__(self) s += "]" return s
def __str__(self): s=self.__class__.__name__+ "=[" s += "rho="+ str(self.rho) s += "nu="+ str(self.nu) s += "sigma="+ str(self.sigma) s += ", " + Kernel.__str__(self) s += "]" return s
def __init__(self, distribution, kernel, Z, nu2=0.1, gamma=0.1, num_eigen=10): Kameleon.__init__(self, distribution, kernel, Z, nu2, gamma) self.num_eigen = num_eigen if Z is None: self.Kc = None self.eigvalues = None self.eigvectors = None else: K = self.kernel.kernel(Z) H = Kernel.centring_matrix(len(self.Z)) self.Kc = H.dot(K.dot(H)) u, s, _ = svd(self.Kc) self.eigvalues = s[0 : self.num_eigen] self.eigvectors = u[:, 0 : self.num_eigen]
def construct_proposal(self, y): """ proposal is a mixture of normals, centred at y and with covariance gamma^2 I + nu^2 MHaa'HM', where a are the eigenvectors of centred kernel matrix Kc=HKH """ assert len(shape(y)) == 1 m = MixtureDistribution(self.distribution.dimension, self.num_eigen) m.mixing_proportion = Discrete((self.eigvalues + 1) / (sum(self.eigvalues) + self.num_eigen)) # print "current mixing proportion: ", m.mixing_proportion.omega M = 2 * self.kernel.gradient(y, self.Z) H = Kernel.centring_matrix(len(self.Z)) for ii in range(self.num_eigen): Sigma = self.gamma ** 2 * eye(len(y)) + self.nu2 * (M.T).dot( H.dot(outer(self.eigvectors[:, ii], self.eigvectors[:, ii]).dot(H.dot(M))) ) m.components[ii] = Gaussian(y, Sigma) return m
def construct_proposal(self, y): """ proposal is a mixture of normals, centred at y and with covariance gamma^2 I + nu^2 MHaa'HM', where a are the eigenvectors of centred kernel matrix Kc=HKH """ assert (len(shape(y)) == 1) m = MixtureDistribution(self.distribution.dimension, self.num_eigen) m.mixing_proportion = Discrete( (self.eigvalues + 1) / (sum(self.eigvalues) + self.num_eigen)) # print "current mixing proportion: ", m.mixing_proportion.omega M = 2 * self.kernel.gradient(y, self.Z) H = Kernel.centring_matrix(len(self.Z)) for ii in range(self.num_eigen): Sigma = self.gamma ** 2 * eye(len(y)) + \ self.nu2 * (M.T).dot(H.dot(outer(self.eigvectors[:, ii], self.eigvectors[:, ii]).dot(H.dot(M)))) m.components[ii] = Gaussian(y, Sigma) return m
def __init__(self, distribution, kernel, Z, nu2=0.1, gamma=0.1, num_eigen=10): Kameleon.__init__(self, distribution, kernel, Z, nu2, gamma) self.num_eigen = num_eigen if Z is None: self.Kc = None self.eigvalues = None self.eigvectors = None else: K = self.kernel.kernel(Z) H = Kernel.centring_matrix(len(self.Z)) self.Kc = H.dot(K.dot(H)) u, s, _ = svd(self.Kc) self.eigvalues = s[0:self.num_eigen] self.eigvectors = u[:, 0:self.num_eigen]
def __init__(self, distribution, n=200, kernel=GaussianKernel(3), nu2=0.1, \ gamma=0.1, ell=15, nXs=100, nYs=100): self.kernel = kernel self.distribution = distribution self.nu2 = nu2 self.gamma = gamma self.ell = ell # fix some samples self.Z = self.distribution.sample(n).samples # evaluate and center kernel and scale self.K = self.kernel.kernel(self.Z, None) self.K = Kernel.center_kernel_matrix(self.K) # sample beta self.rkhs_gaussian = Gaussian(mu=zeros(len(self.Z)), Sigma=self.K, is_cholesky=False, \ ell=self.ell) self.beta = self.rkhs_gaussian.sample().samples # plotting resolution [(xmin, xmax), (ymin, ymax)] = self.distribution.get_plotting_bounds() self.Xs = linspace(xmin, xmax, nXs) self.Ys = linspace(ymin, ymax, nYs)
def __init__(self, list_of_kernels): Kernel.__init__(self) self.list_of_kernels = list_of_kernels
def __init__(self): Kernel.__init__(self)
def __str__(self): s=self.__class__.__name__+ "=[" s += ", " + Kernel.__str__(self) s += "]" return s
def __init__(self, p=1, alpha=0.5, sigma=1.0): Kernel.__init__(self) self.p = p self.alpha = alpha self.sigma = sigma
def __init__(self, sigma): Kernel.__init__(self) self.width = sigma
def __str__(self): s = self.__class__.__name__ + "=[" s += ", " + Kernel.__str__(self) s += "]" return s
def __init__(self, degree,theta=0.2): Kernel.__init__(self) self.degree = degree self.theta = theta
def __init__(self, alpha=1.0): Kernel.__init__(self) GenericTests.check_type(alpha,'alpha',float) self.alpha = alpha