MADlib  1.4.1
User Documentation
 All Files Functions Variables Groups
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.

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.

Function Syntax
Conjugate gradient returns x as an array. It has the following syntax.
conjugate_gradient( table_name, 
                    name_of_row_values_col, 
                    name_of_row_number_col, 
                    aray_of_b_values, 
                    desired_precision 
                  )

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.

Examples
  1. Construct matrix A according to structure.
    SELECT * FROM data;
    
    Result:
     row_num | row_val 
     --------+---------
           1 | {2,1}
           2 | {1,4}
    (2 rows)
    
  2. Call the conjugate gradient function.
    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
        conjugate_gradient     
     --------------------------
     {1,-1.31838984174237e-15}
    (1 row)
    

Literature
[1] "Conjugate gradient method" Wikipedia - http://en.wikipedia.org/wiki/Conjugate_gradient_method

Related Topics
File conjugate_gradient.sql_in documenting the SQL function.