I'm building a simple auto-differentiation (AD) engine for my own educational purpose. The end goal will be to train a neural network. I decided to go for the reverse-mode AD and thus I'm currently deriving and implementing a bunch of vector-jacobian product (vjp) primitives. Vjps for point-wise operations like addition and multiplication are fairly easy but I'm struggling to come up with the solutions for a vector-matrix product and matrix product. More precisely let say I have the following operation : $$z = W.x$$ with $W$ a matrix $\in\mathbb{R}^{n\times m}$, $x$ a vector $\in\mathbb{R}^{m}$ and thus $z$ a vector $\in\mathbb{R}^{n}$. For some vector $v \in\mathbb{R}^{n}$, the vjp of $$v.J_x(z)$$ is simply $$v.W$$ But for the more complicated case where we want the vjp for $$v.J_W(z)$$ I struggle to come up with an expression since $J_W(z)$ is a Tensor. From what I could gather from a simple derivation with $n=m=2$, this tensor is mostly sparse with $x_{i}$'s in its "diagonal", something like $$\begin{pmatrix} (x_1 & x_2) & (0 & 0)\\ (0 & 0) & (x_1 & x_2) \end{pmatrix}$$ Not sure if that make sense since I don't know how to properly manipulate Tensor and how do the product with $v$. Does someone knows an expression for the vjp of this operation ? or how it is implemented in AD engine such as pytorch or TensorFlow.
2026-03-30 18:05:29.1774893929
Help deriving the vector-jacobian product of some operations
161 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
1
There are 1 best solutions below
Related Questions in CALCULUS
- Equality of Mixed Partial Derivatives - Simple proof is Confusing
- How can I prove that $\int_0^{\frac{\pi}{2}}\frac{\ln(1+\cos(\alpha)\cos(x))}{\cos(x)}dx=\frac{1}{2}\left(\frac{\pi^2}{4}-\alpha^2\right)$?
- Proving the differentiability of the following function of two variables
- If $f ◦f$ is differentiable, then $f ◦f ◦f$ is differentiable
- Calculating the radius of convergence for $\sum _{n=1}^{\infty}\frac{\left(\sqrt{ n^2+n}-\sqrt{n^2+1}\right)^n}{n^2}z^n$
- Number of roots of the e
- What are the functions satisfying $f\left(2\sum_{i=0}^{\infty}\frac{a_i}{3^i}\right)=\sum_{i=0}^{\infty}\frac{a_i}{2^i}$
- Why the derivative of $T(\gamma(s))$ is $T$ if this composition is not a linear transformation?
- How to prove $\frac 10 \notin \mathbb R $
- Proving that: $||x|^{s/2}-|y|^{s/2}|\le 2|x-y|^{s/2}$
Related Questions in MULTIVARIABLE-CALCULUS
- Equality of Mixed Partial Derivatives - Simple proof is Confusing
- $\iint_{S} F.\eta dA$ where $F = [3x^2 , y^2 , 0]$ and $S : r(u,v) = [u,v,2u+3v]$
- Proving the differentiability of the following function of two variables
- optimization with strict inequality of variables
- How to find the unit tangent vector of a curve in R^3
- Prove all tangent plane to the cone $x^2+y^2=z^2$ goes through the origin
- Holding intermediate variables constant in partial derivative chain rule
- Find the directional derivative in the point $p$ in the direction $\vec{pp'}$
- Check if $\phi$ is convex
- Define in which points function is continuous
Related Questions in DERIVATIVES
- Derivative of $ \sqrt x + sinx $
- Second directional derivative of a scaler in polar coordinate
- A problem on mathematical analysis.
- Why the derivative of $T(\gamma(s))$ is $T$ if this composition is not a linear transformation?
- Does there exist any relationship between non-constant $N$-Exhaustible function and differentiability?
- Holding intermediate variables constant in partial derivative chain rule
- How would I simplify this fraction easily?
- Why is the derivative of a vector in polar form the cross product?
- Proving smoothness for a sequence of functions.
- Gradient and Hessian of quadratic form
Related Questions in PARTIAL-DERIVATIVE
- Equality of Mixed Partial Derivatives - Simple proof is Confusing
- Proving the differentiability of the following function of two variables
- Partial Derivative vs Total Derivative: Function depending Implicitly and Explicitly on Variable
- Holding intermediate variables constant in partial derivative chain rule
- Derive an equation with Faraday's law
- How might we express a second order PDE as a system of first order PDE's?
- Partial derivative of a summation
- How might I find, in parametric form, the solution to this (first order, quasilinear) PDE?
- Solving a PDE given initial/boundary conditions.
- Proof for f must be a constant polynomial
Related Questions in JACOBIAN
- Finding $Ax=b$ iteratively using residuum vectors
- When a certain subfield of $\mathbb{C}(x,y^2)$ is Galois
- Two variables with joint density: Change of variable technique using Jacobian for $U=\min(X,Y)$ and $V=\max(X,Y)$
- Jacobian determinant of a diffeomorphism on the unit shpere must equal $1$ or $-1$
- Physicists construct their potentials starting from the Laplace equation, why they do not use another differential operator, like theta Θ?
- Solution verification: show that the following functions are not differentiable
- Finding Jacobian of implicit function.
- Jacobian chain rule for function composition with rotation matrix
- Is there a way to avoid chain rules in finding this derivative of an integral?
- Computing the derivative of a matrix-vector dot product
Trending Questions
- Induction on the number of equations
- How to convince a math teacher of this simple and obvious fact?
- Find $E[XY|Y+Z=1 ]$
- Refuting the Anti-Cantor Cranks
- What are imaginary numbers?
- Determine the adjoint of $\tilde Q(x)$ for $\tilde Q(x)u:=(Qu)(x)$ where $Q:U→L^2(Ω,ℝ^d$ is a Hilbert-Schmidt operator and $U$ is a Hilbert space
- Why does this innovative method of subtraction from a third grader always work?
- How do we know that the number $1$ is not equal to the number $-1$?
- What are the Implications of having VΩ as a model for a theory?
- Defining a Galois Field based on primitive element versus polynomial?
- Can't find the relationship between two columns of numbers. Please Help
- Is computer science a branch of mathematics?
- Is there a bijection of $\mathbb{R}^n$ with itself such that the forward map is connected but the inverse is not?
- Identification of a quadrilateral as a trapezoid, rectangle, or square
- Generator of inertia group in function field extension
Popular # Hahtags
second-order-logic
numerical-methods
puzzle
logic
probability
number-theory
winding-number
real-analysis
integration
calculus
complex-analysis
sequences-and-series
proof-writing
set-theory
functions
homotopy-theory
elementary-number-theory
ordinary-differential-equations
circles
derivatives
game-theory
definite-integrals
elementary-set-theory
limits
multivariable-calculus
geometry
algebraic-number-theory
proof-verification
partial-derivative
algebra-precalculus
Popular Questions
- What is the integral of 1/x?
- How many squares actually ARE in this picture? Is this a trick question with no right answer?
- Is a matrix multiplied with its transpose something special?
- What is the difference between independent and mutually exclusive events?
- Visually stunning math concepts which are easy to explain
- taylor series of $\ln(1+x)$?
- How to tell if a set of vectors spans a space?
- Calculus question taking derivative to find horizontal tangent line
- How to determine if a function is one-to-one?
- Determine if vectors are linearly independent
- What does it mean to have a determinant equal to zero?
- Is this Batman equation for real?
- How to find perpendicular vector to another vector?
- How to find mean and median from histogram
- How many sides does a circle have?
I think it is best to derive the result of the vjp in index notation, working with higher tensors in symbolic notation is tricky.
The vjp you look for, i.e., $$v.J_W(z)$$ is in index notation (assuming Einstein summation convention) $$v_i\frac{\partial z_i}{\partial W_{kl}}$$ In order to evaluate the partial derivative, we also need the forward computation in index notation, which would be $$z_i = W_{ij}x_j$$ If we evaluate its derivative, we get $$\frac{\partial z_i}{\partial W_{kl}} = \frac{\partial W_{ij}}{\partial W_{kl}} x_j = \delta_{ik}\delta_{jl}x_j$$ with the Kronecker delta $$\delta_{ij} = \begin{cases} 1, \quad i=j \\ 0, \quad i \ne j \end{cases} $$ In these derivations using the index notation, Kronecker deltas are just a tool to express the derivative of a quantity with respect to itself, but with different indices.
We can plug the derivative back into the vjp definition $$v_i\frac{\partial z_i}{\partial W_{kl}} = v_i \delta_{ik}\delta_{jl}x_j$$ The Kronecker deltas induce an index change $i \leftrightarrow k$ and $j \leftrightarrow l$. Let's choose to keep indices $k$ and $l$ as those are the ones that are left-over on the left-hand side of the equation. Then, we have $$v_i\frac{\partial z_i}{\partial W_{kl}} = v_k x_l$$ The quantity we got is an outer product of vector $v$ and vector $x$.
Hence, we can also go back to symbolic notation to finally find the answer to your question $$v.J_W(z) = v.x^T$$
I hope that helped. Recently, I also uploaded a YouTube video explaining the steps in more detail.