|
Neural Network
Generic Neural Network for Classification
|
File containing common linear algebra functions. More...
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>#include <time.h>#include <assert.h>#include <iostream>

Go to the source code of this file.
Classes | |
| struct | _vector |
| represents a vector padding is to make sure that matrix and vector both have the same byte size and allignment between matrix and vector they are able to be casted into one another More... | |
| struct | _matrix |
| represents a matrix between matrix and vector they are able to be casted into one another More... | |
Macros | |
| #define | MAT(m, x, y) (m->data[(x * m->col) + y]) |
| macro for element access in a matrix struct | |
| #define | VEC(v, x) (v->data[x]) |
| macro for element access in a vector struct | |
Typedefs | |
| typedef struct _vector | vector |
| represents a vector padding is to make sure that matrix and vector both have the same byte size and allignment between matrix and vector they are able to be casted into one another | |
| typedef struct _matrix | matrix |
| represents a matrix between matrix and vector they are able to be casted into one another | |
Functions | |
| vector * | vector_create (size_t size) |
| Creates a vector this function will malloc the exact space for the required dimensions. More... | |
| matrix * | matrix_create (size_t row, size_t col) |
| Creates a matrix this function will malloc the exact space for the required dimensions. More... | |
| matrix * | vec_to_mat (vector *vec, int orientation) |
| Converts vector into matrix this function will "cast" the vector into a matrix by using the fact that they both have the same size. when calling this function, calling free() on the matrix will free the vector and vice versa. More... | |
| vector * | mat_to_vec (matrix *mat) |
| Converts matrix into vector this function will "cast" the matrix into a vector by using the fact that they both have the same size. when calling this function, calling free() on the vector will free the matrix and vice versa. the input matrix can only be a matrix with dimensions 1 X N (a row matrix) More... | |
| void | matrix_reshape (matrix *mat, size_t row, size_t col) |
| Reshapes the matrix this function will reshape the matrix in constant time. More... | |
| double | dot_product (const double *left, const double *right, int length) |
| Performs dot product on two double* this function will malloc for the user a double arrays must be of same size. More... | |
| vector * | vecscalar_multiply (const vector *vec, const double scalar) |
| Performs scalar multiplication of a vector this function will malloc for the user a vector*. More... | |
| vector * | vecscalar_divide (const vector *vec, const double scalar) |
| Performs scalar division of a vector this function will malloc for the user a vector*. More... | |
| vector * | vecmat_multiply (const vector *vec, const matrix *mat) |
| Performs vector matrix multiplication this function will malloc for the user a vector* if the vector is of size M and the matrix size M by N, the resulting column vector will be of size N. More... | |
| vector * | matvec_multiply (const matrix *mat, const vector *vec) |
| Performs matrix vector multiplication this function will malloc for the user a vector* if the matrix is of size M by N and the vector N, the resulting row vector will be of size M. More... | |
| void | mat_print (const matrix *mat) |
| prints the matrix this function will not modify the matrix and print to stdout More... | |
| void | vec_print (const vector *vec) |
| prints the vector this function will not modify the vector and print to stdout More... | |
| matrix * | matmat_multiply (const matrix *left, const matrix *right) |
| Performs standard matrix multiplication this function will malloc for the user a matrix*. More... | |
| matrix * | matmat_addition (const matrix *left, const matrix *right) |
| Performs standard matrix addition this function will malloc for the user a matrix*. More... | |
| matrix * | matmat_subtraction (const matrix *left, const matrix *right) |
| Performs standard matrix subtration this function will malloc for the user a matrix*. More... | |
| matrix * | matscalar_multiply (const matrix *mat, const double scalar) |
| Performs scalar multiplication of a matrix this function will malloc for the user a matrix*. More... | |
| matrix * | matscalar_divide (const matrix *mat, const double scalar) |
| Performs scalar division of a matrix this function will malloc for the user a matrix*. More... | |
| matrix * | mat_transpose (const matrix *mat) |
| Performs matrix transpose this function will malloc for the user a matrix*. More... | |
| void | vec_append (vector **vec_a, vector *vec_b) |
| Appends vector b to vector a this function will realloc for the user vector a and free vector b. More... | |
| void | eigen (int N, double a[], int it_max, double v[], double d[], int *it_num, int *rot_num) |
| Performs Jacobi eigenvalue iteration this function will required the user to pass in non-null it_num and rot_num it does not malloc but rather requires the caller to malloc space for it. More... | |
| void | mat_identity (int n, double a[]) |
| modifies a matrix to be the identity matrix of size n More... | |
| void | diag_vector (int n, double a[], double v[]) |
| gets the diagonal entries More... | |
| double | frobenius_norm (int n, int k, double a[], double x[], double lambda[]) |
| computes the Frobenius norm in a right eigensystem More... | |
| matrix * | covmat (matrix *mat) |
| computes the variance covariance matrix More... | |
File containing common linear algebra functions.
Minhyuk Park
computes the variance covariance matrix
| mat | a matrix* representing the input matrix of deviation scores of size n by k |
| void diag_vector | ( | int | n, |
| double | a[], | ||
| double | v[] | ||
| ) |
gets the diagonal entries
| n | int the dimension |
| a[] | double[] input the matrix, N by N |
| v[] | double[] output the diagonal entries, N |
| double dot_product | ( | const double * | left, |
| const double * | right, | ||
| int | length | ||
| ) |
Performs dot product on two double* this function will malloc for the user a double arrays must be of same size.
| left | const double* the first vector |
| right | const double* the second vector |
| length | int the size of the vectors |
| void eigen | ( | int | N, |
| double | a[], | ||
| int | it_max, | ||
| double | v[], | ||
| double | d[], | ||
| int * | it_num, | ||
| int * | rot_num | ||
| ) |
Performs Jacobi eigenvalue iteration this function will required the user to pass in non-null it_num and rot_num it does not malloc but rather requires the caller to malloc space for it.
| N | int the dimiension of the input matrix a, which is a N by N matrix |
| a[] | double[] the input matrix which has to be square, real, and symmetric |
| it_max | int maximum number of iterations to stop at |
| v[] | double[]output matrix of eigenvectors, which is a N by N matrix |
| d[] | double[] output matrix of eigenvalues, in descending order |
| it_num | int* output total number of iterations |
| rot_num | int* output total number of rotations |
| double frobenius_norm | ( | int | n, |
| int | k, | ||
| double | a[], | ||
| double | x[], | ||
| double | lambda[] | ||
| ) |
computes the Frobenius norm in a right eigensystem
| n | int the dimension of the matrix |
| k | int the number of eigen vectors |
| a[] | double[] input matrix of size n by n |
| x[] | double[] input vector of eigenvectors of size k |
| lamdba[] | double[] input vector of eigen values |
| void mat_identity | ( | int | n, |
| double | a[] | ||
| ) |
modifies a matrix to be the identity matrix of size n
| n | int the dimension |
| a[] | double output identity matrix |
| void mat_print | ( | const matrix * | mat | ) |
prints the matrix this function will not modify the matrix and print to stdout
| mat | const matrix* the matrix to be printed |
Converts matrix into vector this function will "cast" the matrix into a vector by using the fact that they both have the same size. when calling this function, calling free() on the vector will free the matrix and vice versa. the input matrix can only be a matrix with dimensions 1 X N (a row matrix)
| mat | matrix* to be converted in terms of the newly formed vector |
Performs matrix transpose this function will malloc for the user a matrix*.
| mat | const matrix* the matrix to be transposed |
Referenced by Network::Network().
Performs standard matrix addition this function will malloc for the user a matrix*.
| left | const matrix* the matrix to be added to |
| right | const matrix* the matrix to be added |
Referenced by Network::Network().
Performs standard matrix multiplication this function will malloc for the user a matrix*.
| left | const matrix* the matrix to be multiplied to |
| right | const matrix* the matrix to be multiplied |
Referenced by Network::Network().
Performs standard matrix subtration this function will malloc for the user a matrix*.
| left | const matrix* the matrix to be subtracted from |
| right | const matrix* the matrix to be subtrated |
| matrix* matrix_create | ( | size_t | row, |
| size_t | col | ||
| ) |
Creates a matrix this function will malloc the exact space for the required dimensions.
| row | size_t the desired number of rows in the matrix |
| col | size_t the desired number of columns in the matrix |
Referenced by Network::Network().
| void matrix_reshape | ( | matrix * | mat, |
| size_t | row, | ||
| size_t | col | ||
| ) |
Reshapes the matrix this function will reshape the matrix in constant time.
| mat | matrix* to be reshaped |
| row | size_t the new row |
| col | size_t the new column |
Performs scalar division of a matrix this function will malloc for the user a matrix*.
| mat | const matrix* the input matrix |
| scalar | const double the input scalar |
Performs scalar multiplication of a matrix this function will malloc for the user a matrix*.
| mat | const matrix* the input matrix |
| scalar | const double the input scalar |
Performs matrix vector multiplication this function will malloc for the user a vector* if the matrix is of size M by N and the vector N, the resulting row vector will be of size M.
| mat | const matrix* the input matrix |
| vec | const vector* the input vector |
Appends vector b to vector a this function will realloc for the user vector a and free vector b.
| vec_a | vector** the vector to be realloced |
| vec_b | vector* the vector to be appended and freed thereafter |
| void vec_print | ( | const vector * | vec | ) |
prints the vector this function will not modify the vector and print to stdout
| vec | const vector* the vector to be printed |
Converts vector into matrix this function will "cast" the vector into a matrix by using the fact that they both have the same size. when calling this function, calling free() on the matrix will free the vector and vice versa.
| vec | vector* to be converted |
| orientation | int 1 is Row-wise and 0 is Column-wise in terms of the newly formed matrix |
Performs vector matrix multiplication this function will malloc for the user a vector* if the vector is of size M and the matrix size M by N, the resulting column vector will be of size N.
| vec | const vector* the input vector |
| mat | const matrix* the input matrix |
Performs scalar division of a vector this function will malloc for the user a vector*.
| vec | const vector* the input vector |
| scalar | const double the input scalar |
Performs scalar multiplication of a vector this function will malloc for the user a vector*.
| vec | const vector* the input vector |
| scalar | const double the input scalar |
| vector* vector_create | ( | size_t | size | ) |
Creates a vector this function will malloc the exact space for the required dimensions.
| size | size_t the desired number of elements in the vecrtor |
Referenced by Network::Network().
1.8.11