Skip to content

Changes to DifferentiableFunction API #287

Closed
@ahwillia

Description

@ahwillia

Now that PR #266 looks nearly complete, I'm hoping we can revisit issue #156 and a few other additions or changes I've been thinking about. I know @johnmyleswhite mentioned that he would like to change the API in the past (not sure if that was meant in a broader sense or not).

Minor / Low Priority:

  • As I brought up in switch argument order for gradient and hessian evaluations? #156 - I think it would be nice to switch the order of the arguments so that fg!(x, storage) becomes fg!(storage, x) (making the mutated argument come first seems more consistent with Julian conventions and autodiff packages).
  • I kind of like changing the names to OnceDifferentiable and TwiceDifferentiable for brevity (and clarity in the case of DifferentiableFunction which is a bit ambiguous). This could be handled with a depwarn, but maybe isn't worth it. We could also consider merging these into a single type (see some options below)

Higher Priority:

  • DifferentiableFunction and TwiceDifferentiableFunction should know about each other somehow. Some ideas:
abstract AbstractDifferientiable
type OnceDifferentiable <: AbstractDifferentable ...  end
type TwiceDifferentiable <: AbstractDifferentiable ... end
typealias Differentiable Union{OnceDifferentiable, TwiceDifferentiable}
# Merge OnceDifferentiable and TwiceDifferentiable ?
# This could be a problem for dispatching on one vs the other. But there are tricks to fix it.
type Differentiable
    f::Function
    g!::Function
    fg!::Function
    h!::Function
end
# Constructor for a once differentiable function 
Differentiable(f, g!, fg!) = Differentiable(f, g!, fg!, (x,s)->error("Not implemented") )
  • Specifying a differentiable function with autodiff options. The autodiff packages in Julia are coming along and I'd like the ability to do something along these lines:
f(x) = ... # my objective function
DifferentiableFunction(f, method=:autograd) # uses AutoGrad.jl
DifferentiableFunction(f, method=:forward) # uses ForwardDiff.jl
DifferentiableFunction(f, method=:central_diff) # uses finite central differencing

I'm not attached to using symbols - we could also dispatch on types if that is preferred.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions