mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-21 14:05:14 +02:00
added an exception when you input 0 or negative values to logtanh function
This commit is contained in:
parent
0d943ac98e
commit
347bcc963a
1 changed files with 9 additions and 1 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from ..core.parameterization import Parameterized, Param
|
from ..core.parameterization import Parameterized, Param
|
||||||
from paramz.transformations import Logexp
|
from paramz.transformations import Logexp
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class WarpingFunction(Parameterized):
|
class WarpingFunction(Parameterized):
|
||||||
|
|
@ -45,7 +46,11 @@ class WarpingFunction(Parameterized):
|
||||||
it = 0
|
it = 0
|
||||||
update = np.inf
|
update = np.inf
|
||||||
while np.abs(update).sum() > 1e-10 and it < max_iterations:
|
while np.abs(update).sum() > 1e-10 and it < max_iterations:
|
||||||
|
try:
|
||||||
fy = self.f(y)
|
fy = self.f(y)
|
||||||
|
except ValueError:
|
||||||
|
sys.stderr.write("One of y's is negative! Stopping inverse calculation.\n")
|
||||||
|
break
|
||||||
fgrady = self.fgrad_y(y)
|
fgrady = self.fgrad_y(y)
|
||||||
update = (fy - z) / fgrady
|
update = (fy - z) / fgrady
|
||||||
y -= self.rate * update
|
y -= self.rate * update
|
||||||
|
|
@ -204,6 +209,9 @@ class LogTanhFunction(WarpingFunction):
|
||||||
|
|
||||||
:math:`f = (y * d) + \\sum_{terms} a * tanh(b *(y + c))`
|
:math:`f = (y * d) + \\sum_{terms} a * tanh(b *(y + c))`
|
||||||
"""
|
"""
|
||||||
|
if (y <= 0.0).any():
|
||||||
|
sys.stderr.write("Negative y found!, raising exception.\n")
|
||||||
|
raise ValueError
|
||||||
d = self.d
|
d = self.d
|
||||||
mpsi = self.psi
|
mpsi = self.psi
|
||||||
z = d * np.log(y)
|
z = d * np.log(y)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue