# Source code for GPy.likelihoods.exponential

# Copyright (c) 2012-2014 GPy Authors

import numpy as np
from scipy import stats,special
import scipy as sp
from .likelihood import Likelihood

[docs]class Exponential(Likelihood):
"""
Expoential likelihood
Y is expected to take values in {0,1,2,...}
-----
$$L(x) = \exp(\lambda) * \lambda**Y_i / Y_i!$$
"""

"""

.. math::
p(y_{i}|\\lambda(f_{i})) = \\lambda(f_{i})\\exp (-y\\lambda(f_{i}))

:param y: data
:type y: Nx1 array
:returns: likelihood evaluated for this point
:rtype: float
"""
return np.exp(np.sum(np.log(log_objective)))

"""

.. math::
\\ln p(y_{i}|\lambda(f_{i})) = \\ln \\lambda(f_{i}) - y_{i}\\lambda(f_{i})

:param y: data
:type y: Nx1 array
:returns: likelihood evaluated for this point
:rtype: float

"""
return log_objective

"""

.. math::
\\frac{d \\ln p(y_{i}|\lambda(f_{i}))}{d\\lambda(f)} = \\frac{1}{\\lambda(f)} - y_{i}

:param y: data
:type y: Nx1 array
:returns: gradient of likelihood evaluated at points
:rtype: Nx1 array

"""

"""
The hessian will be 0 unless i == j

.. math::
\\frac{d^{2} \\ln p(y_{i}|\lambda(f_{i}))}{d^{2}\\lambda(f)} = -\\frac{1}{\\lambda(f_{i})^{2}}

:param y: data
:type y: Nx1 array
:returns: Diagonal of hessian matrix (second derivative of likelihood evaluated at points f)
:rtype: Nx1 array

.. Note::
Will return diagonal of hessian, since every where else it is 0, as the likelihood factorizes over cases
"""
return hess

"""

.. math::
\\frac{d^{3} \\ln p(y_{i}|\lambda(f_{i}))}{d^{3}\\lambda(f)} = \\frac{2}{\\lambda(f_{i})^{3}}

:param y: data
:type y: Nx1 array
:returns: third derivative of likelihood evaluated at points f
:rtype: Nx1 array
"""