stability enhancing clipping in logexp_clipped and reverse of stability clipping of parameters

This commit is contained in:
Max Zwiessele 2013-05-16 15:17:54 +01:00
parent 524c6e26bf
commit ba4bd50924
2 changed files with 46 additions and 45 deletions

View file

@ -39,17 +39,19 @@ class logexp(transformation):
return '(+ve)' return '(+ve)'
class logexp_clipped(transformation): class logexp_clipped(transformation):
max_bound = 1e300 max_bound = 1e10
min_bound = 1e-10
log_max_bound = np.log(max_bound) log_max_bound = np.log(max_bound)
def __init__(self, lower=1e-15): log_min_bound = np.log(min_bound)
def __init__(self, lower=1e-6):
self.domain = 'positive' self.domain = 'positive'
self.lower = lower self.lower = lower
def f(self, x): def f(self, x):
exp = np.exp(np.where(x > self.log_max_bound, self.log_max_bound, x)) exp = np.exp(np.clip(x, self.log_min_bound, self.log_max_bound))
f = np.log(1. + exp) f = np.log(1. + exp)
return f return f
def finv(self, f): def finv(self, f):
return np.log(np.exp(f) - 1.) return np.log(np.exp(np.clip(f, self.min_bound, self.max_bound)) - 1.)
def gradfactor(self, f): def gradfactor(self, f):
ef = np.exp(f) ef = np.exp(f)
gf = (ef - 1.) / ef gf = (ef - 1.) / ef

View file

@ -196,7 +196,6 @@ class kern(parameterised):
return np.hstack([p._get_params() for p in self.parts]) return np.hstack([p._get_params() for p in self.parts])
def _set_params(self, x): def _set_params(self, x):
x = np.clip(x, -1e300, 1e300)
[p._set_params(x[s]) for p, s in zip(self.parts, self.param_slices)] [p._set_params(x[s]) for p, s in zip(self.parts, self.param_slices)]
def _get_param_names(self): def _get_param_names(self):