diff options
Diffstat (limited to 'plmp.cpp')
-rw-r--r-- | plmp.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/plmp.cpp b/plmp.cpp new file mode 100644 index 0000000..0ca1b83 --- /dev/null +++ b/plmp.cpp @@ -0,0 +1,22 @@ + +#include "mp.h" + +arma::mat mp::plmp(const arma::mat &X, const arma::uvec &sampleIndices, const arma::mat &Ys) +{ + arma::mat Y(X.n_rows, Ys.n_cols); + mp::plmp(X, sampleIndices, Ys, Y); + return Y; +} + +void mp::plmp(const arma::mat &X, const arma::uvec &sampleIndices, const arma::mat &Ys, arma::mat &Y) +{ + arma::mat Xs = X.rows(sampleIndices); + Xs.each_row() -= arma::mean(Xs); + arma::mat lYs = Ys; + lYs.each_row() -= arma::mean(Ys); + const arma::mat &Xst = Xs.t(); + arma::mat P = arma::solve(Xst * Xs, Xst * lYs); + + Y = X * P; + Y.rows(sampleIndices) = lYs; +} |