fixing the logexp (with MZ) and some stability issue in the stationary class

This commit is contained in:
James Hensman 2014-03-21 15:23:49 +00:00
parent 22dafabca2
commit 01271e3868
2 changed files with 7 additions and 12 deletions

View file

@ -7,10 +7,10 @@ from domains import _POSITIVE,_NEGATIVE, _BOUNDED
import weakref import weakref
import sys import sys
#_lim_val = -np.log(sys.float_info.epsilon)
_exp_lim_val = np.finfo(np.float64).max _exp_lim_val = np.finfo(np.float64).max
_lim_val = np.log(_exp_lim_val) _lim_val = 36.0
epsilon = np.finfo(np.float64).resolution
#=============================================================================== #===============================================================================
# Fixing constants # Fixing constants
@ -54,19 +54,19 @@ class Transformation(object):
class Logexp(Transformation): class Logexp(Transformation):
domain = _POSITIVE domain = _POSITIVE
def f(self, x): def f(self, x):
return np.where(x>_lim_val, x, np.log(1. + np.exp(np.clip(x, -_lim_val, _lim_val)))) return np.where(x>_lim_val, x, np.log(1. + np.exp(np.clip(x, -_lim_val, _lim_val)))) + epsilon
#raises overflow warning: return np.where(x>_lim_val, x, np.log(1. + np.exp(x))) #raises overflow warning: return np.where(x>_lim_val, x, np.log(1. + np.exp(x)))
def finv(self, f): def finv(self, f):
return np.where(f>_lim_val, f, np.log(np.exp(f+1e-20) - 1.)) return np.where(f>_lim_val, f, np.log(np.exp(f+1e-20) - 1.))
def gradfactor(self, f): def gradfactor(self, f):
return np.where(f>_lim_val, 1., 1 - np.exp(-f)) return np.where(f>_lim_val, 1., 1. - np.exp(-f))
def initialize(self, f): def initialize(self, f):
if np.any(f < 0.): if np.any(f < 0.):
print "Warning: changing parameters to satisfy constraints" print "Warning: changing parameters to satisfy constraints"
return np.abs(f) return np.abs(f)
def __str__(self): def __str__(self):
return '+ve' return '+ve'
class LogexpNeg(Transformation): class LogexpNeg(Transformation):
domain = _POSITIVE domain = _POSITIVE
@ -98,7 +98,7 @@ class NegativeLogexp(Transformation):
return -self.logexp.initialize(f) # np.abs(f) return -self.logexp.initialize(f) # np.abs(f)
def __str__(self): def __str__(self):
return '-ve' return '-ve'
class LogexpClipped(Logexp): class LogexpClipped(Logexp):
max_bound = 1e100 max_bound = 1e100
min_bound = 1e-10 min_bound = 1e-10

View file

@ -152,12 +152,7 @@ class Stationary(Kern):
This term appears in derviatives. This term appears in derviatives.
""" """
dist = self._scaled_dist(X, X2).copy() dist = self._scaled_dist(X, X2).copy()
if X2 is None: return 1./np.where(dist != 0., dist, np.inf)
nondiag = util.diag.offdiag_view(dist)
nondiag[:] = 1./nondiag
return dist
else:
return 1./np.where(dist != 0., dist, np.inf)
def gradients_X(self, dL_dK, X, X2=None): def gradients_X(self, dL_dK, X, X2=None):
""" """