Graph optimization

For a fixed topology of the graph, the coefficients can be optimized. The package provides some routines for doing the optimization. However, by using the functions eval_graph and eval_jac, external routines based on function values and first derivatives can in principle be used.

GraphMatFun.opt_gauss_newton!Function
(iter,resnorm)=opt_gauss_newton!(
    graph,
    objfun,
    discr;
    maxit = 100,
    logger = 0,
    errtype = :abserr,
    stoptol = 1e-6,
    cref = get_all_cref(graph),
    input = :A,
    γ0 = 1.0,
    linlsqr = :backslash,
    droptol = 0,
)

Applies the Gauss–Newton algorithm to solve the nonlinear least squares problem: Fit the output of the graph to the values of objfun, in the points discr.

The variable graph is modified during the iterations. The function returns the iteration iter where it terminated, and the corresponding residual norm resnorm.

The kwargs are as follows:

  • maxit determines the maximum number of iterations. If logger has a value >0, then the intermediate results are printed.
  • errtype determines the error type measured, see adjust_for_errtype!.
  • stoptol is the corresponding stopping tolerance.
  • cref is a Vector{Tuple{Symbol,Int}} that determines which coefficients of graph that are considered free variables and optimized.
  • input is the label corresponding to the input node of the graph.
  • The stepsize can be scaled with γ0.
  • linlsqr and droptol determines how the inner linear least squares problem is solved; see solve_linlsqr!.
source
GraphMatFun.eval_jacFunction
J=eval_jac(
    graph,
    x,
    cref;
    vals = nothing,
    input = :A,
    output = size(graph.outputs, 1),
)

Computes Jacobian J = dZ(x_i)/dc, with respect to the coefficients given in the vector cref, and points in x. See eval_graph for description of vals and output.

source
GraphMatFun.opt_linear_fit!Function
opt_linear_fit!(
    graph,
    objfun,
    discr,
    linear_cref;
    input = :A,
    errtype = :abserr,
    linlsqr = :backslash,
    droptol = 0,
)

Linear fitting of a graph of the form

c_1 g_1(x) + c_2 g_2(x) + … + c_n g_n(x)

to the values of objfun, in the points discr. Reference to the coefficients c_1,…,c_n should be given linear_cref.

The variable graph is modified during the iterations and the function has no return value.

See opt_gauss_newton! for a description the kwarg errtype and input, and solve_linlsqr! for the kwargs linlsqr anddroptol`.

source
GraphMatFun.solve_linlsqr!Function
d = solve_linlsqr!(A, b, linlsqr, droptol)

Solves the linear least squares problem

Ad=b.

The argument linlsqr determines how the linear least squares problem is solved. It can be :backslash, :real_backslash, :nrmeq, :real_nrmeq, :svd, or :real_svd. For the latter two options singular values below droptol are disregarded. The :real_X options optimizes d in the space of real vectors. The input matrix A is sometimes overwritten.

source
GraphMatFun.adjust_for_errtype!Function
adjust_for_errtype!(A, b, objfun_vals, errtype)

Adjusts the matrix A and vector b to errtype. A is a matrix, e.g., the Jacobian or system matrix in a least squares problem. b is a vector, e.g., the residuals or the right-hand side in a lieast squares problem. objfun_vals is a vector of objective function values, and errtype can be :abserr or :relerr, i.e., absolute error or relative error.

source