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