Questions tagged [automatic-differentiation]

Also known as algorithmic differentiation, short AD. Techniques that take a procedure evaluating a numerical function and transform it into a procedure that additionally evaluates directional derivatives, gradients, higher order derivatives.

Also known as algorithmic differentiation, short AD. Techniques that take a procedure evaluating a numerical function and transform it into a procedure that additionally evaluates directional derivatives, gradients, higher order derivatives.

Techniques include operator

  • overloading for dual numbers,
  • operator overloading to extract the operations sequence as a tape,
  • code analysis and transformation.

For a function with input of dimension n and output of dimension n, requiring L elementary operations for its evaluation, one directional derivative or one gradient can be computed with 3*L operations.

The accuracy of the derivative is, automatically, nearly as good as the accuracy of the function evaluation.

Other differentiation method are

  • symbolic differentiation, where the expanded expression for the derivatives is obtained first, which can be large depending on the implementation, and
  • numerical differentiation by divided differences, which provides less accuracy with comparable effort, or comparable accuracy with a higher effort.

See wikipedia and autodiff.org

192 questions
7
votes
1 answer

Combining Eigen and CppAD

I want to use automatic differentiation mechanism provided by CppAD inside Eigen linear algebra. An example type is Eigen::Matrix< CppAD::AD,-1,-1>. As CppAD::AD is a custom numeric type the NumTraits for this type have to be provided. CppAD…
6
votes
0 answers

How to create an array-like class compatible with NumPy ufuncs?

I'm trying to implement Automatic Differentiation using a class that behaves like a NumPy array. It does not subclass numpy.ndarray, but contains two array attributes. One for the value, and one for the Jacobian matrix. Every operation is overloaded…
roessland
  • 61
  • 5
5
votes
1 answer

what is the difference between if-else statement and torch.where in pytorch?

See the code snippet: import torch x = torch.tensor([-1.], requires_grad=True) y = torch.where(x > 0., x, torch.tensor([2.], requires_grad=True)) y.backward() print(x.grad) The output is tensor([0.]), but import torch x = torch.tensor([-1.],…
gaussclb
  • 1,217
  • 3
  • 13
  • 26
5
votes
1 answer

How efficient/intelligent is Theano in computing gradients?

Suppose I have an artificial neural networks with 5 hidden layers. For the moment, forget about the details of the neural network model such as biases, the activation functions used, type of data and so on ... . Of course, the activation functions…
Amir
  • 10,600
  • 9
  • 48
  • 75
5
votes
3 answers

Derivative of a Higher-Order Function

This is in the context of Automatic Differentiation - what would such a system do with a function like map, or filter - or even one of the SKI Combinators? Example: I have the following function: def func(x): return sum(map(lambda a: a**x,…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
5
votes
1 answer

How to do automatic differentiation on hmatrix?

Sooooo ... as it turns out going from fake matrices to hmatrix datatypes turns out to be nontrivial :) Preamble for reference: {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ParallelListComp #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE…
fho
  • 6,787
  • 26
  • 71
5
votes
4 answers

Optimization issue, Nonlinear: automatic analytical Jacobian/Hessian from objective and constraints in R?

In R, is it possible to find the Jacobian/Hessian/sparsity pattern analytically when you provide just the objective function and constraints for an optimization problem? AMPL does this, and from what I hear even MATLAB can do this, but I don't know…
wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
5
votes
4 answers

Differential Operator usable in Matrix form, in Python module Sympy

We need two matrices of differential operators [B] and [C] such as: B = sympy.Matrix([[ D(x), D(y) ], [ D(y), D(x) ]]) C = sympy.Matrix([[ D(x), D(y) ]]) ans = B * sympy.Matrix([[x*y**2], [x**2*y]]) print…
5
votes
1 answer

Acceptable types in Numeric.AD functions

I'm having little success wrapping my head around the basic plumbing of the types involved in the ad package. For example, the following works perfectly: import Numeric.AD ex :: Num a => [a] -> a ex [x, y] = x + 2*y > grad ex [1.0, 1.0] [1.0,…
jtobin
  • 3,253
  • 3
  • 18
  • 27
4
votes
1 answer

Are reverse mode AD and forward mode AD the same function?

Hi I am old to programming but very new to Julia so the answer may be obvious. Forward Mode AD is often compared with the forward pass of a neural net, Reverse Mode AD is compared with back propagation and clearly you cannot replace back…
david streader
  • 589
  • 2
  • 7
4
votes
1 answer

Why Pytorch autograd need another vector to backward instead of computing Jacobian?

To perform backward in Pytorch, we can use an optional parameter y.backward(v) to compute the Jacobian matrix multiplied by v: x = torch.randn(3, requires_grad=True) y = x * 2 v = torch.tensor([0.1, 1.0, 0.0001],…
4
votes
1 answer

Computational graph vs (computer algebra) symbolic expression

I was reading Baydin et al, Automatic Differentiation in Machine Learning: a Survey, 2018 (Arxiv), which differentiates between symbolic differentiation and automatic differentiation (AD). It then says: AD Is Not Symbolic Differentiation. …
Albert
  • 65,406
  • 61
  • 242
  • 386
4
votes
1 answer

Using automatic differentiation on a function that makes use of a preallocated array in Julia

My long subject title pretty much covers it. I have managed to isolate my much bigger problem in the following contrived example below. I cannot figure out where the problem exactly is, though I imagine it has something to do with the type of the…
user1438310
  • 787
  • 4
  • 14
4
votes
1 answer

C++ reverse automatic differentiation with graph

I'm trying to make a reverse mode automatic differentiation in C++. The idea I came up with is that each variable that results of an operation on one or two other variables, is going to save the gradients in a vector. This is the code : class Var { …
Omar Aflak
  • 2,918
  • 21
  • 39
4
votes
1 answer

Automatic differentiation with ForwardDiff in Julia

I am having some trouble using correctly the ForwardDiff package in Julia. I have managed to isolate my problem in the following chunk of code. In short, I define the function: using ForwardDiff function likelihood(mu,X) N = size(X,2) #…
user1438310
  • 787
  • 4
  • 14
1
2
3
12 13