# Calculus

**URL:** <https://d2l.discourse.group/t/calculus/32>\
**Category:** mxnet\
**Created:** [May 22, 2020, 3:44am UTC](https://d2l.discourse.group/t/calculus/32 "2020-05-22T03:44:11Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![mli](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/mli/32/6_2.png) [@mli](https://d2l.discourse.group/u/mli)\
**Post date:** [May 22, 2020, 3:44am UTC](https://d2l.discourse.group/t/calculus/32/1 "2020-05-22T03:44:11Z")

</div>

[http://d2l.ai/chapter\_preliminaries/calculus.html](http://d2l.ai/chapter_preliminaries/calculus.html)

---

<div class="post-metadata">

**Author:** ![gpk2000](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/gpk2000/32/610_2.png) [@gpk2000](https://d2l.discourse.group/u/gpk2000)\
**Post date:** [August 25, 2020, 12:45pm UTC](https://d2l.discourse.group/t/calculus/32/2 "2020-08-25T12:45:38Z")

</div>

I think it would be better to make a quote that you need to install these packages before running this code such as in [the](https://d2l.ai/chapter_preliminaries/calculus.html#derivatives-and-differentiation) code-block below. Anaconda comes with these pre-installed but Miniconda doesn’t. I am saying this cause the book suggested to download Miniconda.

---

<div class="post-metadata">

**Author:** ![gpk2000](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/gpk2000/32/610_2.png) [@gpk2000](https://d2l.discourse.group/u/gpk2000)\
**Post date:** [August 25, 2020, 12:57pm UTC](https://d2l.discourse.group/t/calculus/32/3 "2020-08-25T12:57:58Z")

</div>

Also in that example this didn’t work

`from d2l import mxnet as d2l`

this works

`import mxnet as d2l`

---

<div class="post-metadata">

**Author:** ![goldpiggy](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/goldpiggy/32/10_2.png) [@goldpiggy](https://d2l.discourse.group/u/goldpiggy)\
**Post date:** [September 3, 2020, 5:50pm UTC](https://d2l.discourse.group/t/calculus/32/4 "2020-09-03T17:50:04Z")

</div>

Hey @gpk2000, thanks for the suggestion of Anaconda. We recommend installing miniconda as it has most of the necessary libraries but not as heavy-lifting as anaconda.

> [@gpk2000](#):
>
> Also in that example this didn’t work
> 
> `from d2l import mxnet as d2l`
> 
> this works
> 
> `import mxnet as d2l`

As for your question, please make sure you have the latest version of D2L and MXNet installed. 😉

---

<div class="post-metadata">

**Author:** ![smizerex](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@smizerex](https://d2l.discourse.group/u/smizerex)\
**Post date:** [September 7, 2020, 11:13pm UTC](https://d2l.discourse.group/t/calculus/32/5 "2020-09-07T23:13:02Z")

</div>

Is exercise 4 in section 2.4 possible?  
How would we do it?

---

<div class="post-metadata">

**Author:** ![goldpiggy](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/goldpiggy/32/10_2.png) [@goldpiggy](https://d2l.discourse.group/u/goldpiggy)\
**Post date:** [September 8, 2020, 8:20pm UTC](https://d2l.discourse.group/t/calculus/32/6 "2020-09-08T20:20:37Z")

</div>

Hey @smizerex, yes chain rule can be applied here. Feel free to share your idea and discuss here.

---

<div class="post-metadata">

**Author:** ![asadalam](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@asadalam](https://d2l.discourse.group/u/asadalam)\
**Post date:** [September 11, 2020, 12:07am UTC](https://d2l.discourse.group/t/calculus/32/7 "2020-09-11T00:07:07Z")

</div>

Does the first part of answer for Q.4 in 2.4 is: du/da = (du/dx)_(dx/da) + (du/dy)_(dy/da) + (du/dz)\*(dz/da)

---

<div class="post-metadata">

**Author:** ![goldpiggy](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/goldpiggy/32/10_2.png) [@goldpiggy](https://d2l.discourse.group/u/goldpiggy)\
**Post date:** [September 11, 2020, 7:55pm UTC](https://d2l.discourse.group/t/calculus/32/8 "2020-09-11T19:55:39Z")

</div>

Hi @asadalam, I believe you are right!

---

<div class="post-metadata">

**Author:** ![anant\_jain](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/anant_jain/32/845_2.png) [@anant\_jain](https://d2l.discourse.group/u/anant_jain)\
**Post date:** [September 25, 2020, 11:20am UTC](https://d2l.discourse.group/t/calculus/32/10 "2020-09-25T11:20:00Z")

</div>

Hey, can you please provide deeper explanation of matrix differentiation rules given?

---

<div class="post-metadata">

**Author:** ![goldpiggy](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/goldpiggy/32/10_2.png) [@goldpiggy](https://d2l.discourse.group/u/goldpiggy)\
**Post date:** [September 25, 2020, 9:26pm UTC](https://d2l.discourse.group/t/calculus/32/11 "2020-09-25T21:26:55Z")

</div>

Hi @anant_jain, great question. We have the math chapter talking about in-depth math, such as [https://d2l.ai/chapter\_appendix-mathematics-for-deep-learning/multivariable-calculus.html](https://d2l.ai/chapter_appendix-mathematics-for-deep-learning/multivariable-calculus.html)

---

<div class="post-metadata">

**Author:** ![Reza\_Afra](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/reza_afra/32/894_2.png) [@Reza\_Afra](https://d2l.discourse.group/u/Reza_Afra)\
**Post date:** [October 9, 2020, 7:06pm UTC](https://d2l.discourse.group/t/calculus/32/12 "2020-10-09T19:06:06Z")

</div>

I just wanted to thank the authors of this book. This book is a godsend!

---

<div class="post-metadata">

**Author:** ![Abhinav\_Raj](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/abhinav_raj/32/864_2.png) [@Abhinav\_Raj](https://d2l.discourse.group/u/Abhinav_Raj)\
**Post date:** [October 25, 2020, 5:34pm UTC](https://d2l.discourse.group/t/calculus/32/13 "2020-10-25T17:34:01Z")

</div>

[http://d2l.ai/chapter\_preliminaries/calculus.html#gradients](http://d2l.ai/chapter_preliminaries/calculus.html#gradients)  
In the above section how is the derivative defined? I may be wrong but I think the derivative for Ax w.r.t. x be A instead of A transpose, assuming the usual definitions of matrix differentiation. I did it in a similar way to [Matrix Derivative](https://atmos.washington.edu/~dennis/MatrixCalculus.pdfsAhXFF3IKHVihCqQQFjAAegQIAhAC&url=https%3A%2F%e2Fatmos.washington.edu%2F~dennis%2FMatrixCalculus.pdf) (page 5).  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![goldpiggy](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/goldpiggy/32/10_2.png) [@goldpiggy](https://d2l.discourse.group/u/goldpiggy)\
**Post date:** [October 26, 2020, 9:23pm UTC](https://d2l.discourse.group/t/calculus/32/14 "2020-10-26T21:23:51Z")

</div>

Hi @Abhinav_Raj, great question! There are two layouts in matrix calculus: numerator layout and denominator layout, and we are using the denominator layout. Check more details in “Layout conventions” section in [https://en.wikipedia.org/wiki/Matrix\_calculus](https://en.wikipedia.org/wiki/Matrix_calculus).

---

<div class="post-metadata">

**Author:** ![Abhinav\_Raj](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/abhinav_raj/32/864_2.png) [@Abhinav\_Raj](https://d2l.discourse.group/u/Abhinav_Raj)\
**Post date:** [October 27, 2020, 5:11am UTC](https://d2l.discourse.group/t/calculus/32/15 "2020-10-27T05:11:33Z")

</div>

@goldpiggy, I see, thanks for clearing it up. So, basically we lay out the y as a row vector and then calculate the gradient in a usual way (column wise). Also, is there some specific reason for choosing this convention say it makes calculations easier or that’s how it’s done in MxNet/Pytorch?TF?  
Thanks again.

---

<div class="post-metadata">

**Author:** ![goldpiggy](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/goldpiggy/32/10_2.png) [@goldpiggy](https://d2l.discourse.group/u/goldpiggy)\
**Post date:** [November 2, 2020, 9:32pm UTC](https://d2l.discourse.group/t/calculus/32/16 "2020-11-02T21:32:39Z")

</div>

Hey @Abhinav_Raj, it doesn’t matter that much to programming. The difference are row vector or column vector, but they are both vectors in programming.

---

<div class="post-metadata">

**Author:** ![shrza](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@shrza](https://d2l.discourse.group/u/shrza)\
**Post date:** [April 28, 2021, 1:56am UTC](https://d2l.discourse.group/t/calculus/32/17 "2021-04-28T01:56:47Z")

</div>

[http://d2l.ai/chapter\_preliminaries/calculus.html#gradients](http://d2l.ai/chapter_preliminaries/calculus.html#gradients)  
In the above section gradient was defined for the function f: ℝⁿ → ℝ in (2.4.9),  
but 𝗔𝘅 and 𝘅ᵀ𝗔 are column and row vectors respectively, in these cases f(𝘅) is f:ℝⁿ → ℝᵐ. How do you define ∇ **ₓ** f(𝘅) in this case? Is it transposed Jacobian?

---

<div class="post-metadata">

**Author:** ![MucsanyiBalint](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/mucsanyibalint/32/2149_2.png) [@MucsanyiBalint](https://d2l.discourse.group/u/MucsanyiBalint)\
**Post date:** [July 12, 2021, 10:33am UTC](https://d2l.discourse.group/t/calculus/32/18 "2021-07-12T10:33:05Z")

</div>

I may be wrong, but I believe that the nabla (or del) operator is not appropriate for the derivatives of Ax and x^TA, as it is used for **gradient vectors** , but these functions are R^n-\>R^m, thus their derivatives are matrices ( **Jacobian matrices** ). I think denoting these by **delta / delta(x) Ax** and **delta / delta(x) x^TA** would be better. The same could be said for the squared Frobenius norm at the end.

If my understanding is right, I will happily contribute. If not, at least I learned something new. 🙂

---

<div class="post-metadata">

**Author:** ![Def255](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/def255/32/2152_2.png) [@Def255](https://d2l.discourse.group/u/Def255)\
**Post date:** [July 25, 2021, 12:53pm UTC](https://d2l.discourse.group/t/calculus/32/19 "2021-07-25T12:53:00Z")

</div>

`display.set_matplotlib_formats('svg')` is deprecated. It is recommended to use `matplotlib_inline.backend_inline.set_matplotlib_formats()` instead
