mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-05 01:32:40 +02:00
Added new link-function to enable derivative sign values as in Riihimaki & Vehtari (2010) paper
This commit is contained in:
parent
f4629c89cd
commit
d862fc71e2
2 changed files with 39 additions and 1 deletions
|
|
@ -138,6 +138,38 @@ class Probit(GPTransformation):
|
||||||
input_dict["class"] = "GPy.likelihoods.link_functions.Probit"
|
input_dict["class"] = "GPy.likelihoods.link_functions.Probit"
|
||||||
return input_dict
|
return input_dict
|
||||||
|
|
||||||
|
class ScaledProbit(Probit):
|
||||||
|
"""
|
||||||
|
.. math::
|
||||||
|
g(f) = \\Phi^{-1} (nu*mu)
|
||||||
|
"""
|
||||||
|
def __init__(self, nu=1.):
|
||||||
|
self.nu = float(nu)
|
||||||
|
|
||||||
|
def transf(self,f):
|
||||||
|
return std_norm_cdf(f*self.nu)
|
||||||
|
|
||||||
|
def dtransf_df(self,f):
|
||||||
|
return std_norm_pdf(f*self.nu)*self.nu
|
||||||
|
|
||||||
|
def d2transf_df2(self,f):
|
||||||
|
return -(f*self.nu) * std_norm_pdf(f*self.nu)*(self.nu**2)
|
||||||
|
|
||||||
|
def d3transf_df3(self,f):
|
||||||
|
return (safe_square(f*self.nu)-1.)*std_norm_pdf(f*self.nu)*(self.nu**3)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""
|
||||||
|
Convert the object into a json serializable dictionary.
|
||||||
|
|
||||||
|
Note: It uses the private method _save_to_input_dict of the parent.
|
||||||
|
|
||||||
|
:return dict: json serializable dictionary containing the needed information to instantiate the object
|
||||||
|
"""
|
||||||
|
|
||||||
|
input_dict = super(ScaledProbit, self)._save_to_input_dict()
|
||||||
|
input_dict["class"] = "GPy.likelihoods.link_functions.ScaledProbit"
|
||||||
|
return input_dict
|
||||||
|
|
||||||
class Cloglog(GPTransformation):
|
class Cloglog(GPTransformation):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@ import numpy as np
|
||||||
import scipy
|
import scipy
|
||||||
from scipy.special import cbrt
|
from scipy.special import cbrt
|
||||||
from GPy.models import GradientChecker
|
from GPy.models import GradientChecker
|
||||||
|
import random
|
||||||
_lim_val = np.finfo(np.float64).max
|
_lim_val = np.finfo(np.float64).max
|
||||||
_lim_val_exp = np.log(_lim_val)
|
_lim_val_exp = np.log(_lim_val)
|
||||||
_lim_val_square = np.sqrt(_lim_val)
|
_lim_val_square = np.sqrt(_lim_val)
|
||||||
_lim_val_cube = cbrt(_lim_val)
|
_lim_val_cube = cbrt(_lim_val)
|
||||||
from GPy.likelihoods.link_functions import Identity, Probit, Cloglog, Log, Log_ex_1, Reciprocal, Heaviside
|
from GPy.likelihoods.link_functions import Identity, Probit, Cloglog, Log, Log_ex_1, Reciprocal, Heaviside, ScaledProbit
|
||||||
|
|
||||||
class LinkFunctionTests(np.testing.TestCase):
|
class LinkFunctionTests(np.testing.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
@ -124,6 +125,11 @@ class LinkFunctionTests(np.testing.TestCase):
|
||||||
lim_of_inf = _lim_val
|
lim_of_inf = _lim_val
|
||||||
self.check_gradient(link, lim_of_inf, test_lim=True)
|
self.check_gradient(link, lim_of_inf, test_lim=True)
|
||||||
|
|
||||||
|
def test_scaledprobit_gradients(self):
|
||||||
|
link = ScaledProbit(nu=random.random())
|
||||||
|
lim_of_inf = _lim_val
|
||||||
|
self.check_gradient(link, lim_of_inf, test_lim=True)
|
||||||
|
|
||||||
def test_Cloglog_gradients(self):
|
def test_Cloglog_gradients(self):
|
||||||
link = Cloglog()
|
link = Cloglog()
|
||||||
lim_of_inf = _lim_val_exp
|
lim_of_inf = _lim_val_exp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue