<< scicolpack scicolpack spCompJacobian >>

scicolpack >> scicolpack > spCompHessian

spCompHessian

Consruct a compressed Hessian engine from its sparsity pattern using column intersection graph coloring

Syntax

hess = spCompHessian(g,sp)
hess = spCompHessian(g,sp,options)

Parameters

g

a Scilab function computing the gradient

sp

a sparse matrix

options

a sequence of optional named arguments allowing to customize the engine (see available options below)

hess

the returned engine, an MList of _spCompHessian type (fields are described below)

Description

First and foremost, you need a Scilab function g which computes the gradient (preferably exact) of the function for wich the Hessian is to be approximated.

The spCompHessian function consructs a compressed Hessian engine from the given sparsity pattern using column intersection graph coloring. Internally, after using a heuristic coloring algorithm, a "seed matrix" is generated, available as hess.seed, and later used by the engine to compute (approximate) directional derivatives of the gradient function g in each seed column direction. Then the uncompressed Hessian is recovered. The typical call sequence starts by calling spCompHessian then continues by invoking the returned MList with the vectors at which the Hessian is to be computed:

hess = spCompHessian(g,sp);
H0 = hess(x0);
H1 = hess(x1);

The options allows to change some parameters of the coloring algorithm and to choose the derivative approximation scheme as well as the step vector. The available options are the following:

The hess MList can be invoked with more than one arguments. In this case the remaining argument after the first are used by the engine as complimentary arguments when calling the gradient g.

Examples

function f=fun(x)
    n = length(x);
    f = norm(x(1:n-2).*x(2:n-1).*x(3:n))^2;
endfunction

function g=grad(x)
    n = length(x);
    g = zeros(n,1);
    k = 3:n-2;
    g(1)   = 2*x(1)*x(2)^2*x(3)^2;
    g(2)   = 2*(x(2)*x(3)^2*x(4)^2+x(1)^2*x(2)*x(3)^2);
    g(k)   = 2*(x(k).*x(k+1).^2.*x(k+2).^2+x(k-1).^2.*x(k).*x(k+1).^2+x(k-2).^2.*x(k-1).^2.*x(k))
    g(n-1) = 2*(x(n-3)^2*x(n-2)^2*x(n-1)+x(n-2)^2*x(n-1)*x(n)^2); 
    g(n)   = 2*x(n-2)^2*x(n-1)^2*x(n);
endfunction

n = 1000;
// Hessian is pentadiagonal
i = (1:n).*.ones(n,1);
sp = sparse(abs(i-i') <= 2);

hess = spCompHessian(grad, sp, FiniteDifferenceType = "COMPLEXSTEP")
x0 = rand(n,1);
tic
H = hess(x0);
toc
tic
Hd = numderivative(grad,x0);
toc
disp(max(abs(H-Hd)))

See also

Bibliography

A. H. Gebremedhin, D. C. Nguyen, Md. M. A. Patwary, A. Pothen}, ColPack: Software for graph coloring and related problems in scientific computing, ACM Trans. Math. Softw., N. 40(1), pp. 1-31, 2013, https://doi.org/10.1145/2513109.2513110.


Report an issue
<< scicolpack scicolpack spCompJacobian >>