Facial Recognition
UsePCAtoperformfacialrecognition
|
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>
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... | |
vector * | compute_average (matrix *images, int num_images) |
computes the average matrix of all the *vector images More... | |
File containing common linear algebra functions.
Minhyuk Park
computes the average matrix of all the *vector images
images | matrix* a matrix where each column represents an image |
num_images | int number of images in the vector |
References MAT, _matrix::row, _vector::size, VEC, and vector_create().
computes the variance covariance matrix
mat | a matrix* representing the input matrix of deviation scores of size n by k |
References mat_transpose(), matmat_multiply(), matscalar_divide(), and _matrix::row.
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 |
Referenced by eigen().
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 |
Referenced by matvec_multiply().
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 |
References diag_vector(), and mat_identity().
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 |
Referenced by eigen().
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 |
References _matrix::col, MAT, and _matrix::row.
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 |
References _matrix::col, and _matrix::row.
Performs matrix transpose this function will malloc for the user a matrix*.
mat | const matrix* the matrix to be transposed |
References _matrix::col, MAT, matrix_create(), and _matrix::row.
Referenced by covmat().
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 |
References _matrix::col, MAT, matrix_create(), and _matrix::row.
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 |
References _matrix::col, MAT, matrix_create(), and _matrix::row.
Referenced by covmat().
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 |
References _matrix::col, MAT, matrix_create(), and _matrix::row.
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 |
References _matrix::col, and _matrix::row.
Referenced by mat_transpose(), matmat_addition(), matmat_multiply(), matmat_subtraction(), and matscalar_multiply().
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 |
References _matrix::col, and _matrix::row.
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 |
References matscalar_multiply().
Referenced by covmat().
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 |
References _matrix::col, MAT, matrix_create(), and _matrix::row.
Referenced by matscalar_divide().
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 |
References _matrix::col, _vector::data, _matrix::data, dot_product(), _vector::size, VEC, and vector_create().
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 |
References _vector::data, _vector::size, and vector_create().
Referenced by tiff_stream_to_vec().
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 |
References _vector::data, and _vector::size.
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 |
References _vector::padding, and _vector::size.
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 |
References _matrix::col, _vector::data, MAT, _matrix::row, _vector::size, VEC, and vector_create().
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 |
References vecscalar_multiply().
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 |
References _vector::size, VEC, and vector_create().
Referenced by vecscalar_divide().
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 |
References _vector::padding, and _vector::size.
Referenced by compute_average(), matvec_multiply(), tiff_to_vec(), vec_append(), vecmat_multiply(), and vecscalar_multiply().