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
0
votes
1 answer

How to link a C++11 program to the Adept library

Adept (http://www.met.reading.ac.uk/clouds/adept/) is a C++ library for automatic differentiation. The following example, placed in a file called home_page.cpp is taken from the home page for the library: #include #include…
0
votes
0 answers

Automatic Differentiation in R (or through any other means?)

I want to calculate the derivative of the following function: (plogis(-0.17283 + 0.0000471*x[1])*exp(9.53643)*(x[1])^0.468)+ (plogis(-0.17283 + 0.0000471*x[2])*exp(9.53643)*(x[2])^0.468)+ (plogis(-0.17283 +…
0
votes
1 answer

Inner workings of pytorch autograd.grad for inner derivatives

Consider the following code: x = torch.tensor(2.0, requires_grad=True) y = torch.square(x) grad = autograd.grad(y, x) x = x + grad[0] y = torch.square(x) grad2 = autograd.grad(y, x) First, we have that ∇(x^2)=2x. In my understanding, grad2=∇((x…
Schach21
  • 412
  • 4
  • 21
0
votes
1 answer

Function tf.test.compute_gradient shows unexpected behavior w.r.t the size of the perturbation delta

I am trying to use tf.test.compute_gradient to check if tf can properly differentiate my (rather complicated) custom loss function. However, tf.test.compute_gradient shows unexpected behavior w.r.t the size of the perturbation delta (dx…
0
votes
1 answer

How can I fix this problem of automated differentiation with Tensorflow?

I need to compute the gradient wrt a loss for the variables of a defined neural network, the loss is computed correctly but the gradients are None. The code is the following: variables = self.model.trainable_variables for var in variables: …
Giuseppe Boezio
  • 101
  • 1
  • 11
0
votes
1 answer

automatic differentiation used on 'real dataset' settles in false minima why?

Hi so I've a done a project where we use tensorflow in automatic differentiation. Using a fairly linear dataset generated with numpy like so: true_w, true_b = 7., 4. def create_batch(batch_size=64): x = np.random.randn(batch_size, 1) y =…
0
votes
0 answers

How to pre-allocate space for intermediate computation values within DynamicAutoDiffCostFunction?

I am using Ceres Solver for the non-linear least squares optimization of a model for which the number of parameters is not known at compile time. Because the number of parameters is not known at compile time, I implement the computation of the cost…
user1158795
  • 81
  • 1
  • 1
  • 5
0
votes
2 answers

Julia JuMP making sure nonlinear objective function has correct function signatures so that autodifferentiate works properly?

so I wrote a minimum example to show what I'm trying to do. Basically I want to solve a optimization problem with multiple variables. When I try to do this in JuMP I was having issues with my function obj not being able to take a forwardDiff…
Eigenvalue
  • 1,093
  • 1
  • 14
  • 35
0
votes
1 answer

Calling __exit_ after GradientTape(persistent=True)

I start recording the gradients with tf.GradientTape(persistent=True) in order be able to call gradient_tape.gradient() more than one time. Since this means that the gradients are not being released after calling the gradient() method, do I have to…
0
votes
0 answers

How to derive (get derivative) a function inside a function using Autograd?

I have a function that looks like this: def f(x, y): def g(w): def h(z): return z * (w ** 2) * (x + y) return h return g I want to calculate the partial derivatives of f w.r.t (x, y, w, z) at point say (x0, y0,…
0
votes
1 answer

Tensorflow custom gradient not giving expected answer

I am learning custom gradient in Tensorflow 1.14. I am testing it out by defining custom gradient for a simple ReLu function as follows: import numpy as np import tensorflow as tf @tf.custom_gradient def rateFunction(v_): z_ = tf.nn.relu(v_) …
0
votes
0 answers

Using Forward- ,Backward Automatic Differentiation to compute higher order derivatives

Im currently trying to wrap my head around Automatic Differentiation. I got to the point where i successfully implemented both forward and reverse mode autodiff. Now to my question: Given a function f i want to compute the second derivative. How…
0
votes
1 answer

Calculating jacobians and gradients using tensor flow

I'm trying to solve 2D Darcy equation which is a mixed formulation. Suppose I have a target vector and source vector as follows: u = [u1,u2,p] x = [x,y]. grad(u,x) = [du1/dx, du2/dx, dp/dx; du1/dy, du2/dy, dp/dy] I'm not understanding if this is…
0
votes
0 answers

RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn for non-neural network implementations

I am working on a project where I am getting some funny error with the automatic differentiator in Pytorch. I am trying to minimize a function with respect to x values. To do so, I use the code at the bottom of this post. As I understand it, I…
0
votes
1 answer

Is there any automatic way in MatLab for computing the gradient of a CNN wrt the inputs?

I have trained a shallow CNN using MatLab's Machine Learning Toolbox. The input of this CNN is an image and the output is an image too: f(x) = y, where x is the input image and y is the output image. The CNN simply reads as f(x) = ReLU(W * x +…