## Using fminunc with ‘HessianMultiplyFcn’ option

I’m trying to solve a large-scale optimization problem using fminunc, where the number of variables is too large to store the Hessian explicitly.

I have carefully read the Matlab documention on using the ‘HessianMultiplyFcn’, which allows the user to pass in a function that will compute the Hessian times a vector Y. It says that in this case, the loss function should return the loss, gradient, and a struct called Hinfo.

However, MATLAB returns an error when using this function:

Error using fminunc (line 410)

FMINUNC requires all values returned by functions to be of data type double.

Note that I have set the algorithm to ‘trust-region’ and ‘HessianFcn’ to [] in optimoptions, so it should know that the third argument returned by my function is a struct.

Help! Has anyone encountered this before? Or can anyone post an example snippet in which they successfully used fminunc with the HessianMultiplyFcn option?

I’m copying the documentation for the HessianMultiplyFcn in the fminunc documentation in case it is helpful. (From:

—————-

HessianMultiplyFcn

Hessian multiply function, specified as a function handle. For large-scale structured problems, this function computes the Hessian matrix product H*Y without actually forming H. The function is of the form

W = hmfun(Hinfo,Y)

where Hinfo contains the matrix used to compute H*Y.

The first argument is the same as the third argument returned by the objective function fun, for example

[f,g,Hinfo] = fun(x)

Y is a matrix that has the same number of rows as there are dimensions in the problem. The matrix W = H*Y, although H is not formed explicitly. fminunc uses Hinfo to compute the preconditioner.I’m trying to solve a large-scale optimization problem using fminunc, where the number of variables is too large to store the Hessian explicitly.

I have carefully read the Matlab documention on using the ‘HessianMultiplyFcn’, which allows the user to pass in a function that will compute the Hessian times a vector Y. It says that in this case, the loss function should return the loss, gradient, and a struct called Hinfo.

However, MATLAB returns an error when using this function:

Error using fminunc (line 410)

FMINUNC requires all values returned by functions to be of data type double.

Note that I have set the algorithm to ‘trust-region’ and ‘HessianFcn’ to [] in optimoptions, so it should know that the third argument returned by my function is a struct.

Help! Has anyone encountered this before? Or can anyone post an example snippet in which they successfully used fminunc with the HessianMultiplyFcn option?

I’m copying the documentation for the HessianMultiplyFcn in the fminunc documentation in case it is helpful. (From:

—————-

HessianMultiplyFcn

Hessian multiply function, specified as a function handle. For large-scale structured problems, this function computes the Hessian matrix product H*Y without actually forming H. The function is of the form

W = hmfun(Hinfo,Y)

where Hinfo contains the matrix used to compute H*Y.

The first argument is the same as the third argument returned by the objective function fun, for example

[f,g,Hinfo] = fun(x)

Y is a matrix that has the same number of rows as there are dimensions in the problem. The matrix W = H*Y, although H is not formed explicitly. fminunc uses Hinfo to compute the preconditioner. I’m trying to solve a large-scale optimization problem using fminunc, where the number of variables is too large to store the Hessian explicitly.

I have carefully read the Matlab documention on using the ‘HessianMultiplyFcn’, which allows the user to pass in a function that will compute the Hessian times a vector Y. It says that in this case, the loss function should return the loss, gradient, and a struct called Hinfo.

However, MATLAB returns an error when using this function:

Error using fminunc (line 410)

FMINUNC requires all values returned by functions to be of data type double.

Note that I have set the algorithm to ‘trust-region’ and ‘HessianFcn’ to [] in optimoptions, so it should know that the third argument returned by my function is a struct.

Help! Has anyone encountered this before? Or can anyone post an example snippet in which they successfully used fminunc with the HessianMultiplyFcn option?

I’m copying the documentation for the HessianMultiplyFcn in the fminunc documentation in case it is helpful. (From:

—————-

HessianMultiplyFcn

Hessian multiply function, specified as a function handle. For large-scale structured problems, this function computes the Hessian matrix product H*Y without actually forming H. The function is of the form

W = hmfun(Hinfo,Y)

where Hinfo contains the matrix used to compute H*Y.

The first argument is the same as the third argument returned by the objective function fun, for example

[f,g,Hinfo] = fun(x)

Y is a matrix that has the same number of rows as there are dimensions in the problem. The matrix W = H*Y, although H is not formed explicitly. fminunc uses Hinfo to compute the preconditioner. fminunc, hessianmultiplyfcn MATLAB Answers — New Questions