91template<
typename Stat_>
159template<
typename Stat_>
165 std::vector<std::vector<Stat_> >
mean;
211template<
typename Index_,
typename Stat_>
212void process_simple_pairwise_effects(
214 const std::size_t ngroups,
215 const std::size_t nblocks,
216 const std::size_t ncombos,
217 std::vector<Stat_>& combo_means,
218 std::vector<Stat_>& combo_vars,
219 std::vector<Stat_>& combo_detected,
221 const std::vector<Stat_>& combo_weights,
222 const double threshold,
223 const int num_threads)
225 std::vector<Stat_> total_weights_per_group;
226 const Stat_* total_weights_ptr = combo_weights.data();
228 total_weights_per_group = compute_total_weight_per_group(ngroups, nblocks, combo_weights.data());
229 total_weights_ptr = total_weights_per_group.data();
231 PrecomputedPairwiseWeights<Stat_> preweights(ngroups, nblocks, combo_weights.data());
234 for (Index_ gene = start, end = start + length; gene < end; ++gene) {
235 auto in_offset = sanisizer::product_unsafe<std::size_t>(gene, ncombos);
236 const auto tmp_means = combo_means.data() + in_offset;
237 const auto tmp_variances = combo_vars.data() + in_offset;
238 const auto tmp_detected = combo_detected.data() + in_offset;
239 average_group_stats(gene, ngroups, nblocks, tmp_means, tmp_detected, combo_weights.data(), total_weights_ptr, output.
mean, output.
detected);
242 const auto out_offset = sanisizer::product_unsafe<std::size_t>(gene, ngroups, ngroups);
244 internal::compute_pairwise_cohens_d(tmp_means, tmp_variances, ngroups, nblocks, preweights, threshold, output.
cohens_d + out_offset);
248 internal::compute_pairwise_simple_diff(tmp_detected, ngroups, nblocks, preweights, output.
delta_detected + out_offset);
252 internal::compute_pairwise_simple_diff(tmp_means, ngroups, nblocks, preweights, output.
delta_mean + out_offset);
255 }, ngenes, num_threads);
258template<
typename Index_,
typename Stat_>
259ScoreMarkersPairwiseBuffers<Stat_> fill_pairwise_results(
const Index_ ngenes,
const std::size_t ngroups, ScoreMarkersPairwiseResults<Stat_>& store,
const ScoreMarkersPairwiseOptions& opt) {
260 ScoreMarkersPairwiseBuffers<Stat_> output;
262 internal::fill_average_results(ngenes, ngroups, store.mean, store.detected, output.mean, output.detected);
264 const auto num_effect_sizes = sanisizer::product<typename std::vector<Stat_>::size_type>(ngenes, ngroups, ngroups);
266 if (opt.compute_cohens_d) {
267 store.cohens_d.resize(num_effect_sizes
268#ifdef SCRAN_MARKERS_TEST_INIT
269 , SCRAN_MARKERS_TEST_INIT
272 output.cohens_d = store.cohens_d.data();
274 if (opt.compute_auc) {
275 store.auc.resize(num_effect_sizes
276#ifdef SCRAN_MARKERS_TEST_INIT
277 , SCRAN_MARKERS_TEST_INIT
280 output.auc = store.auc.data();
282 if (opt.compute_delta_mean) {
283 store.delta_mean.resize(num_effect_sizes
284#ifdef SCRAN_MARKERS_TEST_INIT
285 , SCRAN_MARKERS_TEST_INIT
288 output.delta_mean = store.delta_mean.data();
290 if (opt.compute_delta_detected) {
291 store.delta_detected.resize(num_effect_sizes
292#ifdef SCRAN_MARKERS_TEST_INIT
293 , SCRAN_MARKERS_TEST_INIT
296 output.delta_detected = store.delta_detected.data();
377template<
typename Value_,
typename Index_,
typename Group_,
typename Stat_>
380 const Group_*
const group,
384 const Index_ NC = matrix.
ncol();
385 const auto group_sizes = tatami_stats::tabulate_groups(group, NC);
391 const auto ngroups = group_sizes.size();
392 const auto payload_size = sanisizer::product<typename std::vector<Stat_>::size_type>(matrix.
nrow(), ngroups);
393 std::vector<Stat_> group_means(payload_size), group_vars(payload_size), group_detected(payload_size);
396 internal::scan_matrix_by_row<true>(
401 static_cast<int*
>(NULL),
415 internal::scan_matrix_by_column(
427 internal::process_simple_pairwise_effects(
481template<
typename Value_,
typename Index_,
typename Group_,
typename Block_,
typename Stat_>
484 const Group_*
const group,
485 const Block_*
const block,
489 const Index_ NC = matrix.
ncol();
490 const auto ngroups = output.
mean.size();
491 const auto nblocks = tatami_stats::total_groups(block, NC);
493 const auto combinations = internal::create_combinations(ngroups, group, block, NC);
494 const auto combo_sizes = internal::tabulate_combinations<Index_>(ngroups, nblocks, combinations);
495 const auto ncombos = combo_sizes.size();
498 const auto payload_size = sanisizer::product<typename std::vector<Stat_>::size_type>(matrix.
nrow(), ncombos);
499 std::vector<Stat_> combo_means(payload_size), combo_vars(payload_size), combo_detected(payload_size);
502 internal::scan_matrix_by_row<false>(
521 internal::scan_matrix_by_column(
533 internal::process_simple_pairwise_effects(
564template<
typename Stat_ =
double,
typename Value_,
typename Index_,
typename Group_>
566 const auto ngroups = tatami_stats::total_groups(group, matrix.
ncol());
568 auto buffers = internal::fill_pairwise_results(matrix.
nrow(), ngroups, res, options);
592template<
typename Stat_ =
double,
typename Value_,
typename Index_,
typename Group_,
typename Block_>
595 const Group_*
const group,
596 const Block_*
const block,
599 const auto ngroups = tatami_stats::total_groups(group, matrix.
ncol());
601 const auto buffers = internal::fill_pairwise_results(matrix.
nrow(), ngroups, res, options);
void score_markers_pairwise_blocked(const tatami::Matrix< Value_, Index_ > &matrix, const Group_ *const group, const Block_ *const block, const ScoreMarkersPairwiseOptions &options, const ScoreMarkersPairwiseBuffers< Stat_ > &output)
Definition score_markers_pairwise.hpp:482