kona.linalg.solvers.util

Functions

kona.linalg.solvers.util.abs_sign(x, y)[source]

Returns the value \(|x|\mathsf{sign}(y)\); used in GMRES, for example.

Parameters:
  • x (float) –
  • y (float) –
Returns:

float

Return type:

\(|x|\mathsf{sign}(y)\)

kona.linalg.solvers.util.calc_epsilon(eval_at_norm, mult_by_norm)[source]

Determines the perturbation parameter for forward-difference based matrix-vector products

Parameters:
  • eval_at_norm (float) – the norm of the vector at which the Jacobian-like matrix is evaluated
  • mult_by_norm (float) – the norm of the vector that is being multiplied
Returns:

float

Return type:

perturbation parameter

kona.linalg.solvers.util.eigen_decomp(A)[source]

Returns the (sorted) eigenvalues and eigenvectors of the symmetric part of a square matrix.

The matrix A is stored in dense format and is not assumed to be exactly symmetric. The eigenvalues are found by calling np.linalg.eig, which is given 0.5*(A^T + A) as the input matrix, not A itself.

Parameters:A (2-D numpy.ndarray) – matrix stored in dense format; not necessarily symmetric
Returns:
  • eig_vals (1-D numpy.ndarray) – the eigenvalues in ascending order
  • eig_vecs (2-D numpy.ndarray) – the eigenvectors sorted appropriated
kona.linalg.solvers.util.apply_givens(s, c, h1, h2)[source]

Applies a Givens rotation to a 2-vector

Parameters:
  • s (float) – sine of the Givens rotation angle
  • c (float) – cosine of the Givens rotation angle
  • h1 (float) – first element of 2x1 vector being transformed
  • h2 (float) – second element of 2x1 vector being transformed
kona.linalg.solvers.util.generate_givens(dx, dy)[source]

Generates the Givens rotation matrix for a given 2-vector

Based on givens() of SPARSKIT, which is based on p.202 of “Matrix Computations” by Golub and van Loan.

Parameters:
  • dx (float) – element of 2x1 vector being transformed
  • dy (float) – element of 2x1 vector being set to zero
Returns:

  • dx (float) – element of 2x1 vector being transformed
  • dy (float) – element of 2x1 vector being set to zero
  • s (float) – sine of the Givens rotation angle
  • c (float) – cosine of the Givens rotation angle

kona.linalg.solvers.util.lanczos_tridiag(mat_vec, Q, Q_init=False)[source]

Uses the traditional Lanczos algorithm to compute a tridiagonalization.

Since this is based on the Arnoldi’s method, we only require a matrix-vector product for the matrix of interest, and not the full explicit matrix itself.

Parameters:
  • mat_vec (function) – Matrix-vector product for a symmetric matrix.
  • Q (List[KonaVector]) – Pre-allocated subspace array containing KonaVectors matching the vector-type of the product
  • Q_init (boolean) – If True, start the V-subspace with the Q[0] already stored. If ‘False’, generate a vector of ones in Q[0] to start with.
Returns:

T – Tri-diagonalization of the matrix

Return type:

array_like

kona.linalg.solvers.util.lanczos_bidiag(fwd_mat_vec, Q, q_work, rev_mat_vec, P, p_work, Q_init=False)[source]

Uses the bi-orthogonal Lanczos algorithm to bidiagonalize a matrix.

Since this is based on the Arnoldi’s method, we only require a matrix-vector product for the matrix of interest, and not the full explicit matrix itself.

Parameters:
  • fwd_mat_vec (function) – Forward matrix-vector product for the matrix of interest
  • Q (List[KonaVector]) – Pre-allocated subspace array containing KonaVectors matching the vector-type of the forward product
  • q_work (KonaVector) – Work vector matching the KonaVector-type of the forward product
  • rev_mat_vec (function) – Reverse (transpose) matrix-vector product for the matrix of interest
  • P (List[KonaVector]) – Pre-allocated subspace array containing KonaVectors matching the vector-type of the reverse (transpose) product
  • p_work (KonaVector) – Work vector matching the KonaVector-type of the reverse product
  • Q_init (boolean) – If True, start the V-subspace with the Q[0] already stored. If ‘False’, generate a vector of ones in Q[0] to start with.
Returns:

B – Truncated bi-diagonalization of the matrix

Return type:

array_like

kona.linalg.solvers.util.solve_tri(A, b, lower=False)[source]

Solve an upper-triangular system \(Ux = b\) (lower=False) or lower-triangular system \(Lx = b\) (lower=True)

Parameters:
  • A (2-D numpy.matrix) – a triangular matrix
  • b (1-D numpy.ndarray) – the right-hand side of the system
  • x (1-D numpy.ndarray) – on exit, the solution
  • lower (boolean) – if True, A stores an lower-triangular matrix; stores an upper-triangular matrix otherwise
kona.linalg.solvers.util.solve_trust_reduced(H, g, radius)[source]

Solves the reduced-space trust-region subproblem (the secular equation)

This assumes the reduced space objective is in the form \(g^Tx + \frac{1}{2}x^T H x\). Furthermore, the case \(g = 0\) is not handled presently.

Parameters:
  • H (2-D numpy.matrix) – reduced-space Hessian
  • g (1-D numpy.ndarray) – gradient in the reduced space
  • radius (float) – trust-region radius
Returns:

  • y (1-D numpy.ndarray) – solution to reduced-space trust-region problem
  • lam (float) – Lagrange multiplier value
  • pred (float) – predicted decrease in the objective

kona.linalg.solvers.util.mod_gram_schmidt(i, B, C, w, normalize=False)[source]
kona.linalg.solvers.util.mod_GS_normalize(i, Hsbg, w)[source]
kona.linalg.solvers.util.write_header(out_file, solver_name, res_tol, res_init)[source]

Writes krylov solver data file header text.

Parameters:
  • out_file (file) – File handle for write destination
  • solver_name (string) – Name of Krylov solver type.
  • res_tol (float) – Residual tolerance for convergence.
  • res_init (float) – Initial residual norm.
kona.linalg.solvers.util.write_history(out_file, num_iter, res, res_init)[source]

Writes krylov solver data file iteration history.

Parameters:
  • out_file (file) – File handle for write destination
  • num_iter (int) – Current iteration count.
  • res (float) – Current residual norm.
  • res_init (float) – Initial residual norm.