• Stars
    star
    867
  • Rank 52,189 (Top 2 %)
  • Language
    Julia
  • License
    Other
  • Created over 11 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Forward Mode Automatic Differentiation for Julia

CI Coverage Status

ForwardDiff.jl

ForwardDiff implements methods to take derivatives, gradients, Jacobians, Hessians, and higher-order derivatives of native Julia functions (or any callable object, really) using forward mode automatic differentiation (AD).

While performance can vary depending on the functions you evaluate, the algorithms implemented by ForwardDiff generally outperform non-AD algorithms (such as finite-differencing) in both speed and accuracy.

Here's a simple example showing the package in action:

julia> using ForwardDiff

julia> f(x::Vector) = sin(x[1]) + prod(x[2:end]);  # returns a scalar

julia> x = vcat(pi/4, 2:4)
4-element Vector{Float64}:
 0.7853981633974483
 2.0
 3.0
 4.0

julia> ForwardDiff.gradient(f, x)
4-element Vector{Float64}:
  0.7071067811865476
 12.0
  8.0
  6.0

julia> ForwardDiff.hessian(f, x)
4×4 Matrix{Float64}:
 -0.707107  0.0  0.0  0.0
  0.0       0.0  4.0  3.0
  0.0       4.0  0.0  2.0
  0.0       3.0  2.0  0.0

Functions like f which map a vector to a scalar are the best case for reverse-mode automatic differentiation, but ForwardDiff may still be a good choice if x is not too large, as it is much simpler. The best case for forward-mode differentiation is a function which maps a scalar to a vector, like this g:

julia> g(y::Real) = [sin(y), cos(y), tan(y)];  # returns a vector

julia> ForwardDiff.derivative(g, pi/4)
3-element Vector{Float64}:
  0.7071067811865476
 -0.7071067811865475
  1.9999999999999998

julia> ForwardDiff.jacobian(x) do x  # anonymous function, returns a length-2 vector
         [sin(x[1]), prod(x[2:end])]
       end
2×4 Matrix{Float64}:
 0.707107   0.0  0.0  0.0
 0.0       12.0  8.0  6.0

See ForwardDiff's documentation for full details on how to use this package. ForwardDiff relies on DiffRules for the derivatives of many simple function such as sin.

See the JuliaDiff web page for other automatic differentiation packages.

Publications

If you find ForwardDiff useful in your work, we kindly request that you cite the following paper:

@article{RevelsLubinPapamarkou2016,
    title = {Forward-Mode Automatic Differentiation in {J}ulia},
   author = {{Revels}, J. and {Lubin}, M. and {Papamarkou}, T.},
  journal = {arXiv:1607.07892 [cs.MS]},
     year = {2016},
      url = {https://arxiv.org/abs/1607.07892}
}

More Repositories

1

BlueStyle

A Julia style guide that lives in a blue world
481
star
2

ChainRules.jl

forward and reverse mode automatic differentiation primitives for Julia Base + StdLibs
Julia
432
star
3

Diffractor.jl

Next-generation AD
Julia
431
star
4

ReverseDiff.jl

Reverse Mode Automatic Differentiation for Julia
Julia
343
star
5

TaylorSeries.jl

Taylor polynomial expansions in one and several independent variables.
Julia
323
star
6

FiniteDifferences.jl

High accuracy derivatives, estimated via numerical finite differences (formerly FDM.jl)
Julia
296
star
7

ChainRulesCore.jl

AD-backend agnostic system defining custom forward and reverse mode rules. This is the light weight core to allow you to define rules for your functions in your packages, without depending on any particular AD system.
Julia
250
star
8

FiniteDiff.jl

Fast non-allocating calculations of gradients, Jacobians, and Hessians with sparsity support
Julia
241
star
9

SparseDiffTools.jl

Fast jacobian computation through sparsity exploitation and matrix coloring
Julia
237
star
10

AbstractDifferentiation.jl

An abstract interface for automatic differentiation.
Julia
135
star
11

DualNumbers.jl

Julia package for representing dual numbers and for performing dual algebra
Julia
80
star
12

DiffRules.jl

A simple shared suite of common derivative definitions
Julia
74
star
13

TaylorDiff.jl

Taylor-mode automatic differentiation for higher-order derivatives
Julia
67
star
14

Capstan.jl

A Cassette-based automatic differentiation package for the Julia language
Julia
56
star
15

ChainRulesTestUtils.jl

Utilities for testing custom AD primitives.
Julia
50
star
16

HyperDualNumbers.jl

Julia implementation of HyperDualNumbers
Julia
42
star
17

DiffResults.jl

A package which provides an API for querying differentiation results at multiple orders simultaneously
Julia
35
star
18

PolyesterForwardDiff.jl

Julia
27
star
19

DiffTests.jl

A common suite of test functions for stressing the robustness of differentiation tools.
Julia
12
star
20

juliadiff.github.io

JavaScript
11
star
21

DocThemeIndigo.jl

The Documenter Theme for the ChainRules family of packages. But you can use it too
SCSS
8
star
22

ChainRulesOverloadGeneration.jl

Tools to help generate operator overloads based on ChainRules
Julia
4
star
23

ChainRulesDeclarationHelpers.jl

Helpers for declaring ChainRules
Julia
1
star