# \#differentiation

**URL:** https://discourse.julialang.org/tag/differentiation/110.md?page=2

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 3

---

## [How to take the gradient of one output and keep the other outputs?](https://discourse.julialang.org/t/how-to-take-the-gradient-of-one-output-and-keep-the-other-outputs/63597)

<div class="topic-metadata">

**Author:** [@SvenDummer](https://discourse.julialang.org/u/SvenDummer)\
**Replies:** 0\
**Last updated:** [June 26, 2021, 8:59am UTC](https://discourse.julialang.org/t/how-to-take-the-gradient-of-one-output-and-keep-the-other-outputs/63597 "2021-06-26T08:59:30Z")

</div>

Hi all. I have a (relatively) small question regarding automatic differentiation packages. The problem: I have a function that outputs a Hessian and the corresponding Laplacian. I want to take the gradient concerning t…

---

## [Differentiation without explicit function (np.gradient)](https://discourse.julialang.org/t/differentiation-without-explicit-function-np-gradient/57784)

<div class="topic-metadata">

**Author:** [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Replies:** 8\
**Last updated:** [June 12, 2021, 9:14am UTC](https://discourse.julialang.org/t/differentiation-without-explicit-function-np-gradient/57784 "2021-06-12T09:14:46Z")

</div>

Hi everyone, I am currently looking to evaluate some numerical data and need a method similar to numpy.gradient. All the packages, I have found seem to assume that I have some continuous function that I can evaluate at…

---

## [Custom NeuralODE layer trains innefficiently](https://discourse.julialang.org/t/custom-neuralode-layer-trains-innefficiently/61602)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 2\
**Last updated:** [June 4, 2021, 3:13pm UTC](https://discourse.julialang.org/t/custom-neuralode-layer-trains-innefficiently/61602 "2021-06-04T15:13:21Z")

</div>

I slightly changed a NeuralODE layer and added a few new weights parameters, but it can’t fit the simple data and show the warning ┌ Warning: dt \<= dtmin. Aborting. There is either an error in your model specification …

---

## [How to implement AD for this function?](https://discourse.julialang.org/t/how-to-implement-ad-for-this-function/60623)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 9\
**Last updated:** [May 7, 2021, 9:03am UTC](https://discourse.julialang.org/t/how-to-implement-ad-for-this-function/60623 "2021-05-07T09:03:51Z")

</div>

I am solving a system of equations with the iterative proportional fitting procedure. That means that at each iteration I solve for a subset of the variables μ0m, then hold those fixed and solve for the other subset of v…

---

## [Calculating specific components of gradients](https://discourse.julialang.org/t/calculating-specific-components-of-gradients/59733)

<div class="topic-metadata">

**Author:** [@schaerfo](https://discourse.julialang.org/u/schaerfo)\
**Replies:** 4\
**Last updated:** [April 23, 2021, 7:10pm UTC](https://discourse.julialang.org/t/calculating-specific-components-of-gradients/59733 "2021-04-23T19:10:17Z")

</div>

Occasionally, I work with scalar-valued functions that take multiple vectors as arguments. A simple example is: f(\\mathbf{x}, \\mathbf{y}) = e^{-|\\mathbf{x}-\\mathbf{y}|^2} In Julia, this can be coded as: f(x, y) = exp…

---

## [Flux gradients intepretation](https://discourse.julialang.org/t/flux-gradients-intepretation/58925)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 1\
**Last updated:** [April 9, 2021, 4:20pm UTC](https://discourse.julialang.org/t/flux-gradients-intepretation/58925 "2021-04-09T16:20:25Z")

</div>

There is a code for simple RNN network using Flux rnn = Flux.RNN(2, 3) seq = \[rand(Float32,2) for i = 1:3\] y = \[ones(Float32, 3) for i=1:3\] function loss(x, y) a = flat\_this((rnn.(x) .- y)) \_loss = sum(abs2, a)…

---

## [Set model parameters as Dictionary and define some as trainable](https://discourse.julialang.org/t/set-model-parameters-as-dictionary-and-define-some-as-trainable/58910)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 0\
**Last updated:** [April 9, 2021, 9:02am UTC](https://discourse.julialang.org/t/set-model-parameters-as-dictionary-and-define-some-as-trainable/58910 "2021-04-09T09:02:51Z")

</div>

I defined the following model with a dictionary containing weights mutable struct Affine params end Affine(in::Integer, out::Integer) = Affine(Dict("W"=\>randn(out, in), ("b"=\>randn(out)))) # Overload call, so the …

---

## [Fast Hessian size increase](https://discourse.julialang.org/t/fast-hessian-size-increase/57560)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 6\
**Last updated:** [March 19, 2021, 6:58pm UTC](https://discourse.julialang.org/t/fast-hessian-size-increase/57560 "2021-03-19T18:58:15Z")

</div>

I’d like to compute the Hessian for array values and to get some array with dimension (2,2) but instead I got this julia\> hessian(x -\> sum(x.^3), \[1 2; 3 4\]) # uses linear indexing of x 4×4 Array{$Int,2}: 6 0 0 …

---

## [Why is SUM always used in differentiation?](https://discourse.julialang.org/t/why-is-sum-always-used-in-differentiation/57559)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 3\
**Last updated:** [March 19, 2021, 6:54pm UTC](https://discourse.julialang.org/t/why-is-sum-always-used-in-differentiation/57559 "2021-03-19T18:54:55Z")

</div>

I’ve seen a lot of examples where the output of a NN or any function during the differentiation is preprocessed with sum operator. For example this: julia\> hessian(x -\> sum(x.^3), \[1 2; 3 4\]) # uses linear indexing of …

---

## [How is differentiation of implicit parameters implemented in Flux.jl?](https://discourse.julialang.org/t/how-is-differentiation-of-implicit-parameters-implemented-in-flux-jl/56656)

<div class="topic-metadata">

**Author:** [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Replies:** 0\
**Last updated:** [March 7, 2021, 6:16am UTC](https://discourse.julialang.org/t/how-is-differentiation-of-implicit-parameters-implemented-in-flux-jl/56656 "2021-03-07T06:16:54Z")

</div>

In the document of Flux.jl an example of differentiation of implicit parameters is given as follows: julia\> x = \[2, 1\]; julia\> y = \[2, 0\]; julia\> gs = gradient(params(x, y)) do f(x, y) end Grads(...) …

---

## [Gradient of NN not changing with different inputs](https://discourse.julialang.org/t/gradient-of-nn-not-changing-with-different-inputs/56435)

<div class="topic-metadata">

**Author:** [@edwinb-ai](https://discourse.julialang.org/u/edwinb-ai)\
**Replies:** 2\
**Last updated:** [March 3, 2021, 8:12pm UTC](https://discourse.julialang.org/t/gradient-of-nn-not-changing-with-different-inputs/56435 "2021-03-03T20:12:28Z")

</div>

While playing around with some neural networks (NN) I found out this using Flux using Random using Zygote using ForwardDiff Random.seed!(9120) n = 1 m = 5 hidden = 10 x, y = rand(m), rand(n) # some data model = Flux.…

---

## [How to use Manifold projection in differential equations jl](https://discourse.julialang.org/t/how-to-use-manifold-projection-in-differential-equations-jl/55681)

<div class="topic-metadata">

**Author:** [@manvibharat](https://discourse.julialang.org/u/manvibharat)\
**Replies:** 3\
**Last updated:** [February 21, 2021, 10:43am UTC](https://discourse.julialang.org/t/how-to-use-manifold-projection-in-differential-equations-jl/55681 "2021-02-21T10:43:55Z")

</div>

Hi all. I am trying to simulate a geometric control which we proposed in our paper. Since it involves a differential equation evolving on a manifold. I thought of using manifold projection as mentioned in Callback Librar…

---

## [Understanding the performance of Zygote](https://discourse.julialang.org/t/understanding-the-performance-of-zygote/55447)

<div class="topic-metadata">

**Author:** [@Himanshu\_Chaudhary](https://discourse.julialang.org/u/Himanshu_Chaudhary)\
**Replies:** 1\
**Last updated:** [February 18, 2021, 10:37am UTC](https://discourse.julialang.org/t/understanding-the-performance-of-zygote/55447 "2021-02-18T10:37:27Z")

</div>

I remember reading somewhere that the cost of automatic differentiation is usually less than 2 times the cost of evaluating the function itself. I tried to benchmark a small code and the results that I got were a little…

---

## [Turing.jl, differentiation & categorical outputs -- \`isprobvec\` conundrum](https://discourse.julialang.org/t/turing-jl-differentiation-categorical-outputs-isprobvec-conundrum/54083)

<div class="topic-metadata">

**Author:** [@delehef](https://discourse.julialang.org/u/delehef)\
**Replies:** 5\
**Last updated:** [February 8, 2021, 6:12pm UTC](https://discourse.julialang.org/t/turing-jl-differentiation-categorical-outputs-isprobvec-conundrum/54083 "2021-02-08T18:12:51Z")

</div>

Hi all, I met a strange bug, and, to be honest, I’m relatively new to the language, so it could be a mistake from my part. So, I’m having a real blast playing with bayesian NNs, and I’m slowly building up from the basi…

---

## [Repeatedly calculating a hessian using both ForwardDiff and ReverseDiff](https://discourse.julialang.org/t/repeatedly-calculating-a-hessian-using-both-forwarddiff-and-reversediff/54051)

<div class="topic-metadata">

**Author:** [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Replies:** 3\
**Last updated:** [February 2, 2021, 1:28pm UTC](https://discourse.julialang.org/t/repeatedly-calculating-a-hessian-using-both-forwarddiff-and-reversediff/54051 "2021-02-02T13:28:52Z")

</div>

I would like to calculate a Hessian matrix of a function f:\\mathbb{R}^n \\rightarrow \\mathbb{R} where n\\gg1. In my usecase the Jacobian of f is always needed, and the Hessian may or may not be needed (but this is known be…

---

## [How to avoid ForwardDiff.jl generating a second-order derivative that wastes flops by eventually multiplying by zero](https://discourse.julialang.org/t/how-to-avoid-forwarddiff-jl-generating-a-second-order-derivative-that-wastes-flops-by-eventually-multiplying-by-zero/53845)

<div class="topic-metadata">

**Author:** [@schneiderfelipe](https://discourse.julialang.org/u/schneiderfelipe)\
**Replies:** 10\
**Last updated:** [January 25, 2021, 2:28am UTC](https://discourse.julialang.org/t/how-to-avoid-forwarddiff-jl-generating-a-second-order-derivative-that-wastes-flops-by-eventually-multiplying-by-zero/53845 "2021-01-25T02:28:23Z")

</div>

I played around with second derivatives and ForwardDiff.jl and found something unexpected, so I would like to ask about it. Basically, the generated LLVM representation is multiplying a whole code branch by zero before r…

---

## [CUDA.jl Differentiation Error](https://discourse.julialang.org/t/cuda-jl-differentiation-error/53011)

<div class="topic-metadata">

**Author:** [@Honza9723](https://discourse.julialang.org/u/Honza9723)\
**Replies:** 5\
**Last updated:** [January 12, 2021, 1:28pm UTC](https://discourse.julialang.org/t/cuda-jl-differentiation-error/53011 "2021-01-12T13:28:17Z")

</div>

Dear All, while working on my project (epidemic model, solved using PINN), I tried to port my code to GPU. While function (loss function of my neural network) works and delivers reasonable speed up, while computing grad…

---

## [Gradient of Neural Network wrapper can't be taken](https://discourse.julialang.org/t/gradient-of-neural-network-wrapper-cant-be-taken/53061)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 0\
**Last updated:** [January 8, 2021, 8:12pm UTC](https://discourse.julialang.org/t/gradient-of-neural-network-wrapper-cant-be-taken/53061 "2021-01-08T20:12:34Z")

</div>

I use the following wrapper for neural network nn = Chain(Dense(2, 64, relu), Dense(64, 1)) function wrapper\_nn(state) q, q\_t = state dfdx(x,x\_t) = ForwardDiff.derivative(x -\> nn(\[x, x\_t\]), x) #qtt = nn(\[q, …

---

## [Derivative with respect to specified element of a vector](https://discourse.julialang.org/t/derivative-with-respect-to-specified-element-of-a-vector/53045)

<div class="topic-metadata">

**Author:** [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Replies:** 2\
**Last updated:** [January 8, 2021, 3:34pm UTC](https://discourse.julialang.org/t/derivative-with-respect-to-specified-element-of-a-vector/53045 "2021-01-08T15:34:58Z")

</div>

For example, I have the following function function test\_fun(state) x, y = state # 2 values \[x\*y^2\] end state = \[2,3\] test\_fun(state) I’d like to find the mixed derivative \\frac{d^2f}{dxdy} for vector case. I…

---

## [Method Error: No mathching method when using ContinuousDynamicalSystem](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040)

<div class="topic-metadata">

**Author:** [@Gary\_McCormack](https://discourse.julialang.org/u/Gary_McCormack)\
**Replies:** 7\
**Last updated:** [December 19, 2020, 4:31pm UTC](https://discourse.julialang.org/t/method-error-no-mathching-method-when-using-continuousdynamicalsystem/52040 "2020-12-19T16:31:56Z")

</div>

Hi everyone, I’m very new to Julia and trying to wrap my head around the following error. This is a stripped-down version of the ODE I am trying to wrap as a Continuous Dynamical System. using DifferentialEquations usi…

---

## [ReverseDiff: differentiating a function with an indexing argument](https://discourse.julialang.org/t/reversediff-differentiating-a-function-with-an-indexing-argument/51530)

<div class="topic-metadata">

**Author:** [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Replies:** 5\
**Last updated:** [December 15, 2020, 12:09pm UTC](https://discourse.julialang.org/t/reversediff-differentiating-a-function-with-an-indexing-argument/51530 "2020-12-15T12:09:52Z")

</div>

I am looking to move from using ForwardDiff to ReverseDiff due to the speedup provided by compiled tapes. I would like to differentiate a function where one of the arguments is an index of the output, and then compile th…

---

## [A differentiable and slicable 2D data structure for parameters?](https://discourse.julialang.org/t/a-differentiable-and-slicable-2d-data-structure-for-parameters/51405)

<div class="topic-metadata">

**Author:** [@kmaile](https://discourse.julialang.org/u/kmaile)\
**Replies:** 0\
**Last updated:** [December 7, 2020, 3:28pm UTC](https://discourse.julialang.org/t/a-differentiable-and-slicable-2d-data-structure-for-parameters/51405 "2020-12-07T15:28:36Z")

</div>

I am implementing neural architecture search methods in Julia. One class of them uses trainable architecture weights to learn the best option for each layer of the network. Each repeated cell within a network has N layer…

---

## [Implementing finite difference with periodic B.C](https://discourse.julialang.org/t/implementing-finite-difference-with-periodic-b-c/50975)

<div class="topic-metadata">

**Author:** [@yhchang](https://discourse.julialang.org/u/yhchang)\
**Replies:** 9\
**Last updated:** [November 30, 2020, 9:09pm UTC](https://discourse.julialang.org/t/implementing-finite-difference-with-periodic-b-c/50975 "2020-11-30T21:09:39Z")

</div>

I am pretty new to Julia and ultimately I want to transfer my python code for solving a nonlinear PDE into Julia (and see whether I can get the speedup I hope). The PDE I want to solve is similar to a nonlinear heat equ…

---

## [Help debugging an error with Zygote](https://discourse.julialang.org/t/help-debugging-an-error-with-zygote/50411)

<div class="topic-metadata">

**Author:** [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Replies:** 1\
**Last updated:** [November 19, 2020, 5:37pm UTC](https://discourse.julialang.org/t/help-debugging-an-error-with-zygote/50411 "2020-11-19T17:37:54Z")

</div>

Hoping someone who understands autodiff better than I do can help me figure out what’s going on here. I’ve got a function that calls ldl from LDLFactorizations.jl, and then does further calculations on a field of the LD…

---

## [DifferentialEquations - Derivatives in ODE function/ nesting AD](https://discourse.julialang.org/t/differentialequations-derivatives-in-ode-function-nesting-ad/50100)

<div class="topic-metadata">

**Author:** [@Andreas\_Schlaginhauf](https://discourse.julialang.org/u/Andreas_Schlaginhauf)\
**Replies:** 6\
**Last updated:** [November 17, 2020, 2:57pm UTC](https://discourse.julialang.org/t/differentialequations-derivatives-in-ode-function-nesting-ad/50100 "2020-11-17T14:57:21Z")

</div>

If the ODE function of a neural ODE includes the gradient f’(x) of a neural network f(x), we need to calculate second order gradients of f(x) in the backward pass. For me this led to all sorts of problems when the AD met…

---

## [Cannot compute gradient/apply back method to solve function](https://discourse.julialang.org/t/cannot-compute-gradient-apply-back-method-to-solve-function/50082)

<div class="topic-metadata">

**Author:** [@TomCif](https://discourse.julialang.org/u/TomCif)\
**Replies:** 3\
**Last updated:** [November 15, 2020, 12:07pm UTC](https://discourse.julialang.org/t/cannot-compute-gradient-apply-back-method-to-solve-function/50082 "2020-11-15T12:07:54Z")

</div>

Hi, I’m facing an issue which avoids me to train my model using sciml\_train. I have the following training data: model = Normal(5., 0.1) raw\_data = rand(model, (1, 100)) x = rand(model, (1; 100)) u0 = \[x; 0\] I have…

---

## [FiniteDiff.finite\_difference\_gradient changes input when it errors?](https://discourse.julialang.org/t/finitediff-finite-difference-gradient-changes-input-when-it-errors/43279)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 3\
**Last updated:** [July 18, 2020, 12:45pm UTC](https://discourse.julialang.org/t/finitediff-finite-difference-gradient-changes-input-when-it-errors/43279 "2020-07-18T12:45:01Z")

</div>

I ran into a surprising thing today. Consider the function sumlog: function sumlog(x) sum(log(i) for i in x) end I’m interested in taking the gradient of sumlog at x: using FiniteDiff x = \[1e-6, 1e-6\] FiniteDiff…

---

## [Spetrum method and DifferentialEquaitons](https://discourse.julialang.org/t/spetrum-method-and-differentialequaitons/42919)

<div class="topic-metadata">

**Author:** [@hzgzh](https://discourse.julialang.org/u/hzgzh)\
**Replies:** 2\
**Last updated:** [July 12, 2020, 6:29am UTC](https://discourse.julialang.org/t/spetrum-method-and-differentialequaitons/42919 "2020-07-12T06:29:51Z")

</div>

Hi, I use Differentialequantions to solve the pde, \\left\\{\\begin{array}{l} \\frac{\\partial u}{\\partial t}=\\varepsilon \\frac{\\partial^{2} u}{\\partial x^{2}}+u-u^{3}, \\quad-1\<x\<1 \\\\ \\left.u\\right|\_{x=\\pm 1}=\\pm 1 \\\\ \\lef…

---

## [Derivatives of a production function](https://discourse.julialang.org/t/derivatives-of-a-production-function/42354)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 12\
**Last updated:** [July 2, 2020, 11:16am UTC](https://discourse.julialang.org/t/derivatives-of-a-production-function/42354 "2020-07-02T11:16:34Z")

</div>

I have a production function with several CES levels: function F(L2, A; λ=ones(4)./2, ρ=ones(4)./2) #L2 is 3x2, A is 1x1, λ and ρ are vectors of length 4 λ1 = λ\[1:2\] λ2 = λ\[3:4\] ρ1 = ρ\[1:2\] ρ2 = ρ\[3:…

---

## [Using Flux to optimize a function of the Singular Values](https://discourse.julialang.org/t/using-flux-to-optimize-a-function-of-the-singular-values/39687)

<div class="topic-metadata">

**Author:** [@rajnrao](https://discourse.julialang.org/u/rajnrao)\
**Replies:** 6\
**Last updated:** [June 11, 2020, 3:04pm UTC](https://discourse.julialang.org/t/using-flux-to-optimize-a-function-of-the-singular-values/39687 "2020-06-11T15:04:13Z")

</div>

Update – using latest Flux. I’d like to optimize a function of the singular values of a matrix. The Flux training loop barfs. Here’s my code using Flux, ForwardDiff, LinearAlgebra, GenericLinearAlgebra m = 20 X = rand…

[Previous page](https://discourse.julialang.org/tag/differentiation/110.md?match_all_tags=true&page=1&tags%5B%5D=differentiation)

[Next page](https://discourse.julialang.org/tag/differentiation/110.md?match_all_tags=true&page=3&tags%5B%5D=differentiation)
