Numerics
Namespace: UTILSLIB · Library: Utilities Library
#include <utils/numerics.h>
class UTILSLIB::Numerics
Static numerical helpers: integer GCD and log2, nchoose2, sparsity test, fixed-width histogram binning and time-series baseline rescaling shared across MATHLIB, DISP and the evoked / source-estimate pipelines.
Static scalar/per-vector numerical helpers (GCD, log2, histograms, baseline rescaling).
MatrixXd data(2, 6);
data << 1, 2, 3, 4, 6, 8, 2, 2, 2, 4, 4, 4;
RowVectorXf times(6);
times << -0.2f, -0.1f, 0.0f, 0.1f, 0.2f, 0.3f;
const MatrixXd percent = Numerics::rescale(data, times, std::make_pair(-0.2f, 0.0f), std::string("percent")); // (x - mean) / mean over baseline
Public Methods
~Numerics()
Destroys the Numerics object.
Static Methods
gcd(iA, iB)
Finds the Greatest Common Divisor (GCD) of two integer values.
Parameters:
-
iA : int First input integer.
-
iB : int Second input integer.
Returns:
- int — The Greatest Common Divisor (GCD) of iA and iB.
issparse(v)
Determines if a given data (stored as vector v) are representing a sparse matrix.
Parameters:
- v : Eigen::VectorXd & Data to be tested.
Returns:
- bool — true if sparse, false otherwise.
nchoose2(n)
Calculates the combination of n over 2 (nchoosek(n,2)).
Parameters:
- n : int The number of elements which should be combined with each other (n over 2).
Returns:
- int — The number of combinations.
chi2Isf(p, dof)
Value a chi^2 variable exceeds with probability p (scipy.stats.chi2.isf).
Parameters:
-
p : double Upper-tail probability.
-
dof : int Degrees of freedom.
Returns:
- double — The quantile.
rescale(data, times, baseline, mode)
Rescale (baseline correct) data.
Parameters:
-
data : const Eigen::MatrixXd & Data Matrix (m x n_time).
-
times : const Eigen::RowVectorXf & Time instants in seconds.
-
baseline : const QPair< float, float > & If baseline is (a, b) the interval is between "a (s)" and "b (s)". If a and b are equal, use interval between the beginning of the data and time 0.
-
mode : QString Baseline correction mode: "logratio" | "ratio" | "zscore" | "mean" | "percent".
Returns:
- Eigen::MatrixXd — Rescaled data matrix.
rescale(data, times, baseline, mode)
Rescale (baseline correct) data.
Parameters:
-
data : const Eigen::MatrixXd & Data Matrix (m x n_time).
-
times : const Eigen::RowVectorXf & Time instants in seconds.
-
baseline : const std::pair< float, float > & If baseline is (a, b) the interval is between "a (s)" and "b (s)". If a and b are equal, use interval between the beginning of the data and time 0.
-
mode : const std::string & Baseline correction mode: "logratio" | "ratio" | "zscore" | "mean" | "percent".
Returns:
- Eigen::MatrixXd — Rescaled data matrix.
log2(d)
Compute log base 2 of a given number.
Parameters:
- d : const T Input value.
Returns:
- double — log2 of d.
histcounts(matRawData, bMakeSymmetrical, iClassAmount, vecResultClassLimits, vecResultFrequency, dGlobalMin, dGlobalMax)
Creates a class and frequency distribution from data matrix.
Parameters:
-
matRawData : const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & Raw data matrix that needs to be analyzed.
-
bMakeSymmetrical : bool User input to turn the x-axis symmetric.
-
iClassAmount : int User input to determine the amount of classes in the histogram.
-
vecResultClassLimits : Eigen::VectorXd & The upper limit of each individual class.
-
vecResultFrequency : Eigen::VectorXi & The amount of data that fits in the appropriate class ranges.
-
dGlobalMin : double User input to determine the minimum value allowed in the histogram.
-
dGlobalMax : double User input to determine the maximum value allowed in the histogram.
histcounts(matRawData, bMakeSymmetrical, iClassAmount, vecResultClassLimits, vecResultFrequency, dGlobalMin, dGlobalMax)
histcounts(matRawData, bMakeSymmetrical, iClassAmount, vecResultClassLimits, vecResultFrequency, dGlobalMin, dGlobalMax)
Example
- Full source:
src/examples/ex_math/main.cpp - Build target:
ex_math(runs under CTest)
Used in examples
ex_histogram
Example application of reading raw data and presenting the result in histogram form.
dataSine = sineWaveGenerator(1.0e-6, (1.0 / 1.0e6), 0.0, 1.0); //creates synthetic data using sineWaveGenerator function
qDebug() << "sourceEstimateData.rows = " << sourceEstimateData.rows();
qDebug() << "sourceEstaimateData.cols = " << sourceEstimateData.cols();
Numerics::histcounts(sourceEstimateData, bMakeSymmetrical, classAmount, resultClassLimit, resultFrequency, inputGlobalMin, inputGlobalMax); //user input to normalize and sort the data matrix
std::cout << "resultClassLimits = " << resultClassLimit << std::endl;
std::cout << "resultFrequency = " << resultFrequency << std::endl;
qDebug() << "HistCounts timer:" << myTimerHistCounts.elapsed();
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>