aboutsummaryrefslogtreecommitdiff
path: root/lamp.cpp
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2015-05-22 18:40:07 -0300
committerSamuel Fadel <samuelfadel@gmail.com>2015-05-22 18:40:07 -0300
commit6a7b60784a44013156382843a5e72af272810674 (patch)
treef5cfea6392033e1d4e228eb0f388b343434994ce /lamp.cpp
parente8bb632cae4e7c9a320a3412cbd487f859ae104c (diff)
Improvements to UI and performance.
Diffstat (limited to 'lamp.cpp')
-rw-r--r--lamp.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/lamp.cpp b/lamp.cpp
index a9d7a8b..90be140 100644
--- a/lamp.cpp
+++ b/lamp.cpp
@@ -4,12 +4,19 @@
arma::mat mp::lamp(const arma::mat &X, const arma::uvec &sampleIndices, const arma::mat &Ys)
{
- arma::mat Xs = X.rows(sampleIndices);
- arma::uword sampleSize = sampleIndices.n_elem;
arma::mat projection(X.n_rows, 2);
+ lamp(X, sampleIndices, Ys, projection);
+ return projection;
+}
+void mp::lamp(const arma::mat &X, const arma::uvec &sampleIndices, const arma::mat &Ys, arma::mat &Y)
+{
+ const arma::mat &Xs = X.rows(sampleIndices);
+ arma::uword sampleSize = sampleIndices.n_elem;
+
+ #pragma omp parallel for shared(X, Xs, sampleIndices, Ys, Y)
for (arma::uword i = 0; i < X.n_rows; i++) {
- arma::rowvec point = X.row(i);
+ const arma::rowvec &point = X.row(i);
// calculate alphas
arma::rowvec alphas(sampleSize);
@@ -19,7 +26,6 @@ arma::mat mp::lamp(const arma::mat &X, const arma::uvec &sampleIndices, const ar
}
double alphas_sum = arma::accu(alphas);
- arma::rowvec alphas_sqrt = arma::sqrt(alphas);
// calculate \tilde{X} and \tilde{Y}
arma::rowvec Xtil = arma::sum(alphas * Xs, 0) / alphas_sum;
@@ -32,19 +38,19 @@ arma::mat mp::lamp(const arma::mat &X, const arma::uvec &sampleIndices, const ar
Yhat.each_row() -= Ytil;
// calculate A and B
- arma::mat At = Xhat.t();
- At.each_row() %= alphas_sqrt;
- arma::mat B = Yhat;
- B.each_col() %= alphas_sqrt.t();
-
- arma::mat U, V;
- arma::vec s;
+ alphas = arma::sqrt(alphas);
+ arma::mat &At = Xhat;
+ inplace_trans(At);
+ At.each_row() %= alphas;
+ arma::mat &B = Yhat;
+ B.each_col() %= alphas.t();
+
+ arma::mat U(Ys.n_rows, Ys.n_cols), V(Ys.n_cols, Ys.n_cols);
+ arma::vec s(Ys.n_cols);
arma::svd(U, s, V, At * B);
arma::mat M = U.cols(0, 1) * V.t();
// the projection of point i
- projection.row(i) = (point - Xtil) * M + Ytil;
+ Y(i, arma::span(0, 1)) = (point - Xtil) * M + Ytil;
}
-
- return projection;
}