83template<
typename Stat_>
151template<
typename Stat_>
157 std::vector<std::vector<Stat_> >
mean;
203template<
typename Index_,
typename Stat_>
204void process_simple_pairwise_effects(
209 std::vector<Stat_>& combo_means,
210 std::vector<Stat_>& combo_vars,
211 std::vector<Stat_>& combo_detected,
213 const std::vector<Stat_>& combo_weights,
217 std::vector<Stat_> total_weights_per_group;
218 const Stat_* total_weights_ptr = combo_weights.data();
220 total_weights_per_group = compute_total_weight_per_group(ngroups, nblocks, combo_weights.data());
221 total_weights_ptr = total_weights_per_group.data();
223 PrecomputedPairwiseWeights<Stat_> preweights(ngroups, nblocks, combo_weights.data());
226 for (Index_ gene = start, end = start + length; gene < end; ++gene) {
227 auto in_offset = sanisizer::product_unsafe<std::size_t>(gene, ncombos);
228 const auto* tmp_means = combo_means.data() + in_offset;
229 const auto* tmp_variances = combo_vars.data() + in_offset;
230 const auto* tmp_detected = combo_detected.data() + in_offset;
231 average_group_stats(gene, ngroups, nblocks, tmp_means, tmp_detected, combo_weights.data(), total_weights_ptr, output.
mean, output.
detected);
234 auto out_offset = sanisizer::product_unsafe<std::size_t>(gene, ngroups, ngroups);
236 internal::compute_pairwise_cohens_d(tmp_means, tmp_variances, ngroups, nblocks, preweights, threshold, output.
cohens_d + out_offset);
240 internal::compute_pairwise_simple_diff(tmp_detected, ngroups, nblocks, preweights, output.
delta_detected + out_offset);
244 internal::compute_pairwise_simple_diff(tmp_means, ngroups, nblocks, preweights, output.
delta_mean + out_offset);
247 }, ngenes, num_threads);
250template<
typename Index_,
typename Stat_>
251ScoreMarkersPairwiseBuffers<Stat_> fill_pairwise_results(Index_ ngenes, std::size_t ngroups, ScoreMarkersPairwiseResults<Stat_>& store,
const ScoreMarkersPairwiseOptions& opt) {
252 ScoreMarkersPairwiseBuffers<Stat_> output;
254 internal::fill_average_results(ngenes, ngroups, store.mean, store.detected, output.mean, output.detected);
256 auto num_effect_sizes = sanisizer::product<typename std::vector<Stat_>::size_type>(ngenes, ngroups, ngroups);
258 if (opt.compute_cohens_d) {
259 store.cohens_d.resize(num_effect_sizes
260#ifdef SCRAN_MARKERS_TEST_INIT
261 , SCRAN_MARKERS_TEST_INIT
264 output.cohens_d = store.cohens_d.data();
266 if (opt.compute_auc) {
267 store.auc.resize(num_effect_sizes
268#ifdef SCRAN_MARKERS_TEST_INIT
269 , SCRAN_MARKERS_TEST_INIT
272 output.auc = store.auc.data();
274 if (opt.compute_delta_mean) {
275 store.delta_mean.resize(num_effect_sizes
276#ifdef SCRAN_MARKERS_TEST_INIT
277 , SCRAN_MARKERS_TEST_INIT
280 output.delta_mean = store.delta_mean.data();
282 if (opt.compute_delta_detected) {
283 store.delta_detected.resize(num_effect_sizes
284#ifdef SCRAN_MARKERS_TEST_INIT
285 , SCRAN_MARKERS_TEST_INIT
288 output.delta_detected = store.delta_detected.data();
363template<
typename Value_,
typename Index_,
typename Group_,
typename Stat_>
370 Index_ NC = matrix.
ncol();
371 auto group_sizes = tatami_stats::tabulate_groups(group, NC);
377 auto ngroups = group_sizes.size();
378 auto payload_size = sanisizer::product<typename std::vector<Stat_>::size_type>(matrix.
nrow(), ngroups);
379 std::vector<Stat_> group_means(payload_size), group_vars(payload_size), group_detected(payload_size);
382 internal::scan_matrix_by_row<true>(
387 static_cast<int*
>(NULL),
401 internal::scan_matrix_by_column(
413 internal::process_simple_pairwise_effects(
465template<
typename Value_,
typename Index_,
typename Group_,
typename Block_,
typename Stat_>
473 Index_ NC = matrix.
ncol();
474 auto ngroups = output.
mean.size();
475 auto nblocks = tatami_stats::total_groups(block, NC);
477 auto combinations = internal::create_combinations(ngroups, group, block, NC);
478 auto combo_sizes = internal::tabulate_combinations<Index_>(ngroups, nblocks, combinations);
479 auto ncombos = combo_sizes.size();
482 auto payload_size = sanisizer::product<typename std::vector<Stat_>::size_type>(matrix.
nrow(), ncombos);
483 std::vector<Stat_> combo_means(payload_size), combo_vars(payload_size), combo_detected(payload_size);
486 internal::scan_matrix_by_row<false>(
505 internal::scan_matrix_by_column(
517 internal::process_simple_pairwise_effects(
546template<
typename Stat_ =
double,
typename Value_,
typename Index_,
typename Group_>
548 auto ngroups = tatami_stats::total_groups(group, matrix.
ncol());
550 auto buffers = internal::fill_pairwise_results(matrix.
nrow(), ngroups, res, options);
573template<
typename Stat_ =
double,
typename Value_,
typename Index_,
typename Group_,
typename Block_>
575 auto ngroups = tatami_stats::total_groups(group, matrix.
ncol());
577 auto buffers = internal::fill_pairwise_results(matrix.
nrow(), ngroups, res, options);
void score_markers_pairwise_blocked(const tatami::Matrix< Value_, Index_ > &matrix, const Group_ *group, const Block_ *block, const ScoreMarkersPairwiseOptions &options, const ScoreMarkersPairwiseBuffers< Stat_ > &output)
Definition score_markers_pairwise.hpp:466