diff --git a/GPy/likelihoods/link_functions.py b/GPy/likelihoods/link_functions.py index 0eb05e74..0554bd93 100644 --- a/GPy/likelihoods/link_functions.py +++ b/GPy/likelihoods/link_functions.py @@ -138,6 +138,38 @@ class Probit(GPTransformation): input_dict["class"] = "GPy.likelihoods.link_functions.Probit" 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): """ diff --git a/GPy/testing/link_function_tests.py b/GPy/testing/link_function_tests.py index 9f41f736..8f3525b0 100644 --- a/GPy/testing/link_function_tests.py +++ b/GPy/testing/link_function_tests.py @@ -2,11 +2,12 @@ import numpy as np import scipy from scipy.special import cbrt from GPy.models import GradientChecker +import random _lim_val = np.finfo(np.float64).max _lim_val_exp = np.log(_lim_val) _lim_val_square = np.sqrt(_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): def setUp(self): @@ -123,6 +124,11 @@ class LinkFunctionTests(np.testing.TestCase): link = Probit() lim_of_inf = _lim_val 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): link = Cloglog()