Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.0.0 - Русский


spCompJacobian

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

Syntax

jac = spCompJacobian(f,sp)
jac = spCompJacobian(f,sp,options)

Parameters

f

a Scilab function

sp

a sparse matrix

options

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

jac

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

Description

The spCompJacobian function consructs a compressed Jacobian 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 jac.seed, and later used by the engine to compute (approximate) directional derivatives of f in each seed column direction. Then the uncompressed Jacobian is recovered. The typical call sequence starts by calling spCompJacobian then continues by invoking the returned MList with the vectors at which the Jacobian is to be computed:

jac = spCompJacobian(f,sp);
J0 = jac(x0);
J1 = jac(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:

  • Coloring : the only allowed value is "COLUMN_PARTIAL_DISTANCE_TWO"

  • Ordering : this field allows to change the way columns of the sparsity pattern are ordered before applying the coloring algorithm. The possible values are "SMALLEST_LAST" (the default), "LARGEST_FIRST", "NATURAL", "INCIDENCE_DEGREE", "RANDOM".

  • FiniteDifferenceType : this field gives the chosen approximation scheme. The possible values are "CENTERED" (the default order 2 centered scheme), "FORWARD" (the usual forward order 1 scheme) and "COMPLEXSTEP" (the order 2 complex step scheme). If you choose the complex step scheme check that f accepts complex input and handles it correctly (for example transposition operator has to be the dot-prefixed non-conjugate transposition .').

  • FiniteDifferenceStepSize : this is the relative stepsize (see also "TypicalX" below). For a given x0 the actual step is

    sign(x0).*FiniteDifferenceStepSize.*max(TypicalX,x0)

    It can be a scalar, or a vector with the same size as x0. Its default value depends on the chosen approximation scheme: sqrt(%eps) for the "FORWARD" scheme, %eps^(1/3) for the "CENTERED" scheme and 1e-100 for the "COMPLEXSTEP" scheme.

  • TypicalX : a vector of the same size as x0, with typical magnitude of components. The default value is ones(x0).

  • Vectorized : "on" or "off" : allows to inform the engine if f can be called with a matrix X as argument, with the convention that f(X)(:,i) == f(X(:,i)).

    for each column of X.

The jac 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 f.

Examples

function y=f(x)
    y = x(1:$-2).^2./(4+cos(x(2:$-1)).*sin(x(3:$)));
endfunction
n = 1000;
sp = sparse([1:n-2,1:n-2,1:n-2;1:n-2,2:n-1,3:n]',ones(3*(n-2),1),[n-2,n]);
jac = spCompJacobian(f,sp)
x0 = rand(n,1);
tic
J = jac(x0);
toc
tic
Jd = numderivative(f,x0);
toc
max(abs(Jd-J))

See also

  • spCompHessian — Consruct a compressed Hessian engine from its sparsity pattern using column intersection graph coloring
  • numderivative — approximate derivatives of a function (Jacobian or Hessian)

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
<< spCompHessian Sparse Jacobian computation spyCol >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Oct 24 14:37:07 CEST 2023