Skip to content

Commit

Permalink
edited alpha_vals names
Browse files Browse the repository at this point in the history
  • Loading branch information
shazanfar committed Sep 24, 2024
1 parent d475ed4 commit 4ca82b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
22 changes: 11 additions & 11 deletions R/exploreWSIRParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
#' format: for the previous example, you could write
#' samples = c(rep("sample 1", 5000), rep("sample 2", 5000)), and the result
#' would be the same.
#' @param alpha_vals vector of numbers as the values of parameter alpha to use
#' @param optim_alpha vector of numbers as the values of parameter alpha to use
#' in WSIR. 0 gives Sliced Inverse Regression
#' (SIR) implementation, and larger values represent stronger spatial
#' correlation. Suggest to use integers for interpretability,
#' but can use non-integers. Values must be non-negative.
#' @param slice_vals vector of integers as the values of parameter slices to
#' @param optim_slices vector of integers as the values of parameter slices to
#' use in WSIR. Suggest maximum value in the vector to
#' be no more than around \eqn{\sqrt{n/20}}, as this upper bound ensures an
#' average of at least 10 cells per tile in the training set.
Expand Down Expand Up @@ -58,7 +58,7 @@
#' 4) "best_slices" returns the integer for the best slices value among the
#' values that were tested according to selected metric.
#' 5) "results_dataframe" returns the results dataframe used to create "plot".
#' This dataframe has length(alpha_vals)*length(slice_vals) rows,
#' This dataframe has length(optim_alpha)*length(optim_slices) rows,
#' where one is for each combination of parameters slices and alpha. There is
#' one column for "alpha", one for "slices" and one
#' for each of the evaluation metrics selected in "metrics" argument. Column
Expand All @@ -72,8 +72,8 @@
#' data(MouseData)
#' explore_params = exploreWSIRParams(X = sample1_exprs,
#' coords = sample1_coords,
#' alpha_vals = c(0,2,4,8),
#' slice_vals = c(3,6,10))
#' optim_alpha = c(0,2,4,8),
#' optim_slices = c(3,6,10))
#' explore_params$plot
#' explore_params$message
#' best_alpha = explore_params$best_alpha
Expand All @@ -94,16 +94,16 @@
exploreWSIRParams <- function(X,
coords,
samples = rep(1, nrow(coords)),
alpha_vals = c(0,2,4,10),
slice_vals = c(5,10,15,20),
optim_alpha = c(0,2,4,10),
optim_slices = c(5,10,15,20),
metric = "DC",
nrep = 5,
param = MulticoreParam(workers = 1),
...
) {

# vector of all parameter combinations
param_combinations <- expand.grid(slice = slice_vals, alpha = alpha_vals,
param_combinations <- expand.grid(slices = optim_slices, alpha = optim_alpha,
metric = NA)


Expand Down Expand Up @@ -149,7 +149,7 @@ exploreWSIRParams <- function(X,
wSIROptimisation(as.matrix(X_train),
coords_train, as.matrix(X_test),
coords_test,
samples_train, param_combinations$slice[ii],
samples_train, param_combinations$slices[ii],
param_combinations$alpha[ii],
evalmetrics = metric,
...)
Expand All @@ -161,13 +161,13 @@ exploreWSIRParams <- function(X,
res_df <- param_combinations
best_metric_index <- which.max(res_df[, "metric"])
best_alpha <- res_df[best_metric_index, "alpha"]
best_slices <- res_df[best_metric_index, "slice"]
best_slices <- res_df[best_metric_index, "slices"]

message <- paste0("Optimal (alpha, slices) pair: (",
best_alpha, ", ", best_slices, ")")

plot <- ggplot2::ggplot(res_df, mapping = aes(
x = .data$alpha, y = .data$slice, size = .data$metric)) +
x = .data$alpha, y = .data$slices, size = .data$metric)) +
ggplot2::geom_point() +
ggplot2::theme_classic() +
ggplot2::ggtitle(
Expand Down
5 changes: 1 addition & 4 deletions R/sirCategorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#' @param Y dataframe with 1 column named "coordinate" that is the tile
#' allocation for each cell. There should
#' be up to slices^2 unique tile IDs in this column.
#' @param maxDirections Integer to specify maximum number of directions to
#' retain in thee low-dimensional embedding
#' of the data. Use if you need at most a certain number for a downstream task.
#' @param W Weight matrix created by createWeightMatrix. Entry (i,j)
#' represents the spatial correlation level
#' between tiles i and j. The diagonal values should be all 1. If not
Expand All @@ -25,7 +22,7 @@

sirCategorical <- function(X,
Y,
maxDirections = 50,
# maxDirections = 50,
W = NULL,
...
) {
Expand Down
12 changes: 6 additions & 6 deletions R/wSIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@
#' wsir_obj = wSIR(X = sample1_exprs,
#' coords = sample1_coords,
#' optim_params = TRUE,
#' alpha_vals = c(0,2,4),
#' slice_vals = c(3,6,10),
#' optim_alpha = c(0,2,4),
#' optim_slices = c(3,6,10),
#' metric = "DC",
#' nrep = 1) # create wsir object
#'
#' @export
wSIR <- function(X,
coords,
optim_params = FALSE,
alpha_vals = c(0,1,2,4,8,12),
slice_vals = c(3,5,7,10,15,20),
optim_alpha = c(0,1,2,4,8,12),
optim_slices = c(3,5,7,10,15,20),
metric = "DC",
nrep = 5,
verbose = FALSE,
Expand All @@ -86,8 +86,8 @@ wSIR <- function(X,
if (verbose) message("Optimising parameters...")
optim_obj <- exploreWSIRParams(X = X,
coords = coords,
alpha_vals = alpha_vals,
slice_vals = slice_vals,
optim_alpha = optim_alpha,
optim_slices = optim_slices,
metric = metric,
nrep = nrep,
...)
Expand Down
Binary file modified src/wSIR.so
Binary file not shown.

0 comments on commit 4ca82b2

Please sign in to comment.