From ef1dcef324f979cf6f8431412683baf6211be0dc Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 29 Dec 2023 19:47:16 +0100 Subject: [PATCH] Converted more methods. --- mlpp/lin_alg/lin_alg.cpp | 13 +++++-------- mlpp/lin_alg/lin_alg.h | 4 ++-- test/mlpp_tests.cpp | 27 +++++++-------------------- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/mlpp/lin_alg/lin_alg.cpp b/mlpp/lin_alg/lin_alg.cpp index 824f649..a7bd957 100644 --- a/mlpp/lin_alg/lin_alg.cpp +++ b/mlpp/lin_alg/lin_alg.cpp @@ -14,20 +14,17 @@ #include #include -/* -std::vector> MLPPLinAlg::gramMatrix(std::vector> A) { - return matmult(transpose(A), A); // AtA +Ref MLPPLinAlg::gram_matrix(const Ref &A) { + return A->transposen()->multn(A); // AtA } -*/ -/* -bool MLPPLinAlg::linearIndependenceChecker(std::vector> A) { - if (det(gramMatrix(A), A.size()) == 0) { +bool MLPPLinAlg::linear_independence_checker(const Ref &A) { + if (gram_matrix(A)->det(A->size().y) == 0) { return false; } + return true; } -*/ Ref MLPPLinAlg::gaussian_noise(int n, int m) { std::random_device rd; diff --git a/mlpp/lin_alg/lin_alg.h b/mlpp/lin_alg/lin_alg.h index ada3813..e3199b9 100644 --- a/mlpp/lin_alg/lin_alg.h +++ b/mlpp/lin_alg/lin_alg.h @@ -37,8 +37,8 @@ class MLPPLinAlg : public Reference { public: // MATRIX FUNCTIONS - //std::vector> gramMatrix(std::vector> A); - //bool linearIndependenceChecker(std::vector> A); + Ref gram_matrix(const Ref &A); + bool linear_independence_checker(const Ref &A); Ref gaussian_noise(int n, int m); diff --git a/test/mlpp_tests.cpp b/test/mlpp_tests.cpp index c50bfa8..de3e2a7 100644 --- a/test/mlpp_tests.cpp +++ b/test/mlpp_tests.cpp @@ -1269,7 +1269,6 @@ void MLPPTests::test_numerical_analysis() { // Checks for numerical analysis class. MLPPNumericalAnalysis num_an; - /* //1 PLOG_MSG("num_an.quadratic_approximationr(f, 0, 1)"); PLOG_MSG(String::num(num_an.quadratic_approximationr(f, 0, 1))); @@ -1282,13 +1281,11 @@ void MLPPTests::test_numerical_analysis() { PLOG_MSG("f(1.001)"); PLOG_MSG(String::num(f(1.001))); - Ref v30; v30.instance(); v30->resize(3); v30->fill(0); - Ref v31; v31.instance(); v31->resize(3); @@ -1298,7 +1295,6 @@ void MLPPTests::test_numerical_analysis() { PLOG_MSG("num_an.quadratic_approximationv(f_mv, v30, v31)"); PLOG_MSG(String::num(num_an.quadratic_approximationv(f_mv, v30, v31))); - const real_t iqi_arr[] = { 100, 2, 1.5 }; Ref iqi(memnew(MLPPVector(iqi_arr, 3))); @@ -1316,7 +1312,6 @@ void MLPPTests::test_numerical_analysis() { PLOG_MSG("num_an.inv_quadratic_interpolation(&f, iqi, 10)"); PLOG_MSG(String::num(num_an.inv_quadratic_interpolation(&f, iqi, 10))); - Ref v21; v21.instance(); v21->resize(2); @@ -1351,7 +1346,6 @@ void MLPPTests::test_numerical_analysis() { //128000015514730496 PLOG_MSG("num_an.num_diff_3v(&f_mv, nd3v, 0, 0, 0)"); PLOG_MSG(String::num(num_an.num_diff_3v(&f_mv, nd3v, 0, 0, 0))); - */ Ref v31t; v31t.instance(); @@ -1434,16 +1428,6 @@ void MLPPTests::test_numerical_analysis() { PLOG_MSG("tensor->tensor_vec_mult(tvm)"); PLOG_MSG(tensor->tensor_vec_mult(tvm)->to_string()); - Ref v30; - v30.instance(); - v30->resize(3); - v30->fill(0); - - Ref v31; - v31.instance(); - v31->resize(3); - v31->fill(1); - //1.00001 PLOG_MSG("num_an.cubic_approximationv(f_mv, v30, v31)"); PLOG_MSG(String::num(num_an.cubic_approximationv(f_mv, v30, v31))); @@ -1537,16 +1521,19 @@ void MLPPTests::test_support_vector_classification_kernel(bool ui) { MLPPDualSVC kernelSVM(dt->get_input(), dt->get_output(), 1000); kernelSVM.gradient_descent(0.0001, 20, ui); + + //SCORE: 0.372583 PLOG_MSG("SCORE: " + String::num(kernelSVM.score())); - /* - std::vector> linearlyIndependentMat = { + std::vector> linearly_independent_mat_arr = { { 1, 2, 3, 4 }, { 2345384, 4444, 6111, 55 } }; + Ref linearly_independent_mat(memnew(MLPPMatrix(linearly_independent_mat_arr))); - std::cout << "True of false: linearly independent?: " << std::boolalpha << alg.linearIndependenceChecker(linearlyIndependentMat) << std::endl; - */ + //true + PLOG_MSG("alg.linear_independence_checker(linearly_independent_mat)"); + PLOG_MSG(String::bool_str(alg.linear_independence_checker(linearly_independent_mat))); } void MLPPTests::test_mlpp_vector() {