From b8a09bfff7fa853a14ad52150dc06f67cd03b4d7 Mon Sep 17 00:00:00 2001 From: Neil Lawrence Date: Thu, 16 Oct 2014 15:45:10 +0100 Subject: [PATCH] Remove symbolic import. --- GPy/likelihoods/negative_binomial.py | 47 ------------------------- GPy/likelihoods/skew_exponential.py | 43 ----------------------- GPy/likelihoods/skew_normal.py | 52 ---------------------------- GPy/likelihoods/sstudent_t.py | 45 ------------------------ 4 files changed, 187 deletions(-) delete mode 100644 GPy/likelihoods/negative_binomial.py delete mode 100644 GPy/likelihoods/skew_exponential.py delete mode 100644 GPy/likelihoods/skew_normal.py delete mode 100644 GPy/likelihoods/sstudent_t.py diff --git a/GPy/likelihoods/negative_binomial.py b/GPy/likelihoods/negative_binomial.py deleted file mode 100644 index 7f00742b..00000000 --- a/GPy/likelihoods/negative_binomial.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2014 The GPy authors (see AUTHORS.txt) -# Licensed under the BSD 3-clause license (see LICENSE.txt) - - -try: - import sympy as sym - sympy_available=True - from sympy.utilities.lambdify import lambdify - from GPy.util.symbolic import gammaln, logisticln -except ImportError: - sympy_available=False - -import numpy as np -import link_functions -from symbolic import Symbolic -from scipy import stats - -class Negative_binomial(Symbolic): - """ - Negative binomial - - .. math:: - p(y_{i}|\pi(f_{i})) = \left(\frac{r}{r+f_i}\right)^r \frac{\Gamma(r+y_i)}{y!\Gamma(r)}\left(\frac{f_i}{r+f_i}\right)^{y_i} - - .. Note:: - Y takes non zero integer values.. - link function should have a positive domain, e.g. log (default). - - .. See also:: - symbolic.py, for the parent class - """ - def __init__(self, gp_link=None, dispersion=1.0): - parameters = {'dispersion':dispersion} - if gp_link is None: - gp_link = link_functions.Identity() - - dispersion = sym.Symbol('dispersion', positive=True, real=True) - y_0 = sym.Symbol('y_0', nonnegative=True, integer=True) - f_0 = sym.Symbol('f_0', positive=True, real=True) - gp_link = link_functions.Log() - log_pdf=dispersion*sym.log(dispersion) - (dispersion+y_0)*sym.log(dispersion+f_0) + gammaln(y_0+dispersion) - gammaln(y_0+1) - gammaln(dispersion) + y_0*sym.log(f_0) - #log_pdf= -(dispersion+y)*logisticln(f-sym.log(dispersion)) + gammaln(y+dispersion) - gammaln(y+1) - gammaln(dispersion) + y*(f-sym.log(dispersion)) - super(Negative_binomial, self).__init__(log_pdf=log_pdf, parameters=parameters, gp_link=gp_link, name='Negative_binomial') - - # TODO: Check this. - self.log_concave = False - diff --git a/GPy/likelihoods/skew_exponential.py b/GPy/likelihoods/skew_exponential.py deleted file mode 100644 index 170f5d14..00000000 --- a/GPy/likelihoods/skew_exponential.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) 2014 The GPy authors (see AUTHORS.txt) -# Licensed under the BSD 3-clause license (see LICENSE.txt) - - -import sympy as sym -#from GPy.util.symbolic import normcdfln -import numpy as np -import link_functions -from symbolic import Symbolic -from scipy import stats - -class Skew_exponential(Symbolic): - """ - Negative binomial - - .. math:: - - .. Note:: - Y takes real values. - link function is identity - - .. See also:: - symbolic.py, for the parent class - """ - def __init__(self, gp_link=None, shape=1.0, scale=1.0): - parameters={'scale':scale, 'shape':shape} - if gp_link is None: - gp_link = link_functions.Identity() - - #func_modules = [{'exp':clip_exp}] - - scale = sym.Symbol('scale', positive=True, real=True) - shape = sym.Symbol('shape', real=True) - y_0 = sym.Symbol('y_0', real=True) - f_0 = sym.Symbol('f_0', real=True) - log_pdf=sym.log(shape)-sym.log(scale)-((y_0-f_0)/scale) + normcdfln(shape*(y_0-f_0)/scale) - super(Skew_exponential, self).__init__(log_pdf=log_pdf, gp_link=gp_link, name='Skew_exponential', parameters=parameters) - - # TODO: Check this. - self.log_concave = True - - - diff --git a/GPy/likelihoods/skew_normal.py b/GPy/likelihoods/skew_normal.py deleted file mode 100644 index 6f400c7b..00000000 --- a/GPy/likelihoods/skew_normal.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) 2014 The GPy authors (see AUTHORS.txt) -# Licensed under the BSD 3-clause license (see LICENSE.txt) - - -try: - import sympy as sym - sympy_available=True - from sympy.utilities.lambdify import lambdify - from GPy.util.symbolic import normcdfln, normcdf -except ImportError: - sympy_available=False - -import numpy as np -from GPy.util.functions import clip_exp -import link_functions -from symbolic import Symbolic -from scipy import stats - -class Skew_normal(Symbolic): - """ - Skew Normal distribution. - - .. math:: - - .. Note:: - Y takes real values. - link function is identity - - .. See also:: - symbolic.py, for the parent class - """ - def __init__(self, gp_link=None, shape=1.0, scale=1.0): - parameters = {'scale': scale, 'shape':shape} - if gp_link is None: - gp_link = link_functions.Identity() - - # # this likelihood has severe problems with likelihoods saturating exponentials, so clip_exp is used in place of the true exp as a solution for dealing with the numerics. - # func_modules = [{'exp':clip_exp}] - func_modules = [] - - scale = sym.Symbol('scale', positive=True, real=True) - shape = sym.Symbol('shape', real=True) - y_0 = sym.Symbol('y_0', real=True) - f_0 = sym.Symbol('f_0', real=True) - log_pdf=-sym.log(scale)-1./2*sym.log(2*sym.pi)-1./2*((y_0-f_0)/scale)**2 + sym.log(2) + normcdfln(shape*(y_0-f_0)/scale) - super(Skew_normal, self).__init__(log_pdf=log_pdf, parameters=parameters, gp_link=gp_link, name='Skew_normal', func_modules=func_modules) - - self.log_concave = True - - - - diff --git a/GPy/likelihoods/sstudent_t.py b/GPy/likelihoods/sstudent_t.py deleted file mode 100644 index 790c1437..00000000 --- a/GPy/likelihoods/sstudent_t.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2014 The GPy authors (see AUTHORS.txt) -# Licensed under the BSD 3-clause license (see LICENSE.txt) - - -import sympy as sym -from sympy.utilities.lambdify import lambdify -# does not exist! JH from GPy.util.symbolic import gammaln - -import numpy as np -import link_functions -from symbolic import Symbolic -from scipy import stats - -class SstudentT(Symbolic): - """ - Symbolic variant of the Student-t distribution. - - .. math:: - - .. Note:: - Y takes real values. - link function is identity - - .. See also:: - symbolic.py, for the parent class - """ - def __init__(self, gp_link=None, deg_free=5.0, t_scale2=1.0): - parameters = {'deg_free':5.0, 't_scale2':1.0} - if gp_link is None: - gp_link = link_functions.Identity() - - # this likelihood has severe problems with likelihoods saturating ... - y_0 = sym.Symbol('y_0', real=True) - f_0 = sym.Symbol('f_0', real=True) - nu = sym.Symbol('nu', positive=True, real=True) - t_scale2 = sym.Symbol('t_scale2', positive=True, real=True) - log_pdf = (gammaln((nu + 1) * 0.5) - - gammaln(nu * 0.5) - - 0.5*sym.log(t_scale2 * nu * sym.pi) - - 0.5*(nu + 1)*sym.log(1 + (1/nu)*(((y_0-f_0)**2)/t_scale2))) - super(SstudentT, self).__init__(log_pdf=log_pdf, parameters=parameters, gp_link=gp_link, name='SstudentT') - self.log_concave = False - - -