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

Design improve #37

Merged
merged 15 commits into from
Jul 9, 2019
Merged
27 changes: 0 additions & 27 deletions R/moma_4Dlist_extractor.R

This file was deleted.

37 changes: 37 additions & 0 deletions R/moma_5Dlist_extractor.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
get_5Dlist_elem <- function(x, alpha_u_i, lambda_u_i, alpha_v_i, lambda_v_i, rank_i = 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Longer term, we should think about making an accessor which takes alpha_u, lambda_u, etc (values not indices) and does the extraction. If we don't have exactly the right value in the saved list, we should (by default) interpolate with an option for an exact solve.

(I do something similar for the coef function in my ExclusiveLasso package.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened an issue to track this.

#40 (comment)

if (!inherits(x, "MoMA_5D_list")) {
moma_error(sQuote("x"), " should be a ", sQuote("MoMA_5D_list"), " object.")
}
n_alpha_u <- dim(x)[1]
n_lambda_u <- dim(x)[2]
n_alpha_v <- dim(x)[3]
n_lambda_v <- dim(x)[4]
n_rank <- dim(x)[5]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alignment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found how to set it in styler. Could you point it out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the README, it looks like setting strict = FALSE won't mess with existing alignment but I don't see how to force my type of alignment.

Don't worry about it - we'll just commit to what styler uses. I was commenting out of habit.


# NOTE: R index starts from 1
if (
alpha_u_i <= 0 || alpha_u_i > n_alpha_u ||
lambda_u_i <= 0 || lambda_u_i > n_lambda_u ||
alpha_v_i <= 0 || alpha_v_i > n_alpha_v ||
lambda_v_i <= 0 || lambda_v_i > n_lambda_v ||
rank_i <= 0 || rank_i > n_rank
) {
moma_error(
"Invalid index (", alpha_u_i, ",", lambda_u_i,
",", alpha_v_i, ",", lambda_v_i, ",", rank_i, "), dim = ",
dim(x)
)
}

return(x[
rank_i + n_rank * (
lambda_v_i - 1 + n_lambda_v * (
alpha_v_i - 1 + n_alpha_v * (
lambda_u_i - 1 + n_lambda_u * (
alpha_u_i - 1
)
)
)
)
])
}
29 changes: 13 additions & 16 deletions R/moma_svd.R → R/moma_expose.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ moma_svd <- function(
lambda_u <- as.vector(lambda_u)
lambda_v <- as.vector(lambda_v)

# update argument lists
# GP loop argument
algo_settings_list <- list(
X = X,
lambda_u = lambda_u,
lambda_v = lambda_v,
# smoothness
alpha_u = alpha_u,
alpha_v = alpha_v,
k = k
)

if (!is.matrix(X)) {
moma_error("X must be a matrix.")
}
Expand Down Expand Up @@ -161,7 +149,16 @@ moma_svd <- function(
# Pack all argument into a list
# First we check the smoothness term argument.
algo_settings_list <- c(
algo_settings_list,
list(
X = X,
lambda_u = lambda_u,
lambda_v = lambda_v,
# smoothness
alpha_u = alpha_u,
alpha_v = alpha_v,
rank = k
),
# Penalties
list(
Omega_u = check_omega(Omega_u, alpha_u, n),
Omega_v = check_omega(Omega_v, alpha_v, p),
Expand All @@ -173,12 +170,12 @@ moma_svd <- function(

if (is_multiple_para) {
if (select == "gridsearch") {
a <- do.call("cpp_sfpca_grid", algo_settings_list)
a <- do.call("cpp_moma_grid_search", algo_settings_list)
class(a) <- "moma_svd_grid"
return(a)
}
else if (select == "nestedBIC") {
a <- do.call("cpp_sfpca_nestedBIC", algo_settings_list)
a <- do.call("cpp_moma_criterion_search", algo_settings_list)
class(a) <- "moma_svd_nestedBIC"
return(a)
}
Expand All @@ -187,6 +184,6 @@ moma_svd <- function(
}
}
else {
return(do.call("cpp_sfpca", algo_settings_list))
return(do.call("cpp_moma_multi_rank", algo_settings_list))
}
}
4 changes: 2 additions & 2 deletions R/sfpca.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ sfpca <- function(X,
nonneg = nonneg_v,
group = group_v
)
return(cpp_sfpca(
return(cpp_moma_multi_rank(
X = X,
alpha_u = alpha_u, alpha_v = alpha_v,
Omega_u = Omega_u, Omega_v = Omega_v,
Expand All @@ -98,6 +98,6 @@ sfpca <- function(X,
EPS = EPS, MAX_ITER = MAX_ITER,
EPS_inner = EPS_inner, MAX_ITER_inner = MAX_ITER_inner,
solver = solver,
k = k
rank = k
))
}
Loading