scran_blocks
Blocking utilities for libscran
|
Blocking utilities for libscran. More...
Classes | |
struct | VariableWeightParameters |
Parameters for compute_variable_weight() . More... | |
Enumerations | |
enum class | WeightPolicy : char { NONE , VARIABLE , EQUAL } |
Blocking utilities for libscran.
|
strong |
Policy to use for weighting blocks based on their size, i.e., the number of cells in each block. This controls the calculation of weighted averages across blocks.
NONE
: no weighting is performed. Larger blocks will contribute more to the weighted average.EQUAL
: each block receives equal weight, regardless of its size. Equivalent to averaging across blocks without weights.VARIABLE
: each batch is weighted using the logic in compute_variable_weight()
. This penalizes small blocks with unreliable statistics while equally weighting all large blocks. std::vector< Output_ > scran_blocks::average_vectors | ( | size_t | n, |
std::vector< Stat_ * > | in, | ||
bool | skip_nan | ||
) |
Overload of compute()
that allocates an output vector of averaged values.
Output | Floating-point output type. |
Stat | Type of the input statistic, typically floating point. |
n | Length of each array. | |
[in] | in | Vector of pointers to input arrays of length n . |
skip_nan | Whether to check for NaNs. |
n
is returned, containing the average of all arrays in in
. void scran_blocks::average_vectors | ( | size_t | n, |
std::vector< Stat_ * > | in, | ||
Output_ * | out, | ||
bool | skip_nan | ||
) |
Average parallel elements across multiple arrays.
Stat_ | Type of the input statistic, typically floating point. |
Output_ | Floating-point output type. |
n | Length of each array. | |
[in] | in | Vector of pointers to input arrays of length n . |
[out] | out | Pointer to an output array of length n . On completion, out is filled with the average of all arrays in in . Specifically, each element of out is set to the average of the corresponding elements across all in arrays. |
skip_nan | Whether to check for NaNs. If true , NaNs are ignored in the average calculations for each element, at the cost of some efficiency. |
std::vector< Output_ > scran_blocks::average_vectors_weighted | ( | size_t | n, |
std::vector< Stat_ * > | in, | ||
const Weight_ * | w, | ||
bool | skip_nan | ||
) |
Overload of compute_weighted()
that allocates an output vector of averaged values.
Output_ | Floating-point output type. |
Weight_ | Type of the weight, typically floating point. |
Stat_ | Type of the input statistic, typically floating point. |
n | Length of each array. | |
[in] | in | Vector of pointers to input arrays of the same length. |
[in] | w | Pointer to an array of length equal to in.size() , containing the weight to use for each input array. Weights should be non-negative and finite. |
skip_nan | Whether to check for NaNs. |
in
. void scran_blocks::average_vectors_weighted | ( | size_t | n, |
std::vector< Stat_ * > | in, | ||
const Weight_ * | w, | ||
Output_ * | out, | ||
bool | skip_nan | ||
) |
Compute a weighted average of parallel elements across multiple arrays.
Stat_ | Type of the input statistic, typically floating point. |
Weight_ | Type of the weight, typically floating point. |
Output_ | Floating-point output type. |
n | Length of each array. | |
[in] | in | Vector of pointers to input arrays of length n . |
[in] | w | Pointer to an array of length equal to in.size() , containing the weight to use for each input array. Weights should be non-negative and finite. |
[out] | out | Pointer to an output array of length n . On output, out is filled with the weighted average of all arrays in in . Specifically, each element of out is set to the weighted average of the corresponding elements across all in arrays. |
skip_nan | Whether to check for NaNs. If true , NaNs are ignored in the average calculations for each element, at the cost of some efficiency. |
|
inline |
Assign a variable weight to each block of cells, for use in computing a weighted average across blocks. The weight for each block is calculated from the size of that block.
VariableWeightParameters::lower_bound
, it has zero weight.VariableWeightParameters::upper_bound
, it has weight of 1.Blocks that are "large enough" are considered to be equally trustworthy and receive the same weight, ensuring that each block contributes equally to the weighted average. By comparison, very small blocks receive lower weight as their statistics are generally less stable.
s | Size of the block, in terms of the number of cells in that block. |
params | Parameters for the weight calculation, consisting of the lower and upper bounds. |
std::vector< Weight_ > scran_blocks::compute_weights | ( | const std::vector< Size_ > & | sizes, |
WeightPolicy | policy, | ||
const VariableWeightParameters & | variable | ||
) |
A convenience overload that accepts and returns vectors.
Size_ | Numeric type for the block size. |
Weight_ | Floating-point type for the output weights. |
sizes | Vector containing the size of each block. |
policy | Policy for weighting blocks of different sizes. |
variable | Parameters for the variable block weights. |
void scran_blocks::compute_weights | ( | size_t | num_blocks, |
const Size_ * | sizes, | ||
WeightPolicy | policy, | ||
const VariableWeightParameters & | variable, | ||
Weight_ * | weights | ||
) |
Compute block weights for multiple blocks based on their size and the weighting policy. For variable weights, this function will call compute_variable_weight()
for each block.
Size_ | Numeric type for the block size. |
Weight_ | Floating-point type for the output weights. |
num_blocks | Number of blocks. | |
[in] | sizes | Pointer to an array of length num_blocks , containing the size of each block. |
policy | Policy for weighting blocks of different sizes. | |
variable | Parameters for the variable block weights. | |
[out] | weights | Pointer to an array of length num_blocks . On output, this is filled with the weight of each block. |