#ifndef MLPP_LIN_ALG_H #define MLPP_LIN_ALG_H // // LinAlg.hpp // // Created by Marc Melikyan on 1/8/21. // #include "core/math/math_defs.h" #include #include class MLPPLinAlg { public: // MATRIX FUNCTIONS std::vector> gramMatrix(std::vector> A); bool linearIndependenceChecker(std::vector> A); std::vector> gaussianNoise(int n, int m); std::vector> addition(std::vector> A, std::vector> B); std::vector> subtraction(std::vector> A, std::vector> B); std::vector> matmult(std::vector> A, std::vector> B); std::vector> hadamard_product(std::vector> A, std::vector> B); std::vector> kronecker_product(std::vector> A, std::vector> B); std::vector> elementWiseDivision(std::vector> A, std::vector> B); std::vector> transpose(std::vector> A); std::vector> scalarMultiply(real_t scalar, std::vector> A); std::vector> scalarAdd(real_t scalar, std::vector> A); std::vector> log(std::vector> A); std::vector> log10(std::vector> A); std::vector> exp(std::vector> A); std::vector> erf(std::vector> A); std::vector> exponentiate(std::vector> A, real_t p); std::vector> sqrt(std::vector> A); std::vector> cbrt(std::vector> A); std::vector> matrixPower(std::vector> A, int n); std::vector> abs(std::vector> A); real_t det(std::vector> A, int d); real_t trace(std::vector> A); std::vector> cofactor(std::vector> A, int n, int i, int j); std::vector> adjoint(std::vector> A); std::vector> inverse(std::vector> A); std::vector> pinverse(std::vector> A); std::vector> zeromat(int n, int m); std::vector> onemat(int n, int m); std::vector> full(int n, int m, int k); std::vector> sin(std::vector> A); std::vector> cos(std::vector> A); std::vector> rotate(std::vector> A, real_t theta, int axis = -1); std::vector> max(std::vector> A, std::vector> B); real_t max(std::vector> A); real_t min(std::vector> A); std::vector> round(std::vector> A); real_t norm_2(std::vector> A); std::vector> identity(real_t d); std::vector> cov(std::vector> A); std::tuple>, std::vector>> eig(std::vector> A); struct EigenResult { std::vector> eigen_vectors; std::vector> eigen_values; }; EigenResult eigen(std::vector> A); std::tuple>, std::vector>, std::vector>> SVD(std::vector> A); struct SDVResult { std::vector> U; std::vector> S; std::vector> Vt; }; SDVResult svd(std::vector> A); std::vector vectorProjection(std::vector a, std::vector b); std::vector> gramSchmidtProcess(std::vector> A); std::tuple>, std::vector>> QRD(std::vector> A); struct QRDResult { std::vector> Q; std::vector> R; }; QRDResult qrd(std::vector> A); std::tuple>, std::vector>> chol(std::vector> A); struct CholeskyResult { std::vector> L; std::vector> Lt; }; CholeskyResult cholesky(std::vector> A); real_t sum_elements(std::vector> A); std::vector flatten(std::vector> A); std::vector solve(std::vector> A, std::vector b); bool positiveDefiniteChecker(std::vector> A); bool negativeDefiniteChecker(std::vector> A); bool zeroEigenvalue(std::vector> A); void printMatrix(std::vector> A); // VECTOR FUNCTIONS std::vector> outerProduct(std::vector a, std::vector b); // This multiplies a, bT std::vector hadamard_product(std::vector a, std::vector b); std::vector elementWiseDivision(std::vector a, std::vector b); std::vector scalarMultiply(real_t scalar, std::vector a); std::vector scalarAdd(real_t scalar, std::vector a); std::vector addition(std::vector a, std::vector b); std::vector subtraction(std::vector a, std::vector b); std::vector subtractMatrixRows(std::vector a, std::vector> B); std::vector log(std::vector a); std::vector log10(std::vector a); std::vector exp(std::vector a); std::vector erf(std::vector a); std::vector exponentiate(std::vector a, real_t p); std::vector sqrt(std::vector a); std::vector cbrt(std::vector a); real_t dot(std::vector a, std::vector b); std::vector cross(std::vector a, std::vector b); std::vector abs(std::vector a); std::vector zerovec(int n); std::vector onevec(int n); std::vector> diag(std::vector a); std::vector full(int n, int k); std::vector sin(std::vector a); std::vector cos(std::vector a); std::vector max(std::vector a, std::vector b); real_t max(std::vector a); real_t min(std::vector a); std::vector round(std::vector a); real_t euclideanDistance(std::vector a, std::vector b); real_t norm_2(std::vector a); real_t norm_sq(std::vector a); real_t sum_elements(std::vector a); real_t cosineSimilarity(std::vector a, std::vector b); void printVector(std::vector a); // MATRIX-VECTOR FUNCTIONS std::vector> mat_vec_add(std::vector> A, std::vector b); std::vector mat_vec_mult(std::vector> A, std::vector b); // TENSOR FUNCTIONS std::vector>> addition(std::vector>> A, std::vector>> B); std::vector>> elementWiseDivision(std::vector>> A, std::vector>> B); std::vector>> sqrt(std::vector>> A); std::vector>> exponentiate(std::vector>> A, real_t p); std::vector> tensor_vec_mult(std::vector>> A, std::vector b); std::vector flatten(std::vector>> A); void printTensor(std::vector>> A); std::vector>> scalarMultiply(real_t scalar, std::vector>> A); std::vector>> scalarAdd(real_t scalar, std::vector>> A); std::vector>> resize(std::vector>> A, std::vector>> B); std::vector>> hadamard_product(std::vector>> A, std::vector>> B); std::vector>> max(std::vector>> A, std::vector>> B); std::vector>> abs(std::vector>> A); real_t norm_2(std::vector>> A); std::vector>> vector_wise_tensor_product(std::vector>> A, std::vector> B); private: }; #endif /* LinAlg_hpp */