aboutsummaryrefslogtreecommitdiff
path: root/plmp.cpp
blob: a9f055e9f02809a591bcb85ddc814dba88415ed0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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;
}