Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update insert_rows() (and _cols()) to two-argument signatures #39

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/fastGrplars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ uvec fastGrplars(const mat& x, const vec& y, const uword& sMax,
}
// update correlations (adjustment for unequal group size is taken
// care of by update formula)
r.insert_rows(k, 1, false); // do not initialize new memory
r.insert_rows(k, 1); // do not initialize new memory
r(k) = (r(k-1) - gamma * a) / sigma;
corY.shed_row(whichMin);
corU.shed_row(whichMin);
Expand All @@ -265,7 +265,7 @@ uvec fastGrplars(const mat& x, const vec& y, const uword& sMax,
}
}
// update active set
active.insert_rows(k, 1, false); // do not initialize new memory
active.insert_rows(k, 1); // do not initialize new memory
active(k) = inactive(whichMin);
// update inactive set
inactive.shed_row(whichMin);
Expand Down
6 changes: 3 additions & 3 deletions src/fastLars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ uvec fastLars(const mat& x, const vec& y, const uword& sMax,
double minGammaMinus, minGammaPlus, gamma;
minGammaMinus = gammaMinus.min(whichMinus);
minGammaPlus = gammaPlus.min(whichPlus);
signs.insert_rows(k, 1, false); // do not initialize new memory
signs.insert_rows(k, 1); // do not initialize new memory
if(minGammaMinus < minGammaPlus) {
whichMin = whichMinus;
gamma = minGammaMinus;
Expand All @@ -182,13 +182,13 @@ uvec fastLars(const mat& x, const vec& y, const uword& sMax,
signs(k) = -1;
}
// update correlations
r.insert_rows(k, 1, false); // do not initialize new memory
r.insert_rows(k, 1); // do not initialize new memory
r(k) = r(k-1) - gamma * a;
corY.shed_row(whichMin);
corU.shed_row(whichMin);
corY = corY - gamma * corU;
// update active set
active.insert_rows(k, 1, false); // do not initialize new memory
active.insert_rows(k, 1); // do not initialize new memory
active(k) = inactive(whichMin);
// update inactive set
inactive.shed_row(whichMin);
Expand Down
14 changes: 7 additions & 7 deletions src/fastLasso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ void fastLasso(const mat& x, const vec& y, const double& lambda,
// correct way
// insert row and column without initializing memory
// (set_size() and reshape() have strange behavior)
L.insert_rows(k, 1, false);
L.insert_cols(k, 1, false);
L.insert_rows(k, 1);
L.insert_cols(k, 1);
// fill new parts of the matrix
for(uword j = 0; j < k; j++) {
L(k, j) = l(j);
Expand All @@ -300,7 +300,7 @@ void fastLasso(const mat& x, const vec& y, const double& lambda,
// in case of singularity
if(rank == k) {
// singularity: drop variable for good
ignores.insert_rows(s, 1, false); // do not initialize new memory
ignores.insert_rows(s, 1); // do not initialize new memory
ignores(s) = newJ;
s++; // increase number of ignored variables
p--; // decrease number of variables
Expand All @@ -310,10 +310,10 @@ void fastLasso(const mat& x, const vec& y, const double& lambda,
}
} else {
// no singularity: add variable to active set
active.insert_rows(k, 1, false); // do not initialize new memory
active.insert_rows(k, 1); // do not initialize new memory
active(k) = newJ;
// keep track of sign of correlation for new active variable
signs.insert_rows(k, 1, false); // do not initialize new memory
signs.insert_rows(k, 1); // do not initialize new memory
signs(k) = sign(corY(newJ));
k++; // increase number of active variables
}
Expand Down Expand Up @@ -436,7 +436,7 @@ void fastLasso(const mat& x, const vec& y, const double& lambda,
L = symmatu(L);
// add dropped variables to inactive set and make sure
// coefficients are 0
inactive.insert_rows(m, drops.n_elem, false);
inactive.insert_rows(m, drops.n_elem);
for(uword j = 0; j < drops.n_elem; j++) {
uword newInactive = active(drops(j));
inactive(m + j) = newInactive;
Expand Down Expand Up @@ -529,7 +529,7 @@ SEXP R_fastLasso(SEXP R_x, SEXP R_y, SEXP R_lambda, SEXP R_useSubset,
useGram, false, intercept, coefficients, residuals, crit);
if(useIntercept) {
// prepend intercept
coefficients.insert_rows(0, 1, false);
coefficients.insert_rows(0, 1);
coefficients(0) = intercept;
}
return List::create(
Expand Down
6 changes: 3 additions & 3 deletions src/fastSparseLTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ SEXP R_testLasso(SEXP R_x, SEXP R_y, SEXP R_lambda, SEXP R_initial,
vec coefficients = subset.coefficients;
if(useIntercept) {
// prepend intercept
coefficients.insert_rows(0, 1, false);
coefficients.insert_rows(0, 1);
coefficients(0) = subset.intercept;
}
return List::create(
Expand Down Expand Up @@ -196,7 +196,7 @@ SEXP R_testCStep(SEXP R_x, SEXP R_y, SEXP R_lambda, SEXP R_subset,
vec coefficients = subset.coefficients;
if(useIntercept) {
// prepend intercept
coefficients.insert_rows(0, 1, false);
coefficients.insert_rows(0, 1);
coefficients(0) = subset.intercept;
}
return List::create(
Expand Down Expand Up @@ -422,7 +422,7 @@ SEXP R_fastSparseLTS(SEXP R_x, SEXP R_y, SEXP R_lambda, SEXP R_initial,
vec coefficients = best.coefficients;
if(useIntercept) {
// prepend intercept
coefficients.insert_rows(0, 1, false);
coefficients.insert_rows(0, 1);
coefficients(0) = best.intercept;
}
return List::create(
Expand Down