module HasGP.Covariance.SquaredExp
(
SquaredExponential(..)
) where
import Numeric.LinearAlgebra
import HasGP.Types.MainTypes
import HasGP.Covariance.Basic
data SquaredExponential = SquaredExponential
{
f :: Double,
l :: Double
}
instance CovarianceFunction SquaredExponential where
trueHyper se = mapVector exp $ fromList [(f se), (l se)]
covariance se in1 in2 =
f2 * exp ((1/(2 * (l2^2))) * (diff <.> diff))
where
diff = in1 in2
f2 = exp (f se)
l2 = exp (l se)
dCovarianceDParameters se in1 in2 =
fromList [dLogByDF, dLogByDL]
where
diff = in1 in2
d = diff <.> diff
f2 = exp (f se)
l2 = exp (l se)
dLogByDF = exp ((1/(2 * (l2^2))) * d)
dLogByDL = f2 * dLogByDF * (d * (l2^^(3)))
makeCovarianceFromList se [f, l] = SquaredExponential f l
makeCovarianceFromList se _ =
error "SquaredExp requires exactly 2 hyperparameters"
makeListFromCovariance se = [f se, l se]