From 831d5cdc2d6f20147d4669e1c523adaf14b57be9 Mon Sep 17 00:00:00 2001 From: WawerOS Date: Tue, 19 Apr 2022 03:28:42 -0500 Subject: [PATCH 1/2] Added a implementation of likelihood for the Student t distribution --- src/likelihoods/studentt.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/likelihoods/studentt.jl diff --git a/src/likelihoods/studentt.jl b/src/likelihoods/studentt.jl new file mode 100644 index 00000000..c672f703 --- /dev/null +++ b/src/likelihoods/studentt.jl @@ -0,0 +1,14 @@ + +using SpecialFunctions :: logbeta +using IrrationalConstants :: logπ, + +struct StudentTLikelihood{T<:Real, Tn :: Real} <: AbstractLikelihood + σ²::Vector{T} + ν::Vector{Tn} +end + +function expected_loglikelihood( ::AnalyticExpectation,lik::StudentTLikelihood,q_f :: AbstractVector{<:Normal}, y :: AbstractVector{<:Real}) + f_μ = mean.(q_f) + # Why? + return sum(-logbeta(0.5,0.5*lik.ν) .- 0.5*logπ .- 0.5*log(lik.ν) .- log(lik.σ²) .- (0.5*(lik.ν+1))*log.(1 .+ ((y .- f_μ).^2 + var.(q_f)) / lik.σ²) ) +end \ No newline at end of file From f5d4d3e099b847242bda2dd4ff6c1d0f3be459cf Mon Sep 17 00:00:00 2001 From: WawerOS Date: Tue, 19 Apr 2022 03:46:28 -0500 Subject: [PATCH 2/2] added come documentation --- src/likelihoods/studentt.jl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/likelihoods/studentt.jl b/src/likelihoods/studentt.jl index c672f703..fafd0046 100644 --- a/src/likelihoods/studentt.jl +++ b/src/likelihoods/studentt.jl @@ -2,6 +2,18 @@ using SpecialFunctions :: logbeta using IrrationalConstants :: logπ, + +""" + StudentTLikelihood(σ²,ν) + +Student's T likelihood with `σ²` scale and ν degrees of freedom . This is to be used if we assume that the +uncertainity associated with the data follows a Student's T distribution. + +```math + p(y|f) = \\operatorname{Student}(y | f, σ², ν) +``` +""" + struct StudentTLikelihood{T<:Real, Tn :: Real} <: AbstractLikelihood σ²::Vector{T} ν::Vector{Tn} @@ -10,5 +22,8 @@ end function expected_loglikelihood( ::AnalyticExpectation,lik::StudentTLikelihood,q_f :: AbstractVector{<:Normal}, y :: AbstractVector{<:Real}) f_μ = mean.(q_f) # Why? - return sum(-logbeta(0.5,0.5*lik.ν) .- 0.5*logπ .- 0.5*log(lik.ν) .- log(lik.σ²) .- (0.5*(lik.ν+1))*log.(1 .+ ((y .- f_μ).^2 + var.(q_f)) / lik.σ²) ) -end \ No newline at end of file + return sum(-logbeta(0.5,0.5*lik.ν) .- 0.5*logπ .- 0.5*log(lik.ν) .- log(lik.σ²) .- (0.5*(lik.ν+1))*log.(1 .+ ((y .- f_μ).^2 + var.(q_f)) / lik.σ²)) +end + + +default_expectation_method(::StudentTLikelihood) = AnalyticExpectation() \ No newline at end of file