{- | HasGP Gaussian Process Library. This module contains the definition 
     for the standard log logistic likelihood function.

     Copyright (C) 2011 Sean Holden. sbh11\@cl.cam.ac.uk.
-}
{- This file is part of HasGP.

   HasGP is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   HasGP is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with HasGP.  If not, see <http://www.gnu.org/licenses/>.
-}
module HasGP.Likelihood.LogLogistic 
   (
     LogLogistic(..)
   ) where

import Numeric.LinearAlgebra

import HasGP.Types.MainTypes
import HasGP.Support.Functions
import HasGP.Likelihood.Basic

{- | Value and first three derivatives of log sigmoid with respect to its 
     parameter f. log p(y|f) = log sigmoid (yf) where y is +1 or -1.
-}
data LogLogistic = LogLogistic

instance LogLikelihood LogLogistic where
    likelihood    LogLogistic y f = log (1 / (1 + (exp (-(f * y)))))
    dLikelihood   LogLogistic y f = ((y + 1) / 2) - (sigmoid f)
    ddLikelihood  LogLogistic y f = (-x) * (1 - x)
        where x = sigmoid f
    dddLikelihood LogLogistic y f = (exp (-f)) * (x^2) * ((2 * x) - 1)
        where x = sigmoid f