JuliaMath / JuliaMath/MeasureTheory.jl

Code redundancy in parameterizations

Open
#23 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
401
Forks
31
PR merge metrics
No merged PRs in 30d

Description

We currently have `logdensity(::Normal)` as
```julia
function logdensity(d::Normal{P} , x::X) where {P <: NamedTuple{(:μ, :σ)}, X}
return - log(d.par.σ) - (x - d.par.μ)^2 / (2 * d.par.σ^2)
end

function logdensity(d::Normal{EmptyNamedTuple} , x::X) where {X}
return - x^2 / 2
end
```

There's a fair amount of redundancy here, and really no need for it. And many distributions have a `(:μ, :σ)` variant indicating a location and scale, so this is really not a one-off. In general, these log-likelihoods look like

```julia
ℓ(x; μ,σ) = ℓ((x-μ)/σ; 0,1) - log(σ)
```

Rather than write out each case, we should be able to only add the standard case, and have a macro add the location-scale parameterizations for us.

Also, there's a very easy way to get many of these log-densities:
https://gist.github.com/cscherrer/47f0fc7597b4ffc11186d54cc4d8e577

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.