-
-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Some statistical modeling approaches rely on transforming variables to ℝⁿ. For example, if y ~ Gamma() we may instead work in terms of log(y). We can reason about this example statically from the AST (just have a function on symbols that takes :Gamma to log), and in general if we had a fixed set of distributions this would be no problem. It's more difficult when we have something like y ~ f(x); we need to know x, evaluate f(x) to determine a distribution, and then find the transformation for that.
One way to address this (and the best I have thought of so far) is to a sort of abstract interpretation based on random sampling from the model. This could, for example, turn y ~ f(x) into
dist = f(x)
y = rand(dist)
xforms[:y] = getTransform(dist)where xforms is a dictionary of the transformations that need to be done.
Because this determines transformations based on a random sample, it requires an additional restriction that supports must be static and cannot change from one execution to the next.
I'm using @thautwarm's MLStyle.jl quite a lot, and had thought a nice approach would be to use this to build a little interpreter to hook into.
But as I type this, the problem seems less challenging than it originally had. [Nice side effect of writing it down. Note to self: write more things down]
So for now I'll stick with the approach that has been working so far: generate code, @eval, and then invokelatest. There are clear problems with this -- global evaluation, execution overhead -- but we can keep hunting for a better approach and migrate everything to a new approach if an alternative becomes clear.