mirror of
https://github.com/Relintai/pmlpp.git
synced 2025-05-03 17:57:56 +02:00
More reworks.
This commit is contained in:
parent
3a297ae5d4
commit
b39e0acdf8
@ -1073,7 +1073,7 @@ std::tuple<std::vector<std::vector<real_t>>, std::vector<std::vector<real_t>>> M
|
|||||||
return { eigenvectors, a_new };
|
return { eigenvectors, a_new };
|
||||||
}
|
}
|
||||||
|
|
||||||
MLPPLinAlg::EigenResult MLPPLinAlg::eigen(std::vector<std::vector<real_t>> A) {
|
MLPPLinAlg::EigenResultOld MLPPLinAlg::eigen_old(std::vector<std::vector<real_t>> A) {
|
||||||
/*
|
/*
|
||||||
A (the entered parameter) in most use cases will be X'X, XX', etc. and must be symmetric.
|
A (the entered parameter) in most use cases will be X'X, XX', etc. and must be symmetric.
|
||||||
That simply means that 1) X' = X and 2) X is a square matrix. This function that computes the
|
That simply means that 1) X' = X and 2) X is a square matrix. This function that computes the
|
||||||
@ -1191,7 +1191,7 @@ MLPPLinAlg::EigenResult MLPPLinAlg::eigen(std::vector<std::vector<real_t>> A) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EigenResult res;
|
EigenResultOld res;
|
||||||
res.eigen_vectors = eigenvectors;
|
res.eigen_vectors = eigenvectors;
|
||||||
res.eigen_values = a_new;
|
res.eigen_values = a_new;
|
||||||
|
|
||||||
@ -1199,8 +1199,8 @@ MLPPLinAlg::EigenResult MLPPLinAlg::eigen(std::vector<std::vector<real_t>> A) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MLPPLinAlg::SDVResultOld MLPPLinAlg::SVD(std::vector<std::vector<real_t>> A) {
|
MLPPLinAlg::SDVResultOld MLPPLinAlg::SVD(std::vector<std::vector<real_t>> A) {
|
||||||
EigenResult left_eigen = eigen(matmult(A, transpose(A)));
|
EigenResultOld left_eigen = eigen_old(matmult(A, transpose(A)));
|
||||||
EigenResult right_eigen = eigen(matmult(transpose(A), A));
|
EigenResultOld right_eigen = eigen_old(matmult(transpose(A), A));
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> singularvals = sqrt(left_eigen.eigen_values);
|
std::vector<std::vector<real_t>> singularvals = sqrt(left_eigen.eigen_values);
|
||||||
std::vector<std::vector<real_t>> sigma = zeromat(A.size(), A[0].size());
|
std::vector<std::vector<real_t>> sigma = zeromat(A.size(), A[0].size());
|
||||||
@ -1218,9 +1218,10 @@ MLPPLinAlg::SDVResultOld MLPPLinAlg::SVD(std::vector<std::vector<real_t>> A) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
MLPPLinAlg::SDVResultOld MLPPLinAlg::svd(std::vector<std::vector<real_t>> A) {
|
MLPPLinAlg::SDVResult MLPPLinAlg::svd(const Ref<MLPPMatrix> &A) {
|
||||||
EigenResult left_eigen = eigen(matmult(A, transpose(A)));
|
/*
|
||||||
EigenResult right_eigen = eigen(matmult(transpose(A), A));
|
EigenResultOld left_eigen = eigen(matmult(A, transpose(A)));
|
||||||
|
EigenResultOld right_eigen = eigen(matmult(transpose(A), A));
|
||||||
|
|
||||||
std::vector<std::vector<real_t>> singularvals = sqrt(left_eigen.eigen_values);
|
std::vector<std::vector<real_t>> singularvals = sqrt(left_eigen.eigen_values);
|
||||||
std::vector<std::vector<real_t>> sigma = zeromat(A.size(), A[0].size());
|
std::vector<std::vector<real_t>> sigma = zeromat(A.size(), A[0].size());
|
||||||
@ -1230,12 +1231,15 @@ MLPPLinAlg::SDVResultOld MLPPLinAlg::svd(std::vector<std::vector<real_t>> A) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDVResultOld res;
|
SDVResult res;
|
||||||
res.U = left_eigen.eigen_vectors;
|
res.U = left_eigen.eigen_vectors;
|
||||||
res.S = sigma;
|
res.S = sigma;
|
||||||
res.Vt = right_eigen.eigen_vectors;
|
res.Vt = right_eigen.eigen_vectors;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
*/
|
||||||
|
|
||||||
|
return SDVResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<real_t> MLPPLinAlg::vectorProjection(std::vector<real_t> a, std::vector<real_t> b) {
|
std::vector<real_t> MLPPLinAlg::vectorProjection(std::vector<real_t> a, std::vector<real_t> b) {
|
||||||
|
@ -114,13 +114,21 @@ public:
|
|||||||
|
|
||||||
std::tuple<std::vector<std::vector<real_t>>, std::vector<std::vector<real_t>>> eig(std::vector<std::vector<real_t>> A);
|
std::tuple<std::vector<std::vector<real_t>>, std::vector<std::vector<real_t>>> eig(std::vector<std::vector<real_t>> A);
|
||||||
|
|
||||||
struct EigenResult {
|
struct EigenResultOld {
|
||||||
std::vector<std::vector<real_t>> eigen_vectors;
|
std::vector<std::vector<real_t>> eigen_vectors;
|
||||||
std::vector<std::vector<real_t>> eigen_values;
|
std::vector<std::vector<real_t>> eigen_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
EigenResult eigen(std::vector<std::vector<real_t>> A);
|
EigenResultOld eigen_old(std::vector<std::vector<real_t>> A);
|
||||||
|
|
||||||
|
/*
|
||||||
|
struct EigenResult {
|
||||||
|
Ref<MLPPMatrix> eigen_vectors;
|
||||||
|
Ref<MLPPMatrix> eigen_values;
|
||||||
|
};
|
||||||
|
|
||||||
|
EigenResult eigen(const Ref<MLPPMatrix> &A);
|
||||||
|
*/
|
||||||
struct SDVResultOld {
|
struct SDVResultOld {
|
||||||
std::vector<std::vector<real_t>> U;
|
std::vector<std::vector<real_t>> U;
|
||||||
std::vector<std::vector<real_t>> S;
|
std::vector<std::vector<real_t>> S;
|
||||||
@ -129,7 +137,13 @@ public:
|
|||||||
|
|
||||||
SDVResultOld SVD(std::vector<std::vector<real_t>> A);
|
SDVResultOld SVD(std::vector<std::vector<real_t>> A);
|
||||||
|
|
||||||
SDVResultOld svd(std::vector<std::vector<real_t>> A);
|
struct SDVResult {
|
||||||
|
Ref<MLPPMatrix> U;
|
||||||
|
Ref<MLPPMatrix> S;
|
||||||
|
Ref<MLPPMatrix> Vt;
|
||||||
|
};
|
||||||
|
|
||||||
|
SDVResult svd(const Ref<MLPPMatrix> &A);
|
||||||
|
|
||||||
std::vector<real_t> vectorProjection(std::vector<real_t> a, std::vector<real_t> b);
|
std::vector<real_t> vectorProjection(std::vector<real_t> a, std::vector<real_t> b);
|
||||||
|
|
||||||
|
@ -711,7 +711,7 @@ void MLPPTests::test_pca_svd_eigenvalues_eigenvectors(bool ui) {
|
|||||||
// PCA, SVD, eigenvalues & eigenvectors
|
// PCA, SVD, eigenvalues & eigenvectors
|
||||||
std::vector<std::vector<real_t>> inputSet = { { 1, 1 }, { 1, 1 } };
|
std::vector<std::vector<real_t>> inputSet = { { 1, 1 }, { 1, 1 } };
|
||||||
|
|
||||||
MLPPLinAlg::EigenResult eigen = alg.eigen(inputSet);
|
MLPPLinAlg::EigenResultOld eigen = alg.eigen_old(inputSet);
|
||||||
|
|
||||||
std::cout << "Eigenvectors:" << std::endl;
|
std::cout << "Eigenvectors:" << std::endl;
|
||||||
alg.printMatrix(eigen.eigen_vectors);
|
alg.printMatrix(eigen.eigen_vectors);
|
||||||
|
Loading…
Reference in New Issue
Block a user