44 int components, arma::mat &X_loadings,
45 arma::mat &Y_loadings,
48 arma::mat &coefficients,
49 arma::mat &percent_variance,
53 uword observations = X.n_rows;
54 uword predictors = X.n_cols;
55 uword responses = Y.n_cols;
57 mat Xmeans = arma::mean(X);
58 mat Ymeans = arma::mean(Y);
61 X.each_row() -= Xmeans;
62 Y.each_row() -= Ymeans;
65 mat R = zeros(predictors, components);
68 mat T = zeros(observations, components);
70 mat Q = zeros(responses, components);
82 for (
int i = 0; i < components; ++i){
83 eig_sym(eigval, eigvec, (trans(S) * S));
84 max_eigval = eigval.max();
85 uvec dom_index = find(eigval >= max_eigval);
86 uword dominant_index = dom_index(0);
88 q = eigvec.col(dominant_index);
92 t.each_row() -= mean(t);
93 nt = arma::sqrt(t.t()*t);
107 v.each_row() /= arma::sqrt(trans(v) * v);
108 S = S - v * (trans(v)*S);
120 fitted.each_row() += Ymeans;
130 percent_variance.set_size(2, P.n_cols);
131 percent_variance.row(0) = sum(arma::abs(P)%arma::abs(P)) / sum(sum(arma::abs(X)%arma::abs(X)));
132 percent_variance.row(1) = sum(arma::abs(Q)%arma::abs(Q)) / sum(sum(arma::abs(Y)%arma::abs(Y)));
VESPUCCI_EXPORT bool plsregress(arma::mat X, arma::mat Y, int components, arma::mat &X_loadings, arma::mat &Y_loadings, arma::mat &X_scores, arma::mat &Y_scores, arma::mat &coefficients, arma::mat &percent_variance, arma::mat &fitted)
Vespucci::MathDimensionReduction::plsregress PLS Regression Using SIMPLS algorithm. This is essentially a line-for-line rewrite of plsregress from the Octave statistics package. Copyright (C) 2012 Fernando Damian Nieuwveldt fdnieuwveldt@gmail.com This is an implementation of the SIMPLS algorithm: Reference: SIMPLS: An alternative approach to partial least squares regression. Chemometrics and Intelligent Laboratory Systems (1993)