# Connection between sensitivity algorithm and gradient calculation of the loss function

**URL:** <https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550>\
**Category:** Machine Learning\
**Created:** [August 17, 2021, 1:38pm UTC](https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550 "2021-08-17T13:38:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hardy](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@hardy](https://discourse.julialang.org/u/hardy)\
**Post date:** [August 17, 2021, 1:38pm UTC](https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550/1 "2021-08-17T13:38:04Z")

</div>

I’m new to Julia and ML and try to understand the basics.

I have defined an ODE problem with 2 parameters. This is used for the prediction in my loss function. This loss function is now used in turn to optimize the parameters of my ODE using DiffEqFlux.sciml\_train (loss, … BFGS (), …).  
Now I have discovered the local sensitivity analysis in the documentation:  
[https://diffeq.sciml.ai/stable/analysis/sensitivity/](https://diffeq.sciml.ai/stable/analysis/sensitivity/)

but didn’t quite understand what is happening.  
Can I use the sensitivity algorithm to determine how the gradient of my loss function is calculated?  
I understood that the sciml\_train function uses zygote and reverse-mode AD by default.  
Or does the sensitivity analysis not refer to the loss function?

Any help is highly appreciated 😊 🤔

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 17, 2021, 8:26pm UTC](https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550/2 "2021-08-17T20:26:54Z")

</div>

> [@hardy](#):
>
> Can I use the sensitivity algorithm to determine how the gradient of my loss function is calculated?

It’s doing that automatically.

> [@hardy](#):
>
> I understood that the sciml\_train function uses zygote and reverse-mode AD by default.  
> Or does the sensitivity analysis not refer to the loss function?

The default is a lot more complicated. With 2 parameters, it probably automatically switched to forward sensitivities.

---

<div class="post-metadata">

**Author:** ![hardy](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@hardy](https://discourse.julialang.org/u/hardy)\
**Post date:** [August 17, 2021, 9:05pm UTC](https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550/3 "2021-08-17T21:05:33Z")

</div>

Thank you for your help, but I still need some information to understand. If I add a sensealg to my prediction, what does it do?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 17, 2021, 9:09pm UTC](https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550/4 "2021-08-17T21:09:03Z")

</div>

It overrides the default and chooses which sensitivity method to use.

---

<div class="post-metadata">

**Author:** ![hardy](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@hardy](https://discourse.julialang.org/u/hardy)\
**Post date:** [August 17, 2021, 9:18pm UTC](https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550/5 "2021-08-17T21:18:05Z")

</div>

To calculate the gradients of my loss function at every data point?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 17, 2021, 9:19pm UTC](https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550/6 "2021-08-17T21:19:59Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![hardy](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@hardy](https://discourse.julialang.org/u/hardy)\
**Post date:** [August 17, 2021, 9:22pm UTC](https://discourse.julialang.org/t/connection-between-sensitivity-algorithm-and-gradient-calculation-of-the-loss-function/66550/7 "2021-08-17T21:22:31Z")

</div>

Thank you, now I finally get it! Sorry for the clumsy language, I am not very fluent in english
