Hello all,
I’m having some type constraint troubles, hoping someone here might have a suggestion for a workaround. For most distributions, the logpdf
is just an algebraic expression, which I need to be able to perform some basic manipulations on. There are a few options for doing this, but the one that so far seems most promising is @chakravala’s Reduce.jl, which wraps the external tool Reduce.
Because most of these are so simple, I had hoped to be able to pass a symbolic value to build a distribution, and then pass that and another symbolic value to logpdf
to end up with some symbolic expression.
Simple example:
# μ, σ, x are all symbolic
logpdf(Normal(μ,σ),x)
Type constraints are preventing this. Even if I bypass the distribution, I’m stuck with
normlogpdf(μ::Real, σ::Real, x::Number)
which, of course, doesn’t hold because the values are symbolic.
I had thought the obvious solution would be to make e.g., normlogpdf
more generic, possibly only exporting a type-constrained version. IIUC, this would present an identical interface with no loss in performance; the only difference would be the existence of an importable generic version handy for situations like this.
From some Slack discussion, there wasn’t much interest in this suggestion, so I’m trying to find a workaround. Some possibilities:
- Fork
StatsFuns.jl
and modify as needed. The introduces a new dependency to track and generally confuses things. - Copy lots of
StatsFuns
into my package and genericize them there. This way I could still use the original StatsFuns for most purposes, but I’d have generic versions for the algebraic stuff. - Find another CAS that allows type constraints (is there one?)
Any suggestions? Are there other options I’m missing?