Skip to content

Commit

Permalink
correct bug with 3 or more FEs
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Mar 28, 2024
1 parent f7e4d24 commit e5a5b18
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
12 changes: 4 additions & 8 deletions src/01_center_variables.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "00_main.h"

// Method of alternating projections (Halperin)
[[cpp11::register]] doubles_matrix<>
center_variables_(const doubles_matrix<> &V_r, const doubles &v_sum_r,
const doubles &w_r, const list &klist, const double tol,
const int maxiter, bool sum_v) {
[[cpp11::register]] doubles_matrix<> center_variables_(
const doubles_matrix<> &V_r, const doubles &v_sum_r, const doubles &w_r,
const list &klist, const double tol, const int maxiter, bool sum_v) {
// Types conversion
Mat<double> V = as_Mat(V_r);
Mat<double> w = as_Mat(w_r);
Expand Down Expand Up @@ -32,13 +31,10 @@ center_variables_(const doubles_matrix<> &V_r, const doubles &v_sum_r,
// Center each variable
x = V.col(p);

int interruptCheckCounter = 0;

for (iter = 0; iter < 100000; ++iter) {
// Check user interrupt
if (++interruptCheckCounter == 1000) {
if ((iter % 1000) == 0) {
check_user_interrupt();
interruptCheckCounter = 0;
}

// Store centered vector from the last iteration
Expand Down
21 changes: 8 additions & 13 deletions src/02_get_alpha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,21 @@
field<Col<double>> Alpha(K);
for (k = 0; k < K; k++) {
J = as_cpp<list>(klist[k]).size();
Alpha(k) = zeros(J);
Alpha(k) = zeros<Col<double>>(J);
}

// Start alternating between normal equations
field<Col<double>> Alpha0(size(Alpha));

// Create vector for alpha
Col<double> alpha(J);

int interruptCheckCounter = 0;

for (iter = 0; iter < 10000; iter++) {
// Check user interrupt
if (++interruptCheckCounter == 1000) {
if ((iter % 1000) == 0) {
check_user_interrupt();
interruptCheckCounter = 0;
}
// Store \alpha_{0} of the previous iteration

// Store alpha_0 of the previous iteration
Alpha0 = Alpha;

// Solve normal equations of category k
for (k = 0; k < K; k++) {
// Compute adjusted dependent variable
y = p;
Expand All @@ -50,14 +44,15 @@
integers indexes = as_cpp<list>(klist[l])[j];
I = indexes.size();
for (i = 0; i < I; i++) {
y(indexes[i]) -= Alpha(j)(j);
y(indexes[i]) -= Alpha(l)(j);
}
}
}
}

// Compute group mean
J = as_cpp<list>(klist[k]).size();
Col<double> alpha = zeros<Col<double>>(J);

for (j = 0; j < J; j++) {
// Subset the j-th group of category k
integers indexes = as_cpp<list>(klist[k])[j];
Expand All @@ -73,7 +68,7 @@
alpha(j) = sum / I;
}

// Update \alpha_{k}
// Update alpha_k
Alpha(k) = alpha;
}

Expand Down
1 change: 0 additions & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

1 change: 0 additions & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

0 comments on commit e5a5b18

Please sign in to comment.