Skip to content

Automatic Higher Order Differentiation for Generic Julia Functions

License

Notifications You must be signed in to change notification settings

kgeoffrey/HigherOrderDerivatives.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HigherOrderDerivatives

Automatic higher order differentiation of generic Julia Functions. This repository contains an original implementation of (forward) automatic differentiation via dual numbers. Higher order derivatives are obtained by recursively chaining dual numbers together.

Example:

julia> using HigherOrderDerivatives

julia> f(x::Real) = exp(x^3 * cos(-x)^2 * sin(x));

julia> D = x -> derivative(f, x); # gives first derivative
julia> D⁹ = x -> derivative(f, x, 9); # gives 9th derivative

julia> D(0.8)
0.567190549030136

julia> D⁹(0.8)
-2.982695656166806e6

julia> g(x::Vector) = exp(x'*x)

julia> test = ones(4)

julia> grad = x -> gradient(g, x); # returns the gradient
julia> hess = x -> hessian(g, x); # hessian
julia> higher_grad = x,y -> gradient(g, x, y) ## returns the yth order gradient

julia> higher_grad(test, 3)

4x4x4 Array{Float64,3}:
[1091.9630006628847 655.1778003977308 655.1778003977308 655.1778003977308;
655.1778003977308 655.1778003977308 436.7852002651539 436.7852002651539;
655.1778003977308 436.7852002651539 655.1778003977308 436.7852002651539;
655.1778003977308 436.7852002651539 436.7852002651539 655.1778003977308]

[655.1778003977308 655.1778003977308 436.7852002651539 436.7852002651539;
655.1778003977308 1091.9630006628847 655.1778003977308 655.1778003977308;
436.7852002651539 655.1778003977308 655.1778003977308 436.7852002651539;
436.7852002651539 655.1778003977308 436.7852002651539 655.1778003977308]

[655.1778003977308 436.7852002651539 655.1778003977308 436.7852002651539;
436.7852002651539 655.1778003977308 655.1778003977308 436.7852002651539;
655.1778003977308 655.1778003977308 1091.9630006628847 655.1778003977308;
436.7852002651539 436.7852002651539 655.1778003977308 655.1778003977308]

[655.1778003977308 436.7852002651539 436.7852002651539 655.1778003977308;
436.7852002651539 655.1778003977308 436.7852002651539 655.1778003977308;
436.7852002651539 436.7852002651539 655.1778003977308 655.1778003977308;
655.1778003977308 655.1778003977308 655.1778003977308 1091.9630006628847]

About

Automatic Higher Order Differentiation for Generic Julia Functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages