Converted more methods.

This commit is contained in:
Relintai 2023-12-29 19:47:16 +01:00
parent c8b93a107b
commit ef1dcef324
3 changed files with 14 additions and 30 deletions

View File

@ -14,20 +14,17 @@
#include <map> #include <map>
#include <random> #include <random>
/* Ref<MLPPMatrix> MLPPLinAlg::gram_matrix(const Ref<MLPPMatrix> &A) {
std::vector<std::vector<real_t>> MLPPLinAlg::gramMatrix(std::vector<std::vector<real_t>> A) { return A->transposen()->multn(A); // AtA
return matmult(transpose(A), A); // AtA
} }
*/
/* bool MLPPLinAlg::linear_independence_checker(const Ref<MLPPMatrix> &A) {
bool MLPPLinAlg::linearIndependenceChecker(std::vector<std::vector<real_t>> A) { if (gram_matrix(A)->det(A->size().y) == 0) {
if (det(gramMatrix(A), A.size()) == 0) {
return false; return false;
} }
return true; return true;
} }
*/
Ref<MLPPMatrix> MLPPLinAlg::gaussian_noise(int n, int m) { Ref<MLPPMatrix> MLPPLinAlg::gaussian_noise(int n, int m) {
std::random_device rd; std::random_device rd;

View File

@ -37,8 +37,8 @@ class MLPPLinAlg : public Reference {
public: public:
// MATRIX FUNCTIONS // MATRIX FUNCTIONS
//std::vector<std::vector<real_t>> gramMatrix(std::vector<std::vector<real_t>> A); Ref<MLPPMatrix> gram_matrix(const Ref<MLPPMatrix> &A);
//bool linearIndependenceChecker(std::vector<std::vector<real_t>> A); bool linear_independence_checker(const Ref<MLPPMatrix> &A);
Ref<MLPPMatrix> gaussian_noise(int n, int m); Ref<MLPPMatrix> gaussian_noise(int n, int m);

View File

@ -1269,7 +1269,6 @@ void MLPPTests::test_numerical_analysis() {
// Checks for numerical analysis class. // Checks for numerical analysis class.
MLPPNumericalAnalysis num_an; MLPPNumericalAnalysis num_an;
/*
//1 //1
PLOG_MSG("num_an.quadratic_approximationr(f, 0, 1)"); PLOG_MSG("num_an.quadratic_approximationr(f, 0, 1)");
PLOG_MSG(String::num(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("f(1.001)");
PLOG_MSG(String::num(f(1.001))); PLOG_MSG(String::num(f(1.001)));
Ref<MLPPVector> v30; Ref<MLPPVector> v30;
v30.instance(); v30.instance();
v30->resize(3); v30->resize(3);
v30->fill(0); v30->fill(0);
Ref<MLPPVector> v31; Ref<MLPPVector> v31;
v31.instance(); v31.instance();
v31->resize(3); v31->resize(3);
@ -1298,7 +1295,6 @@ void MLPPTests::test_numerical_analysis() {
PLOG_MSG("num_an.quadratic_approximationv(f_mv, v30, v31)"); PLOG_MSG("num_an.quadratic_approximationv(f_mv, v30, v31)");
PLOG_MSG(String::num(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 }; const real_t iqi_arr[] = { 100, 2, 1.5 };
Ref<MLPPVector> iqi(memnew(MLPPVector(iqi_arr, 3))); Ref<MLPPVector> 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("num_an.inv_quadratic_interpolation(&f, iqi, 10)");
PLOG_MSG(String::num(num_an.inv_quadratic_interpolation(&f, iqi, 10))); PLOG_MSG(String::num(num_an.inv_quadratic_interpolation(&f, iqi, 10)));
Ref<MLPPVector> v21; Ref<MLPPVector> v21;
v21.instance(); v21.instance();
v21->resize(2); v21->resize(2);
@ -1351,7 +1346,6 @@ void MLPPTests::test_numerical_analysis() {
//128000015514730496 //128000015514730496
PLOG_MSG("num_an.num_diff_3v(&f_mv, nd3v, 0, 0, 0)"); 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))); PLOG_MSG(String::num(num_an.num_diff_3v(&f_mv, nd3v, 0, 0, 0)));
*/
Ref<MLPPVector> v31t; Ref<MLPPVector> v31t;
v31t.instance(); 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)");
PLOG_MSG(tensor->tensor_vec_mult(tvm)->to_string()); PLOG_MSG(tensor->tensor_vec_mult(tvm)->to_string());
Ref<MLPPVector> v30;
v30.instance();
v30->resize(3);
v30->fill(0);
Ref<MLPPVector> v31;
v31.instance();
v31->resize(3);
v31->fill(1);
//1.00001 //1.00001
PLOG_MSG("num_an.cubic_approximationv(f_mv, v30, v31)"); PLOG_MSG("num_an.cubic_approximationv(f_mv, v30, v31)");
PLOG_MSG(String::num(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); MLPPDualSVC kernelSVM(dt->get_input(), dt->get_output(), 1000);
kernelSVM.gradient_descent(0.0001, 20, ui); kernelSVM.gradient_descent(0.0001, 20, ui);
//SCORE: 0.372583
PLOG_MSG("SCORE: " + String::num(kernelSVM.score())); PLOG_MSG("SCORE: " + String::num(kernelSVM.score()));
/* std::vector<std::vector<real_t>> linearly_independent_mat_arr = {
std::vector<std::vector<real_t>> linearlyIndependentMat = {
{ 1, 2, 3, 4 }, { 1, 2, 3, 4 },
{ 2345384, 4444, 6111, 55 } { 2345384, 4444, 6111, 55 }
}; };
Ref<MLPPMatrix> 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() { void MLPPTests::test_mlpp_vector() {