/* ----------------------------------------------------------------------- *//** * * @file conjugate_gradient.sql_in * * @brief SQL function computing Conjugate Gradient * @date March 2011 * * *//* ----------------------------------------------------------------------- */ /** @addtogroup grp_cg @brief Finds the solution to the function \f\$ \boldsymbol Ax = \boldsymbol b \f\$, where \f\$A\f\$ is a symmetric, positive-definite matrix and \f\$x\f\$ and \f\$ \boldsymbol b \f\$ are vectors. \warning This MADlib method is still in early stage development. Interface and implementation are subject to change. This function uses the iterative conjugate gradient method [1] to find a solution to the function: \f[ \boldsymbol Ax = \boldsymbol b \f] where \f\$ \boldsymbol A \f\$ is a symmetric, positive definite matrix and \f\$x\f\$ and \f\$ \boldsymbol b \f\$ are vectors. @anchor syntax @par Function Syntax Conjugate gradient returns x as an array. It has the following syntax.
name_of_row_values_col,
name_of_row_number_col,
aray_of_b_values,
desired_precision
)
Matrix \f\$ \boldsymbol A \f\$ 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. \f\$ \boldsymbol b \f\$ is passed as a FLOAT[] to the function. @anchor examples @examp -# Construct matrix A according to structure.
SELECT * FROM data;
Result:
row_num | row_val
--------+---------
1 | {2,1}
2 | {1,4}
(2 rows)
-# Call the conjugate gradient function.
'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