# Hessian matrix of ML model

**URL:** <https://discourse.julialang.org/t/hessian-matrix-of-ml-model/59933>\
**Category:** General Usage\
**Tags:** flux, zygote, forwarddiff, reversediff\
**Created:** [April 24, 2021, 3:06pm UTC](https://discourse.julialang.org/t/hessian-matrix-of-ml-model/59933 "2021-04-24T15:06:24Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [April 27, 2021, 8:18am UTC](https://discourse.julialang.org/t/hessian-matrix-of-ml-model/59933/7 "2021-04-27T08:18:02Z")

</div>

The docs state that `hessian(f, x) ... where x is a real number or an array, ...` which I interpret as if it should be a scalar array.  
Doing something like

```julia
function f2(params)
	loss = Flux.mse(params[:, 2:end] * x .+ params[:, 1:1], y)
end
initial_params = [model[1].b model[1].W]
Zygote.hessian(f, initial_params)

```

seems to work for me. I think it is something with mutating arrays that Zygote does not like, have not read into it much but [here](https://discourse.julialang.org/t/mutating-arrays-not-supported/42123/3) is some discussion around the topic.

---

_[View the full topic](https://discourse.julialang.org/t/hessian-matrix-of-ml-model/59933)._
