# Help with Jacobian vector product to get natural gradient

**URL:** <https://discourse.julialang.org/t/help-with-jacobian-vector-product-to-get-natural-gradient/51115>\
**Category:** Probabilistic Programming\
**Tags:** forwarddiff, natural-gradient\
**Created:** [December 2, 2020, 2:03pm UTC](https://discourse.julialang.org/t/help-with-jacobian-vector-product-to-get-natural-gradient/51115 "2020-12-02T14:03:03Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![YingboMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yingboma/32/2181_2.png) [@YingboMa](https://discourse.julialang.org/u/YingboMa)\
**Post date:** [December 2, 2020, 4:36pm UTC](https://discourse.julialang.org/t/help-with-jacobian-vector-product-to-get-natural-gradient/51115/12 "2020-12-02T16:36:21Z")

</div>

The derivative of `f(t * a + c)` wrt `t` at 0 is the Jacobian vector product `J(f, c) * a`.

```julia
julia> using ForwardDiff

julia> foo(x) = [x[1], x[1]*x[3], x[2]^2]
foo (generic function with 1 method)

julia> ForwardDiff.derivative(t->foo([1,2,3] * t + [3, 4, 5]), 0)
3-element Vector{Int64}:
  1
 14
 16

julia> ForwardDiff.jacobian(foo, [3,4,5]) * [1,2,3]
3-element Vector{Int64}:
  1
 14
 16

```

---

_[View the full topic](https://discourse.julialang.org/t/help-with-jacobian-vector-product-to-get-natural-gradient/51115)._
