-
Notifications
You must be signed in to change notification settings - Fork 41
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
Unify passing of optional parts of the objective in high-level solver interfaces #381
Comments
I thought about this for a while, and it seems most-unified to put the We though have to decide whether |
I don't have a strong opinion about it. Your solution looks fine though mutating a keyword argument may indeed be a bit surprising. |
The mutating keyword is the one thing I to not like so much, but I also do not like to move mandatory things like the Hessian to keywords. So I am myself a bit divided here. |
I think I have an idea that even makes the objective a bit more flexible and maybe even reduces code duplication. Similar to the IN general the user does not have to think about that, we would just have one further dispatch in between
wherever possible without introducing ambiguities. Whenever ambiguities occur, we would require the HessienFunction to be specified (instead of being a function or untyped). But there is more. We could even do
and hence have a more fine granular usage of in-place and allocating functions. The (objective wide) old evaluation would be the default, but you could specify that you have an in-place gradient but an allocating Hessian this way. Not sure whether theta useful, but it is a bit more flexible. I feel this would also be a very least breaking thing – but a bit of a rework as well. What do you think? |
Maybe it would be nicer to introduce a two-level scheme here instead of wrappers, for example difference_of_convex_algorithm(M, f, g, ∂h, p=rand(M); kwargs...) = _difference_of_convex_algorithm(M, f, g, ∂h, p; kwargs...) There would be even less room for ambiguity and no need for new wrappers. |
I am not yet so sure how that helps, but I can think about how that might be meant. |
But you might be right that function types are maybe overcomplicating things – the main idea comes from maybe indeed “typing the Hessian” (though not in this but the other signatures. |
If the user doesn't use those wrappers, they don't help with user-facing ambiguities either I think. If there is an ambiguity, the user can already construct the objective themselves and avoid it. That would probably be the easiest way to resolve such ambiguities. |
I do not yet see how your dispatch solves the problem with the ambiguity to In most cases the user would not need the |
I didn't know we have an ambiguity when passing the full objective? When does it occur? Anyway, I haven't thought about it particularly deeply but I don't see if introducing a new type really solves any problem that can't be solved with what we have. |
So there are two problems: sometimes objectives & start point |
I added all cases (14) above and investigated them
|
Why not wrapping the number
It would be easier to restrict here |
Just fixing For the Hessian: Thatsounds like a solution and would not even be breaking, great :) will add that to the documentation thenhowever. |
As a continuation of #379, in order to reduce the ambiguities, we should unify how optional elements of the objective are passed.
For example TCG has 7 signatures – the Hessian, the base point p and the start point X are optional, but positional rguemnts, and any of these can be left out.
On the other hand the difference of convex algorithm there are two signatures
this can be enhanced by for example passing the gradient of
g
(to get the subproblem automatically generated) or the gradient off
(to get better debug), but all these are keyword arguments.This should become the default, to reduce possibilities of ambiguity.
Second, there is often an ambiguity for the case where the points are not arrays but numbers and we provide a wrapper; this happens, when just the cost (or in general only one element like a gradient) is necessary for the objective (like in particle swarm).
And idea to resolve this is more like an internal redesign – we could introduce a keyword argument
iterate_type=:Number
that is set to number if the iterate is number and dispatch on the value internally. That way the dispatch does not happen on the high-level interface. This would even allow users with “non-Number
-eltypes that are not arrays” to benefit from the idea of “wrapping into mutable arrays” automatically.Hopefully this second idea can be done non-breaking; the first is breaking for sure.
Edit
To be precise the ambiguity errors are
Number
p, on the other hand we also do not want to typegrad_h
.f
being untyped and/or we do not want to specialise a swarm of numbers on a already generated objective.f
andgrad_f
since we also havep
andX
).The text was updated successfully, but these errors were encountered: