# Smooth delta functions to compute Jacobian and Hessian from samples

**URL:** <https://discourse.julialang.org/t/smooth-delta-functions-to-compute-jacobian-and-hessian-from-samples/45282>\
**Category:** Numerics\
**Created:** [August 20, 2020, 6:24pm UTC](https://discourse.julialang.org/t/smooth-delta-functions-to-compute-jacobian-and-hessian-from-samples/45282 "2020-08-20T18:24:45Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [August 21, 2020, 4:51am UTC](https://discourse.julialang.org/t/smooth-delta-functions-to-compute-jacobian-and-hessian-from-samples/45282/10 "2020-08-21T04:51:05Z")

</div>

Going back to the OP, CoupledFields is based on kernel regression.  
If yᵢ = g(xᵢ), then it follows from kernel ridge regression that:

```
∇g(xᵢ) = ∇K(xᵢ, ⋅) (Gₓ + 10ᵇnI)⁻¹ Y

```

where Gₓ is the gram matrix of X, and ∇K() is the gradient function of a kernel function.

In CoupledFields, for `gradvecfield([a b], ...)`, a is a smoothness parameter (that scales an auto-estimate of kernel width), and b is a ridge parameter (as in the equation above).  
Using a=1.0 should typically work well.

Here’s an example. The black line is the true value, the gradient function is estimated using `gradvecfield([a -7], X, Y, GaussianKP(X))` for 3 values of a.

![CF_sinc](https://global.discourse-cdn.com/julialang/original/3X/4/1/419d07d19e84ca32347b9e2c7d831f337b677cd8.png)

For high-dimensional problems, the average product of jacobians can be used to find an [active subspace](https://doi.org/10.1137/1.9781611973860).

---

_[View the full topic](https://discourse.julialang.org/t/smooth-delta-functions-to-compute-jacobian-and-hessian-from-samples/45282)._
