Skip to content

Commit

Permalink
fix #88 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot authored Aug 15, 2024
1 parent 259cd87 commit a416040
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions R/oolong_data_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ utils::globalVariables(c('cookd', 'diffxy', 'index', 'meanxy', 'word_length', 'a
}
return(digest::digest(x, algo = "sha1"))
}

.map_dfr <- function(x, f, ...) {
purrr::list_rbind(purrr::map(x, f, ...))
}
6 changes: 3 additions & 3 deletions R/oolong_summary_tm.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
res$tlo <- NA
res$tlo_p_value <- NA
} else {
res$tlo <- .cal_tlo(purrr::map_dfr(all_topic_test_content, ~.), mean_value = FALSE) ### it should not be just the mean.
res$tlo <- .cal_tlo(.map_dfr(all_topic_test_content, ~.), mean_value = FALSE) ### it should not be just the mean.
monkey_median <- unlist(replicate(n_iter, .monkey_median(.clone_obj_list(obj_list))))
res$tlo_p_value <- sum(monkey_median > median(res$tlo)) / n_iter
}
Expand All @@ -88,7 +88,7 @@
n_correct <- apply(correction_matrix, 2, sum)
res$rater_precision_wsi <- as.vector(n_correct / nrow(correction_matrix))
if (length(obj_list) == 1) {
res$kripp_alpha_wsi <- NA
res$kripp_alpha_wsi <- NA
} else {
res$kripp_alpha_wsi <- irr::kripp.alpha(t(ifelse(correction_matrix, 2, 1)))$value
}
Expand Down Expand Up @@ -140,5 +140,5 @@
.monkey_median <- function(obj_list) {
monkeyed_obj_list <- purrr::map(obj_list, .monkey_test)
all_topic_test_content <- purrr::map(monkeyed_obj_list, ~ .$.__enclos_env__$private$test_content$ti)
median(.cal_tlo(purrr::map_dfr(all_topic_test_content, ~.), mean_value = FALSE))
median(.cal_tlo(.map_dfr(all_topic_test_content, ~.), mean_value = FALSE))
}
6 changes: 3 additions & 3 deletions R/oolong_tm.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
## refer to oolong_stm.R for an example

.generate_word_intrusion_test <- function(ingredients, bottom_terms_percentile = 0.6, n_top_terms) {
test_items <- purrr::map_dfr(seq_len(ingredients$K), .generate_candidates, terms = ingredients$terms, all_terms = ingredients$all_terms, bottom_terms_percentile = bottom_terms_percentile, n_top_terms = n_top_terms)
test_items <- .map_dfr(seq_len(ingredients$K), .generate_candidates, terms = ingredients$terms, all_terms = ingredients$all_terms, bottom_terms_percentile = bottom_terms_percentile, n_top_terms = n_top_terms)
return(test_items)
}

Expand Down Expand Up @@ -90,7 +90,7 @@
target_theta <- ingredients$theta[sample_vec,]
k <- ncol(target_theta)
target_text <- input_corpus[sample_vec]
test_items <- purrr::map_dfr(seq_len(exact_n), .generate_topic_frame, target_text = target_text, target_theta = target_theta, model_terms = ingredients$model_terms, k = k, n_top_topics = n_top_topics)
test_items <- .map_dfr(seq_len(exact_n), .generate_topic_frame, target_text = target_text, target_theta = target_theta, model_terms = ingredients$model_terms, k = k, n_top_topics = n_top_topics)
return(test_items)
}

Expand All @@ -117,7 +117,7 @@
}

.generate_wsi <- function(ingredients, n_correct_ws = 3, n_topiclabel_words = 4, wsi_n_top_terms = 20) {
test_content <- purrr::map_dfr(seq_len(ingredients$K), .generate_candidates_wsi, terms = ingredients$terms, n_correct_ws = n_correct_ws, n_topiclabel_words = n_topiclabel_words, wsi_n_top_terms = wsi_n_top_terms)
test_content <- .map_dfr(seq_len(ingredients$K), .generate_candidates_wsi, terms = ingredients$terms, n_correct_ws = n_correct_ws, n_topiclabel_words = n_topiclabel_words, wsi_n_top_terms = wsi_n_top_terms)
return(test_content)
}

Expand Down

0 comments on commit a416040

Please sign in to comment.