User Documentation
 All Files Functions Groups
Conjugate Gradient
+ Collaboration diagram for Conjugate Gradient:
Warning
This MADlib method is still in early stage development. There may be some issues that will be addressed in a future version. Interface and implementation is subject to change.
About:
This function uses the iterative conjugate gradient method [1] to find a solution to the function:

\[ \boldsymbol Ax = \boldsymbol b \]

where \( \boldsymbol A \) is a symmetric, positive definite matrix and \(x\) and \( \boldsymbol b \) are vectors.
Input:
Matrix \( \boldsymbol A \) is assumed to be stored in a table where each row consists of at least two columns: array containing values of a given row, row number:
{TABLE|VIEW} matrix_A (
    row_number FLOAT,
    row_values FLOAT[],
)
The number of elements in each row should be the same.

\( \boldsymbol b \) is passed as a FLOAT[] to the function.

Usage:
Conjugate gradient can be called as follows:
SELECT conjugate_gradient('table_name', 
    'name_of_row_values_col', 'name_of_row_number_col', 'aray_of_b_values', 
    'desired_precision');
Function returns x as an array.
Examples:
  1. Construct matrix A according to structure:
    sql> SELECT * FROM data;
    row_num | row_val
    ---------+---------
    1 | {2,1}
    2 | {1,4}
    (2 rows)
  2. Call conjugate gradient function:
    sql> SELECT conjugate_gradient('data','row_val','row_num','{2,1}',1E-6,1);
    INFO: COMPUTE RESIDUAL ERROR 14.5655661859659
    INFO: ERROR 0.144934004246004
    INFO: ERROR 3.12963615962926e-31
    INFO: TEST FINAL ERROR 2.90029642185163e-29
    ---------------------------
    {1,-1.31838984174237e-15}
    (1 row)
Literature:
[1] "Conjugate gradient method" Wikipedia - http://en.wikipedia.org/wiki/Conjugate_gradient_method
See Also
File conjugate_gradient.sql_in documenting the SQL function.