tatami_stats
Matrix statistics for tatami
Loading...
Searching...
No Matches
Classes | Functions
tatami_stats::variances Namespace Reference

Functions for computing dimension-wise variances. More...

Classes

struct  Options
 Variance calculation options. More...
 
class  RunningDense
 Running variances from dense data. More...
 
class  RunningSparse
 Running variances from sparse data. More...
 

Functions

template<typename Output_ = double, typename Value_ , typename Index_ >
std::pair< Output_, Output_ > direct (const Value_ *value, Index_ num_nonzero, Index_ num_all, bool skip_nan)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::pair< Output_, Output_ > direct (const Value_ *ptr, Index_ num, bool skip_nan)
 
template<typename Value_ , typename Index_ , typename Output_ >
void apply (bool row, const tatami::Matrix< Value_, Index_ > *p, Output_ *output, const Options &vopt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > by_column (const tatami::Matrix< Value_, Index_ > *p, const Options &vopt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > by_column (const tatami::Matrix< Value_, Index_ > *p)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > by_row (const tatami::Matrix< Value_, Index_ > *p, const Options &vopt)
 
template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > by_row (const tatami::Matrix< Value_, Index_ > *p)
 

Detailed Description

Functions for computing dimension-wise variances.

Function Documentation

◆ direct() [1/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::pair< Output_, Output_ > tatami_stats::variances::direct ( const Value_ *  value,
Index_  num_nonzero,
Index_  num_all,
bool  skip_nan 
)

Compute the mean and variance from a sparse objective vector. This uses the standard two-pass algorithm with naive accumulation of the sum of squared differences; thus, it is best used with a sufficiently high-precision Output_ like double.

Template Parameters
Output_Type of the output data.
Value_Type of the input data.
Index_Type of the row/column indices.
Parameters
[in]valuePointer to an array of length num, containing the values of the structural non-zeros.
num_nonzeroLength of the array pointed to by value.
num_allLength of the objective vector, including the structural zeros not in value. This should be greater than or equal to num_nonzero.
skip_nanSee Options::skip_nan.
Returns
The sample mean and variance of values in the sparse array. This may be NaN if there are not enough (non-NaN) values in value.

◆ direct() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::pair< Output_, Output_ > tatami_stats::variances::direct ( const Value_ *  ptr,
Index_  num,
bool  skip_nan 
)

Compute the mean and variance from a dense objective vector. This uses the standard two-pass algorithm with naive accumulation of the sum of squared differences; thus, it is best used with a sufficiently high-precision Output_ like double.

Template Parameters
Output_Type of the output data.
Value_Type of the input data.
Index_Type of the row/column indices.
Parameters
[in]ptrPointer to an array of length num, containing the values of the objective vector.
numLength of the objective vector, i.e., length of the array at ptr.
skip_nanSee Options::skip_nan.
Returns
The sample mean and variance of values in [ptr, ptr + num). This may be NaN if there are not enough (non-NaN) values in ptr.

◆ apply()

template<typename Value_ , typename Index_ , typename Output_ >
void tatami_stats::variances::apply ( bool  row,
const tatami::Matrix< Value_, Index_ > *  p,
Output_ *  output,
const Options vopt 
)

Compute variances for each element of a chosen dimension of a tatami::Matrix. This may use either Welford's method or the standard two-pass method, depending on the dimension in row and the preferred access dimension of p.

Template Parameters
Value_Type of the matrix value, should be numeric.
Index_Type of the row/column indices.
Output_Type of the output value.
Parameters
rowWhether to compute the variance for each row. If false, the variance is computed for each column instead.
pPointer to a tatami::Matrix.
[out]outputPointer to an array of length equal to the number of rows (if row = true) or columns (otherwise). On output, this will contain the row/column variances.
voptVariance calculation options.

◆ by_column() [1/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::variances::by_column ( const tatami::Matrix< Value_, Index_ > *  p,
const Options vopt 
)

Wrapper around apply() for column variances.

Template Parameters
Output_Type of the output value.
Value_Type of the matrix value, should be numeric.
Index_Type of the row/column indices.
Parameters
pPointer to a tatami::Matrix.
voptVariance calculation options.
Returns
A vector of length equal to the number of columns, containing the column variances.

◆ by_column() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::variances::by_column ( const tatami::Matrix< Value_, Index_ > *  p)

Overload with default options.

Template Parameters
Output_Type of the output value.
Value_Type of the matrix value, should be numeric.
Index_Type of the row/column indices.
Parameters
pPointer to a tatami::Matrix.
Returns
A vector of length equal to the number of columns, containing the column variances.

◆ by_row() [1/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::variances::by_row ( const tatami::Matrix< Value_, Index_ > *  p,
const Options vopt 
)

Wrapper around apply() for column variances.

Template Parameters
Output_Type of the output value.
Value_Type of the matrix value, should be numeric.
Index_Type of the row/column indices.
Parameters
pPointer to a tatami::Matrix.
voptVariance calculation options.
Returns
A vector of length equal to the number of rows, containing the row variances.

◆ by_row() [2/2]

template<typename Output_ = double, typename Value_ , typename Index_ >
std::vector< Output_ > tatami_stats::variances::by_row ( const tatami::Matrix< Value_, Index_ > *  p)

Overload with default options.

Template Parameters
Output_Type of the output value.
Value_Type of the matrix value, should be numeric.
Index_Type of the row/column indices.
Parameters
pPointer to a tatami::Matrix.
Returns
A vector of length equal to the number of rows, containing the row variances.