Skip to content

Commit

Permalink
return top feature scores and indices from each search
Browse files Browse the repository at this point in the history
  • Loading branch information
RC-88 committed Aug 28, 2023
1 parent fefb3d5 commit ba5b8d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
19 changes: 7 additions & 12 deletions R/candidate_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ candidate_search <- function(
start_feature <- rownames(FS)[feature_best_index]
best_feature <- start_feature
best_score <- rowscore[best_feature]
best_index <- which(rowscore == best_score, arr.ind = TRUE)


verbose("***Top Feature ", x, ": ", best_feature, "***\n")
verbose("Score: ", best_score, "\n")

Expand All @@ -197,7 +196,6 @@ candidate_search <- function(

# Initiate list of global features, indices, and scores
global_best_s_features <- c()
global_best_s_indices <- c()
global_best_s_scores <- c()

# Counter variable for number of iterations
Expand All @@ -221,7 +219,6 @@ candidate_search <- function(

# Update meta-feature set, its indices, and best scores
global_best_s_features <- c(global_best_s_features, best_feature)
global_best_s_indices <- c(global_best_s_indices, best_index)
global_best_s_scores <- c(global_best_s_scores, best_score)

verbose("Current meta-feature set:\n ", global_best_s_features, "\n")
Expand All @@ -248,13 +245,11 @@ candidate_search <- function(
verbose = verbose,
glob_f = global_best_s_features,
glob_s = global_best_s,
glob_f_scores = global_best_s_scores,
glob_f_indices = global_best_s_indices
glob_f_scores = global_best_s_scores
)

# Update global features, scores
global_best_s_features <- backward_search_results[["best_features"]]
global_best_s_indices <- backward_search_results[["best_indices"]]
global_best_s_scores <- backward_search_results[["best_scores"]]
global_best_s <- backward_search_results[["score"]]

Expand Down Expand Up @@ -333,7 +328,11 @@ candidate_search <- function(
# Assign the name of the best meta-feature score to be the
# starting feature that gave that score
names(global_best_s) <- start_feature


# Get indices of best features
global_best_s_indices <- which(names(rowscore) %in% global_best_s_features)
names(global_best_s_indices) <- global_best_s_features

return(list("feature_set" = FS_best,
"input_score" = input_score,
"score" = global_best_s,
Expand Down Expand Up @@ -420,7 +419,6 @@ forward_backward_check <- function
glob_f,
glob_s,
glob_f_scores,
glob_f_indices,
verbose = FALSE,
...
){
Expand Down Expand Up @@ -453,7 +451,6 @@ forward_backward_check <- function
#n=1;
# Store features to list
f_names[[n]] <- glob_f[-n]
f_indices[[n]] <- glob_f_indices[-n]
f_scores[[n]] <- glob_f_scores[-n]

# Take the leave-one-out union of features will result in a single
Expand Down Expand Up @@ -512,7 +509,6 @@ forward_backward_check <- function
# Return a set of features that gave a better score than
# the existing best score and its new best score as well
return(list(best_features = f_names[[f_best_index]],
best_indices = f_indices[[f_best_index]],
best_scores = f_scores[[f_best_index]],
score = f_best_score))

Expand All @@ -521,7 +517,6 @@ forward_backward_check <- function
# Don't change anything. Return the existing
# best set of features and its corresponding score
return(list(best_features = glob_f,
best_indices = glob_f_indices,
best_scores = glob_f_scores,
score = glob_s))

Expand Down
14 changes: 11 additions & 3 deletions R/topn_best.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' its corresponding best score for each top 'N' search.
#'
#' @return A list of objects containing the best meta-feature,
#' its corresponding best score, and observed input scores
#' its corresponding best score, and observed input scores
#'
#' @examples
#'
Expand All @@ -32,7 +32,7 @@ topn_best <- function(topn_list){
# get best score list
scores_l <- lapply(seq_along(topn_list),
function(l){ topn_list[[l]][['score']] })

# Working with scores for each top N run
scores <- unlist(scores_l)

Expand All @@ -48,12 +48,20 @@ topn_best <- function(topn_list){

# Correspoding input_score
best_input_score <- topn_list[[n]]$input_score

# get scores of best features
best_meta_scores <- topn_list[[n]]$best_scores

# get indices of best features
best_meta_indices <- topn_list[[n]]$best_indices

return(
list(
"feature_set" = best_meta,
"input_score" = best_input_score,
"score" = top_score
"score" = top_score,
"best_scores" = best_meta_scores,
"best_indices" = best_meta_indices
)
)

Expand Down
2 changes: 1 addition & 1 deletion man/topn_best.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba5b8d7

Please sign in to comment.