mirror of
https://github.com/Relintai/pmlpp.git
synced 2025-04-25 16:55:00 +02:00
Fix warnings in PCAOld.
This commit is contained in:
parent
c49d089791
commit
d4409491d7
@ -25,23 +25,27 @@ std::vector<std::vector<real_t>> MLPPPCAOld::principalComponents() {
|
|||||||
X_normalized = data.meanCentering(inputSet);
|
X_normalized = data.meanCentering(inputSet);
|
||||||
U_reduce.resize(svr_res.U.size());
|
U_reduce.resize(svr_res.U.size());
|
||||||
for (int i = 0; i < k; i++) {
|
for (int i = 0; i < k; i++) {
|
||||||
for (int j = 0; j < svr_res.U.size(); j++) {
|
for (uint32_t j = 0; j < svr_res.U.size(); j++) {
|
||||||
U_reduce[j].push_back(svr_res.U[j][i]);
|
U_reduce[j].push_back(svr_res.U[j][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Z = alg.matmult(alg.transpose(U_reduce), X_normalized);
|
Z = alg.matmult(alg.transpose(U_reduce), X_normalized);
|
||||||
return Z;
|
return Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simply tells us the percentage of variance maintained.
|
// Simply tells us the percentage of variance maintained.
|
||||||
real_t MLPPPCAOld::score() {
|
real_t MLPPPCAOld::score() {
|
||||||
MLPPLinAlg alg;
|
MLPPLinAlg alg;
|
||||||
std::vector<std::vector<real_t>> X_approx = alg.matmult(U_reduce, Z);
|
std::vector<std::vector<real_t>> X_approx = alg.matmult(U_reduce, Z);
|
||||||
real_t num, den = 0;
|
real_t num = 0;
|
||||||
for (int i = 0; i < X_normalized.size(); i++) {
|
real_t den = 0;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < X_normalized.size(); i++) {
|
||||||
num += alg.norm_sq(alg.subtraction(X_normalized[i], X_approx[i]));
|
num += alg.norm_sq(alg.subtraction(X_normalized[i], X_approx[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
num /= X_normalized.size();
|
num /= X_normalized.size();
|
||||||
for (int i = 0; i < X_normalized.size(); i++) {
|
for (uint32_t i = 0; i < X_normalized.size(); i++) {
|
||||||
den += alg.norm_sq(X_normalized[i]);
|
den += alg.norm_sq(X_normalized[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +53,7 @@ real_t MLPPPCAOld::score() {
|
|||||||
if (den == 0) {
|
if (den == 0) {
|
||||||
den += 1e-10; // For numerical sanity as to not recieve a domain error
|
den += 1e-10; // For numerical sanity as to not recieve a domain error
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1 - num / den;
|
return 1 - num / den;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user