-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing extra (constant) arguments to differentiated function #28
Comments
P.S. Trying to generalize, there are two possible cases:
The second case involves closures. Both cases have one aspect in common, that of passing arguments (such as |
One more thing, what I am actually trying to do ultimately is to use a functor as in
But then the following fails:
|
Good improvement ideas. Noted. |
Thanks a lot @fredo-dedup. It will become a bit clearer how this can be interfaced with Lora in the next week or so, as I am working on changing slightly function signatures in parameter methods to take a single argument using closures; we would still need to ignore some parameters when doing the differentiation. I will be able to be a bit more concrete with examples in a few days, once I make the needed changes... |
I know what is needed by now for Lora; a simple example below:
We want to be able to able to tell ReverseDiffSource to differentiate with respect to |
@fredo-dedup in order to better clarify what I meant, you may have a look at the example in Lora.jl/doc/examples/swiss/MALA.jl. The likelihood there takes two input arguments:
So we want to differentiate with respect to p and ignore the second input argument v (cell array). I added this comment here so that it can help understand what we want to achieve, for future reference. |
Hi, @fredo-dedup, I wanted to ask if this issue is part of your "todo" list or part of your near future plans. If you have a lot of work and can't get on top of it any time soon, may I suggest we make an effort to submit an idea for GSoC so that a student can push forward this issue as well as ReverseDiffSource? If you prefer to work on it at your own time though, it is fine of course. cc @mlubin |
I confirm it is still on my todo list. It doesn't seem to me to be big enough for a GSoC though, but I don't know much about the kind of projects that are typical. While we are at it: there are two ways I can think of to indicate that we do not want to differentiate with respect to one or several of the variables : 1) add an option to Solution 1) seems more generic and require less efforts from the user. Is this what you also had in mind ? Having 2) would be nice too, there could be use cases for that. But it seems like a convoluted way to solve this issue. |
Yes, @fredo-dedup, what you say makes sense, this specific issue seems too small to fill in a whole GSoC project, esp if it is part of your todo list in the long run. Besides, it looks you have developed your package well, so perhaps thinking of a GSoC project is a stretch. I also agree that solution 2 seems a bit more convoluted, solution 1 seems more transparent to me as a user. If solution 1 is easy to implement (and given that we both seem to find it a cleaner solution if not mistaken), it sounds the best way to proceed. |
I have updated the devl branch with a version of rdiff that takes an function ploglikelihood(p::Vector{Float64}, v::Vector)
Xp = v[2]*p
dot(Xp, v[3])-sum(log(1+exp(Xp)))
end
args = (ones(3), Any[1.,2.,[3.,2.,-2]])
dplog = m.rdiff( ploglikelihood, args, ignore=[:v;])
dplog(ones(3), Any[1.,2.,[3.,2.,-2]]) I'll push it to master and tag it if it solves your issue @Scidom. |
Thanks, @fredo-dedup! Yes, this would allow me to tackle all user cases and integrate completely your reverse autodiff with Lora! It would be great to push it to master and tag it. One quick question; from a user's perspective, the |
Unfortunately, the values are also required because I need to have the type of all the downstream variables and to do that I evaluate all the AST. |
Sure, @fredo-dedup, I only asked to enhance my understanding and to make sure I don't make any mistakes when I interface ReverseDiffSource with Lora, I didn't imply that a further change is needed in ReverseDiffSource (what you did above is great and solves the issue I had initially). So to be clear, in practice I need to ensure that |
Ok. To directly answer your question : yes, values are required, but no, their actual value do not matter, as long as the type is correct and the function/expression is evaluable at those values (i.e. in the support of the function). The initial condition of the MCMC will, by necessity, fit those constraints, but other values can, of course, be used. |
Thanks, @fredo-dedup, it makes sense now. Then the way you have coded this initialization is rather flexible and easy to cope with when calling ReverseDiffSource. Looking forward to the tagging! |
Solved in v0.2.2 (registration pending) |
Thanks @fredo-dedup! I am very excited about this update on ReverseDiffSource, it means it will be possible to reverse diff in Lora with non-trivial examples and with MCMC with higher order derivatives computed automatically (for ex SMMALA). Appreciated! |
@fredo-dedup I started familiarizing myself with your package, and it is really great. I'd like to suggest a feature. For now, ReverseDiffSource works well with one argument:
This is great but for Lora there is one more important use case. We may want to define a log-target
f
with more than one arguments. For example, we may want to defineDifferentiation will happen with respect to the first input argument
x
off
only. Subsequent arguments tof
, after the first one, will be ignored as far as autodiff goes. This way one may pass additional data tof
, which is useful in case of hyper-parameters, data and Gibbs.Would it be possible to consider extending ReverseDiffSource this way? If this is possible, it would be nice to make this functionality available both for expressions and function input. to
rdiff()
.The text was updated successfully, but these errors were encountered: