#ifndef MLPP_LIN_ALG_H #define MLPP_LIN_ALG_H /*************************************************************************/ /* lin_alg.h */ /*************************************************************************/ /* This file is part of: */ /* PMLPP Machine Learning Library */ /* https://github.com/Relintai/pmlpp */ /*************************************************************************/ /* Copyright (c) 2023-present Péter Magyar. */ /* Copyright (c) 2022-2023 Marc Melikyan */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ //TODO Methods here should probably use error macros in a way where they get disabled in non-tools(?) (maybe release?) builds #ifndef GDNATIVE #include "core/math/math_defs.h" #include "core/object/reference.h" #else #include "core/defs.h" #include "core/math_funcs.h" #include "gen/resource.h" #endif #include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_vector.h" #include #include class MLPPLinAlg : public Reference { GDCLASS(MLPPLinAlg, Reference); public: // MATRIX FUNCTIONS Ref gram_matrix(const Ref &A); bool linear_independence_checker(const Ref &A); Ref gaussian_noise(int n, int m); Ref additionnm(const Ref &A, const Ref &B); Ref subtractionnm(const Ref &A, const Ref &B); Ref matmultnm(const Ref &A, const Ref &B); Ref hadamard_productnm(const Ref &A, const Ref &B); Ref kronecker_productnm(const Ref &A, const Ref &B); Ref division_element_wisenvnm(const Ref &A, const Ref &B); Ref transposenm(const Ref &A); Ref scalar_multiplynm(real_t scalar, const Ref &A); Ref scalar_addnm(real_t scalar, const Ref &A); Ref lognm(const Ref &A); Ref log10nm(const Ref &A); Ref expnm(const Ref &A); Ref erfnm(const Ref &A); Ref exponentiatenm(const Ref &A, real_t p); Ref sqrtnm(const Ref &A); Ref cbrtnm(const Ref &A); //std::vector> matrixPower(std::vector> A, int n); Ref absnm(const Ref &A); real_t detm(const Ref &A, int d); //real_t trace(std::vector> A); Ref cofactornm(const Ref &A, int n, int i, int j); Ref adjointnm(const Ref &A); Ref inversenm(const Ref &A); Ref pinversenm(const Ref &A); Ref zeromatnm(int n, int m); Ref onematnm(int n, int m); Ref fullnm(int n, int m, int k); Ref sinnm(const Ref &A); Ref cosnm(const Ref &A); Ref maxnm(const Ref &A, const Ref &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); Ref identitym(int d); Ref covnm(const Ref &A); struct EigenResult { Ref eigen_vectors; Ref eigen_values; }; EigenResult eigen(Ref A); struct SVDResult { Ref U; Ref S; Ref Vt; }; SVDResult svd(const Ref &A); Ref vector_projection(const Ref &a, const Ref &b); Ref gram_schmidt_process(const Ref &A); struct QRDResult { Ref Q; Ref R; }; QRDResult qrd(const Ref &A); struct CholeskyResult { Ref L; Ref Lt; }; CholeskyResult cholesky(const Ref &A); //real_t sum_elements(std::vector> A); Ref flattenvvnv(const Ref &A); Ref solve(const Ref &A, const Ref &b); bool positive_definite_checker(const Ref &A); bool negative_definite_checker(const Ref &A); bool zero_eigenvalue(const Ref &A); // VECTOR FUNCTIONS Ref flattenmnv(const Vector> &A); Ref hadamard_productnv(const Ref &a, const Ref &b); void hadamard_productv(const Ref &a, const Ref &b, Ref out); Ref division_element_wisenv(const Ref &a, const Ref &b); Ref scalar_multiplynv(real_t scalar, const Ref &a); void scalar_multiplyv(real_t scalar, const Ref &a, Ref out); Ref scalar_addnv(real_t scalar, const Ref &a); void scalar_addv(real_t scalar, const Ref &a, Ref out); Ref additionnv(const Ref &a, const Ref &b); void additionv(const Ref &a, const Ref &b, Ref out); Ref subtractionnv(const Ref &a, const Ref &b); void subtractionv(const Ref &a, const Ref &b, Ref out); Ref lognv(const Ref &a); Ref log10nv(const Ref &a); Ref expnv(const Ref &a); Ref erfnv(const Ref &a); Ref exponentiatenv(const Ref &a, real_t p); Ref sqrtnv(const Ref &a); Ref cbrtnv(const Ref &a); real_t dotnv(const Ref &a, const Ref &b); //std::vector cross(std::vector a, std::vector b); Ref absv(const Ref &a); Ref zerovecnv(int n); Ref onevecnv(int n); Ref fullnv(int n, int k); Ref sinnv(const Ref &a); Ref cosnv(const Ref &a); Ref maxnvv(const Ref &a, const Ref &b); real_t maxvr(const Ref &a); real_t minvr(const Ref &a); //std::vector round(std::vector a); real_t euclidean_distance(const Ref &a, const Ref &b); real_t euclidean_distance_squared(const Ref &a, const Ref &b); /* real_t norm_2(std::vector a); */ real_t norm_sqv(const Ref &a); real_t sum_elementsv(const Ref &a); //real_t cosineSimilarity(std::vector a, std::vector b); // MATRIX-VECTOR FUNCTIONS Ref mat_vec_multnv(const Ref &A, const Ref &b); Ref subtract_matrix_rowsnv(const Ref &a, const Ref &B); Ref outer_product(const Ref &a, const Ref &b); // This multiplies a, bT Ref mat_vec_addnm(const Ref &A, const Ref &b); Ref diagnm(const Ref &a); // TENSOR FUNCTIONS Vector> additionnvt(const Vector> &A, const Vector> &B); void division_element_wisevt(const Vector> &A, const Vector> &B); Vector> division_element_wisenvnvt(const Vector> &A, const Vector> &B); Vector> sqrtnvt(const Vector> &A); Vector> exponentiatenvt(const Vector> &A, real_t p); //std::vector> tensor_vec_mult(std::vector>> A, std::vector b); //std::vector flatten(std::vector>> A); Vector> scalar_multiplynvt(real_t scalar, Vector> A); Vector> scalar_addnvt(real_t scalar, Vector> A); void resizevt(Vector> &r_target, const Vector> &A); Vector> resizencvt(const Vector> &A); //std::vector>> hadamard_product(std::vector>> A, std::vector>> B); Vector> maxnvt(const Vector> &A, const Vector> &B); Vector> absnvt(const Vector> &A); //real_t norm_2(std::vector>> A); //std::vector>> vector_wise_tensor_product(std::vector>> A, std::vector> B); protected: static void _bind_methods(); }; #endif /* LinAlg_hpp */