#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "blas.h"
#include "def.h"
#include "pcg.h"
Functions | |
void | init_pcg_status (pcg_status_t *pcgstat) |
Initialize pcg_status_t structure. | |
int | pcg (double *x, pcg_status_t *pcgstat, void(*afun)(double *, const double *, const void *), const void *adata, void(*mfun)(double *, const double *, const void *), const void *mdata, double *b, double tol, double maxiter, int n) |
Solves Ax = b via PCG. |
This PCG implementation is based on the algorithm in the book Numerical Optimization by Nocedal and Write.
void init_pcg_status | ( | pcg_status_t * | pcgstat | ) |
Initialize pcg_status_t structure.
pcgstat | pointer to a pcg_status_t structure. |
References pcg_status_t::flag, pcg_status_t::iter, and pcg_status_t::relres.
Referenced by l1_logreg_train().
int pcg | ( | double * | x, | |
pcg_status_t * | pcgstat, | |||
void(*)(double *, const double *, const void *) | afun, | |||
const void * | adata, | |||
void(*)(double *, const double *, const void *) | mfun, | |||
const void * | mdata, | |||
double * | b, | |||
double | tol, | |||
double | maxiter, | |||
int | n | |||
) |
Solves Ax = b via PCG.
PCG implements a preconditioned conjugate gradient method, which solves a positive definite linear system Ax = b. Here, A is a (m x n) matrix, b is an m-vector, and variable x is an n-vector.
x | double array of size n; This parameter is used for both taking an initial value and returning the result. | |
pcgstat | pointer to a structure of PCG status. | |
afun | pointer to a function that computes A*x. | |
adata | pointer to a data structure for afun; | |
mfun | pointer to a function that computes M^{-1}r. | |
mdata | pointer to a data structure for mfun; | |
b | pointer to a n-vector | |
tol | integer; terminates algorithm when ||r|| < ||b||*tol. | |
maxiter | integer; terminates algorithm when iteration exceeds maxiter. | |
n | integer; dimension of the problem. |
References pcg_status_t::flag, pcg_status_t::iter, and pcg_status_t::relres.
Referenced by compute_searchdir_pcg().