mgplvm.fast_utils.linear_cg module
This file taken from GPytorch https://github.com/cornellius-gp/gpytorch/blob/c74b8ed8d590fcb1d79808d9ee7cde168588ef99/gpytorch/utils/linear_cg.py
With this License: MIT License
Copyright (c) 2017 Jake Gardner
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- mgplvm.fast_utils.linear_cg.linear_cg(matmul_closure, rhs, n_tridiag=0, tolerance=0.01, eps=1e-10, stop_updating_after=1e-10, max_iter=1000, max_tridiag_iter=20, initial_guess=None, preconditioner=None, verbose=False)[source]
Implements the linear conjugate gradients method for (approximately) solving systems of the form
lhs result = rhs
for positive definite and symmetric matrices.
- Args:
matmul_closure - a function which performs a left matrix multiplication with lhs_mat
rhs - the right-hand side of the equation
n_tridiag - returns a tridiagonalization of the first n_tridiag columns of rhs
tolerance - stop the solve when the max residual is less than this
eps - noise to add to prevent division by zero
stop_updating_after - will stop updating a vector after this residual norm is reached
max_iter - the maximum number of CG iterations
max_tridiag_iter - the maximum size of the tridiagonalization matrix
initial_guess - an initial guess at the solution result
precondition_closure - a functions which left-preconditions a supplied vector
- Returns:
result - a solution to the system (if n_tridiag is 0) result, tridiags - a solution to the system, and corresponding tridiagonal matrices (if n_tridiag > 0)