CCL Library  1.0
ccl_math.h
Go to the documentation of this file.
1 
6 #ifndef __CCL_MATH_H
7 #define __CCL_MATH_H
8 
9 #include <assert.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdbool.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 #include <gsl/gsl_blas.h>
18 #include <gsl/gsl_math.h>
19 #include <gsl/gsl_statistics.h>
20 #include <gsl/gsl_rng.h>
21 #include <gsl/gsl_randist.h>
22 #include <gsl/gsl_permutation.h>
23 #include <gsl/gsl_sort.h>
24 
31 typedef struct {
32  gsl_matrix *V;
33  gsl_matrix *Sigma_pinv;
34  gsl_matrix *U;
35  gsl_matrix *A_pinv;
36  gsl_matrix *A;
37  gsl_matrix *_tmp_mat;
38  gsl_vector *_tmp_vec;
39  gsl_vector *u;
40 }MP_INV_WS;
41 
50 void ccl_mat_add (double *A, const double *B, int row, int col);
51 
60 void ccl_mat_sub(double *A, const double *B, int row, int col);
61 
68 double ccl_vec_sum(double* vec, int size);
69 
80 void mat_hotz_app ( double *A, int i,int j, const double *B,int k,int d,double* c);
81 
92 void mat_vert_app (const double *A, int i, int j, const double *B, int k, int d, double * c);
93 
104 void ccl_dot_product (const double *A, int i,int j, const double *B,int k,int d,double *C);
105 
113 void ccl_mat_inv(const double *A, int i, int j, double *invA);
114 
122 void ccl_MP_pinv(const double *A_in, int row, int col, double *invA);
123 
133 int ccl_MP_inv_ws_alloc(MP_INV_WS *ws, int n, int m);
134 
145 //void ccl_MP_pinv_test(const double *A_in, int row, int col, MP_INV_WS *ws,double *invA);
146 
154 void linspace(double min, double max, double n, double *y);
155 
165 void repmat(const double *mat, int row, int col, int rows, int cols, double *A);
166 
174 void repvec(const gsl_vector *vec, int rows, int cols, gsl_matrix * A);
175 
182 void repvvec(const double *vec, int size, int rows, double *A);
183 
191 void flt_mat(const double *mat, int row, int col, double *vec);
192 
201 void ccl_mat_var(const double* data_in,int row,int col,int axis,double * var);
202 
207 void print_mat(gsl_matrix *mat);
208 
215 void print_mat_d(double *mat, int row, int col);
216 
223 void print_mat_i(int * mat,int row,int col);
224 
230 void vec_to_mat(const gsl_vector *vec, gsl_matrix *mat);
231 
239 void nround(const double *n, int size, unsigned int c, double *ret);
240 
248 void generate_kmeans_centres(const double * X, const int dim_x,const int dim_n, const int dim_b,double * centres);
249 
258 void ccl_get_sub_mat_cols(const double * mat, const int row, const int col,const int * ind, int size, double * ret);
259 
269 int ccl_mat_distance(const double *A,const int a_i,const int a_j,const double *B,const int b_i,const int b_j,double * D);
270 
278 void ccl_mat_sum(const double *mat, const int i, const int j, const int axis, double * ret);
279 
288 void ccl_mat_min(const double * mat,const int i,const int j,const int axis,double* val,int* indx);
289 
297 void ccl_mat_mean(const double *mat,const int i, const int j,const int axis,double*val);
298 
309 int ccl_find_index_int(const int *a, const int num_elements, const int operand, const int value,int* idx);
310 
321 int ccl_find_index_double(const double *a, const int num_elements, const int operand, const double value,int* idx);
322 
330 void ccl_mat_set_col(double * mat, int i, int j, int c, double* vec);
331 
342 void ccl_gaussian_rbf(const double * X,int i, int j,const double *C,int k, int d,double s,double * BX);
343 
350 void ccl_mat_transpose(const double* mat, int i, int j, double* mat_T);
351 
361 int ccl_any(double* vec, double epx, int size, int op);
362 
369 void ccl_mat_reshape(const double *vec, int i, int j, double *mat);
370 #ifdef __cplusplus
371 }
372 #endif
373 #endif
gsl_matrix * U
Pad to full matrix of A.
Definition: ccl_math.h:34
void ccl_mat_reshape(const double *vec, int i, int j, double *mat)
Reshape vector to matrix.
void repvec(const gsl_vector *vec, int rows, int cols, gsl_matrix *A)
Replicate vector.
gsl_matrix * Sigma_pinv
Pseudo inverse of sigma.
Definition: ccl_math.h:33
gsl_matrix * V
SVD return of A.
Definition: ccl_math.h:32
void ccl_mat_sum(const double *mat, const int i, const int j, const int axis, double *ret)
Summation of a matrix.
gsl_matrix * A_pinv
Pseodo inverse of A.
Definition: ccl_math.h:35
void mat_vert_app(const double *A, int i, int j, const double *B, int k, int d, double *c)
Append matrix vertically.
void ccl_MP_pinv(const double *A_in, int row, int col, double *invA)
Matrix inverse of arbitrary matrix.
void linspace(double min, double max, double n, double *y)
Equally divided space.
void ccl_mat_add(double *A, const double *B, int row, int col)
Matrix addition.
int ccl_MP_inv_ws_free(MP_INV_WS *ws)
Free the workspace memory for MP_INV_WS.
gsl_vector * u
SVD return of A.
Definition: ccl_math.h:39
void ccl_gaussian_rbf(const double *X, int i, int j, const double *C, int k, int d, double s, double *BX)
Radial basis function.
void ccl_mat_min(const double *mat, const int i, const int j, const int axis, double *val, int *indx)
Minimum values of a matrix.
int ccl_MP_inv_ws_alloc(MP_INV_WS *ws, int n, int m)
Allocates the workspace memory for MP_INV_WS.
void ccl_mat_var(const double *data_in, int row, int col, int axis, double *var)
Variances of a matrix.
gsl_vector * _tmp_vec
A temporal vector.
Definition: ccl_math.h:38
int ccl_mat_distance(const double *A, const int a_i, const int a_j, const double *B, const int b_i, const int b_j, double *D)
Distance of two matrices.
double ccl_vec_sum(double *vec, int size)
Sum of a vector.
void ccl_mat_inv(const double *A, int i, int j, double *invA)
Matrix inverse of square matrix.
void ccl_dot_product(const double *A, int i, int j, const double *B, int k, int d, double *C)
Dot product of two matrix.
void generate_kmeans_centres(const double *X, const int dim_x, const int dim_n, const int dim_b, double *centres)
K mean algorithm.
gsl_matrix * _tmp_mat
A temporal matrix.
Definition: ccl_math.h:37
void print_mat_d(double *mat, int row, int col)
Print double matrix.
void ccl_mat_transpose(const double *mat, int i, int j, double *mat_T)
Matrix transpose.
void vec_to_mat(const gsl_vector *vec, gsl_matrix *mat)
Convert vector type to matrix type.
gsl_matrix * A
Copy of input matrix A.
Definition: ccl_math.h:36
int ccl_find_index_double(const double *a, const int num_elements, const int operand, const double value, int *idx)
Find index of an array of integers. operand 1: = ; 2 >=; 3<= .
void ccl_get_sub_mat_cols(const double *mat, const int row, const int col, const int *ind, int size, double *ret)
Get sub cols of a matrix.
int ccl_any(double *vec, double epx, int size, int op)
Return true if any of the element in the vector satify the tolerance: op==0 '>=', op==1 '<='...
This structure describes the workspace memory of calculating matrix pseudo inverse MP_INV_WS...
Definition: ccl_math.h:31
void ccl_mat_mean(const double *mat, const int i, const int j, const int axis, double *val)
Mean values of a matrix.
void flt_mat(const double *mat, int row, int col, double *vec)
Flatten matrix to vector.
void print_mat_i(int *mat, int row, int col)
Print int matrix.
void print_mat(gsl_matrix *mat)
Print GSL matrix.
int ccl_find_index_int(const int *a, const int num_elements, const int operand, const int value, int *idx)
Find index of an array of integers.
void repvvec(const double *vec, int size, int rows, double *A)
Replicate vector vertically (to be removed).
void ccl_mat_set_col(double *mat, int i, int j, int c, double *vec)
Find index of an array of doubles. operand 1: = ; 2 >=; 3<= .
void nround(const double *n, int size, unsigned int c, double *ret)
Round double array to some decimal.
void ccl_mat_sub(double *A, const double *B, int row, int col)
Matrix subtraction.
void repmat(const double *mat, int row, int col, int rows, int cols, double *A)
Replicate matrix.
void mat_hotz_app(double *A, int i, int j, const double *B, int k, int d, double *c)
Append matrix horizontally.