mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Utilities for working with std::vector.
template<typename vectorT > | |
void | mx::math::vectorScale (vectorT &vec, size_t N=0, typename vectorT::value_type scale=0, typename vectorT::value_type offset=0) |
Fill in a vector with a regularly spaced scale. More... | |
template<typename memberT > | |
std::vector< size_t > | mx::math::vectorSortOrder (std::vector< memberT > const &values) |
Return the indices of the vector in sorted order, without altering the vector itself. More... | |
template<typename valueT > | |
valueT | mx::math::vectorSum (const valueT *vec, size_t sz) |
Calculate the sum of a vector. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorSum (const vectorT &vec) |
Calculate the sum of a vector. More... | |
template<typename valueT > | |
valueT | mx::math::vectorMean (const valueT *vec, size_t sz) |
Calculate the mean of a vector. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorMean (const vectorT &vec) |
Calculate the mean of a vector. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorMean (const vectorT &vec, const vectorT &w) |
Calculate the weighted mean of a vector. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorMedianInPlace (vectorT &vec) |
Calculate median of a vector in-place, altering the vector. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorMedian (const vectorT &vec, vectorT *work=0) |
Calculate median of a vector, leaving the vector unaltered. More... | |
template<typename valueT > | |
valueT | mx::math::vectorVariance (const valueT *vec, size_t sz, valueT mean) |
Calculate the variance of a vector relative to a supplied mean value. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorVariance (const vectorT &vec, const typename vectorT::value_type &mean) |
Calculate the variance of a vector relative to a supplied mean value. More... | |
template<typename valueT > | |
valueT | mx::math::vectorVariance (const valueT *vec, size_t sz) |
Calculate the variance of a vector. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorVariance (const vectorT &vec) |
Calculate the variance of a vector. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorSigmaMean (const vectorT &vec, const vectorT *weights, typename vectorT::value_type sigma, int &maxPasses) |
Calculate the sigma-clipped mean of a vector. More... | |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorSigmaMean (const vectorT &vec, typename vectorT::value_type sigma) |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorSigmaMean (const vectorT &vec, const vectorT &weights, typename vectorT::value_type sigma, int &maxPasses) |
template<typename vectorT > | |
vectorT::value_type | mx::math::vectorSigmaMean (const vectorT &vec, const vectorT &weights, typename vectorT::value_type sigma) |
template<typename valueT , typename constT > | |
void | mx::math::vectorSub (valueT *vec, size_t sz, const constT &c) |
Subtract a constant value from a vector. More... | |
template<typename vecT , typename constT > | |
void | mx::math::vectorSub (vecT &vec, const constT &c) |
Subtract a constant value from a vector. More... | |
template<typename valueT > | |
void | mx::math::vectorMeanSub (valueT *vec, size_t sz) |
Subtract the mean from a vector. More... | |
template<typename vecT > | |
void | mx::math::vectorMeanSub (vecT &vec) |
Subtract the mean from a vector. More... | |
template<typename vecT > | |
void | mx::math::vectorMedianSub (vecT &vec) |
Subtract the median from a vector. More... | |
template<typename realT > | |
int | mx::math::vectorSmoothMean (realT *smVec, realT *vec, size_t vecSize, int win) |
Smooth a vector using the mean in a window specified by its full-width. More... | |
template<typename realT > | |
int | mx::math::vectorSmoothMean (std::vector< realT > &smVec, std::vector< realT > &vec, int win) |
Smooth a vector using the mean in a window specified by its full-width. More... | |
template<typename realT > | |
int | mx::math::vectorSmoothMean (std::vector< realT > &smVec, std::vector< realT > &vec, std::vector< int > &wins, bool norm=false) |
Smooth a vector using the mean in windows specified by their full-widths. More... | |
template<typename realT > | |
int | mx::math::vectorSmoothMedian (std::vector< realT > &smVec, std::vector< realT > &vec, int win) |
Smooth a vector using the median in a window specified by its full-width. More... | |
template<typename realT > | |
int | mx::math::vectorSmoothMax (std::vector< realT > &smVec, std::vector< realT > &vec, int win) |
Smooth a vector using the max in a window specified by its full-width. More... | |
template<typename vectorT > | |
int | mx::math::vectorRebin (vectorT &binv, const vectorT &v, unsigned n, bool binMean=false) |
Re-bin a vector by summing (or averaging) in bins of size n points. More... | |
template<typename vectorT , typename binVectorT > | |
int | mx::math::vectorBinMeans (std::vector< vectorT > &means, binVectorT &binSzs, const vectorT &v) |
Calculate and accumulate the means of a timeseries in bins of various sizes. More... | |
template<typename realT > | |
int | mx::math::vectorGaussConvolve (std::vector< realT > &dataOut, const std::vector< realT > &dataIn, const std::vector< realT > &scale, const realT fwhm, const int winhw) |
Convolve (smooth) a vector with a Gaussian. More... | |
template<typename floatT > | |
int | mx::math::vectorCumHist (std::vector< floatT > &svec, std::vector< floatT > &sum, std::vector< floatT > &vec) |
Calculate a cumulative histogram of a vector. More... | |
template<typename floatT > | |
int | mx::math::vectorCumHistReverse (std::vector< floatT > &svec, std::vector< floatT > &sum, std::vector< floatT > &vec) |
Calculate a reverse cumulative histogram of a vector. More... | |
int mx::math::vectorBinMeans | ( | std::vector< vectorT > & | means, |
binVectorT & | binSzs, | ||
const vectorT & | v | ||
) |
Calculate and accumulate the means of a timeseries in bins of various sizes.
Useful mainly to calculate the variance of the mean as a function of sample size. The output is a vector of vectors, where each element is a vector which contains the means in the unique bins of size corresponding to the same index in the in put binSzs vector.
[out] | means | the means in each distinct bin. Not cleared, but Will be resized with new means appended. |
[in] | binSzs | the bin sizes in which to calculate the means |
[in] | v | the input vector to bin . |
Definition at line 730 of file vectorUtils.hpp.
References mx::math::vectorRebin().
int mx::math::vectorCumHist | ( | std::vector< floatT > & | svec, |
std::vector< floatT > & | sum, | ||
std::vector< floatT > & | vec | ||
) |
Calculate a cumulative histogram of a vector.
Sorts the vector and sums.
0 | on success, -1 otherwise. |
floatT | the floating point type of the vector contens. |
[out] | svec | Contains the sorted vector. |
[out] | sum | Contains the cumulative or running sum of the sorted vector |
[in] | vec | The vector to sort and sum. |
Definition at line 805 of file vectorUtils.hpp.
int mx::math::vectorCumHistReverse | ( | std::vector< floatT > & | svec, |
std::vector< floatT > & | sum, | ||
std::vector< floatT > & | vec | ||
) |
Calculate a reverse cumulative histogram of a vector.
Reverse-sorts the vector and sums.
0 | on success, -1 otherwise. |
floatT | the floating point type of the vector contens. |
[out] | svec | Contains the reverse-sorted vector. |
[out] | sum | Contains the cumulative or running sum of the reverse-sorted vector |
[in] | vec | The vector to reverse-sort and sum. |
Definition at line 834 of file vectorUtils.hpp.
int mx::math::vectorGaussConvolve | ( | std::vector< realT > & | dataOut, |
const std::vector< realT > & | dataIn, | ||
const std::vector< realT > & | scale, | ||
const realT | fwhm, | ||
const int | winhw | ||
) |
Convolve (smooth) a vector with a Gaussian.
realT | is the real floating point type of the data. |
[out] | dataOut | The smoothed data vector. Resized. |
[in] | dataIn | The data vector to smooth. |
[in] | scale | The scale vector used to calculate the kernel. |
[in] | fwhm | The FWHM of the Gaussian kernel, same units as scale. |
[in] | winhw | The window half-width in pixels. |
Definition at line 758 of file vectorUtils.hpp.
References mx::astro::constants::G(), and mx::astro::constants::sigma().
valueT mx::math::vectorMean | ( | const valueT * | vec, |
size_t | sz | ||
) |
Calculate the mean of a vector.
vectorT | the std::vector type of vec |
[in] | vec | the vector |
[in] | sz | the size of the vector |
Definition at line 150 of file vectorUtils.hpp.
Referenced by mx::improc::imCenterCircleSym< realT >::center(), mx::improc::eigenCube< dataT >::mean(), and mx::improc::sourceFinder< _realT >::operator()().
vectorT::value_type mx::math::vectorMean | ( | const vectorT & | vec | ) |
Calculate the mean of a vector.
vectorT | the std::vector type of vec |
[in] | vec | the vector |
Definition at line 172 of file vectorUtils.hpp.
vectorT::value_type mx::math::vectorMean | ( | const vectorT & | vec, |
const vectorT & | w | ||
) |
Calculate the weighted mean of a vector.
vectorT | the std::vector type of vec and w |
[in] | vec | the vector */ |
[in] | w | the weights |
Definition at line 191 of file vectorUtils.hpp.
Referenced by mx::math::vectorMeanSub(), mx::math::vectorSigmaMean(), and mx::math::vectorVariance().
void mx::math::vectorMeanSub | ( | valueT * | vec, |
size_t | sz | ||
) |
Subtract the mean from a vector.
vec | [in.out] the vector, each element will have the mean subtracted from it | |
[in] | sz | the vector size |
Definition at line 505 of file vectorUtils.hpp.
References mx::math::vectorMean(), and mx::math::vectorSub().
void mx::math::vectorMeanSub | ( | vecT & | vec | ) |
Subtract the mean from a vector.
vec | [in.out] the vector, each element will have the mean subtracted from it |
Definition at line 515 of file vectorUtils.hpp.
vectorT::value_type mx::math::vectorMedian | ( | const vectorT & | vec, |
vectorT * | work = 0 |
||
) |
Calculate median of a vector, leaving the vector unaltered.
Returns the center element if vec has an odd number of elements. Returns the mean of the center 2 elements if vec has an even number of elements.
vectorT | the std::vector type of vec |
[in] | vec | the vector for which the median is desired |
[in] | work | [optional] an optional vector to use as workspace, use to avoid re-allocation |
Definition at line 247 of file vectorUtils.hpp.
References mx::math::vectorMedianInPlace().
Referenced by mx::improc::aperturePhotometer< realT >::cumPhotWork(), mx::improc::sourceFinder< _realT >::operator()(), mx::math::vectorMedianSub(), and mx::math::vectorSigmaMean().
vectorT::value_type mx::math::vectorMedianInPlace | ( | vectorT & | vec | ) |
Calculate median of a vector in-place, altering the vector.
Returns the center element if vec has an odd number of elements. Returns the mean of the center 2 elements if vec has an even number of elements.
vectorT | the std::vector type of vec |
[in] | vec | the vector, is altered by std::nth_element |
Definition at line 218 of file vectorUtils.hpp.
Referenced by mx::improc::imageMedian(), mx::improc::medianSmooth(), mx::math::vectorMedian(), and mx::math::vectorSmoothMedian().
void mx::math::vectorMedianSub | ( | vecT & | vec | ) |
Subtract the median from a vector.
vec | [in.out] the vector, each element will have the median subtracted from it |
Definition at line 522 of file vectorUtils.hpp.
References mx::math::vectorMedian(), and mx::math::vectorSub().
int mx::math::vectorRebin | ( | vectorT & | binv, |
const vectorT & | v, | ||
unsigned | n, | ||
bool | binMean = false |
||
) |
Re-bin a vector by summing (or averaging) in bins of size n points.
vectorT | is any vector-like type with resize(), size(), and the operator()[]. |
[out] | binv | the re-binned vector. will be resized. |
[in] | v | the vector to bin. |
[in] | n | the size of the bins, in points |
[in] | binMean | [optional] flag controlling whether sums (false) or means (true) are calculated. |
Definition at line 691 of file vectorUtils.hpp.
Referenced by mx::math::vectorBinMeans().
void mx::math::vectorScale | ( | vectorT & | vec, |
size_t | N = 0 , |
||
typename vectorT::value_type | scale = 0 , |
||
typename vectorT::value_type | offset = 0 |
||
) |
Fill in a vector with a regularly spaced scale.
Fills in the vector with a 0....N-1 scale. The spacing of the points can be changed with the scale parameter, and the starting point can be changed with the offset.
Example:
vectorT | is a std::vector type. |
[out] | vec | the vector to fill in, can be pre-allocated or not |
[in] | N | [optional] if specified > 0, then vec is resize()-ed. Default is 0, and vec is not resize()-ed. |
[in] | scale | [optional] if specified !=0, then the points are spaced by this value. Default spacing is 1. |
[in] | offset | [optional] if specified !=0, then the starting point of the scale is this value. |
Definition at line 62 of file vectorUtils.hpp.
Referenced by mx::AO::analysis::fourierTemporalPSD< _realT, aosysT >::makePSDGrid().
vectorT::value_type mx::math::vectorSigmaMean | ( | const vectorT & | vec, |
const vectorT & | weights, | ||
typename vectorT::value_type | sigma | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | vec | the vector (unaltered) |
[in] | weights | [optional] the weights (unaltered) |
[in] | sigma | the standard deviation threshold to apply. |
Definition at line 473 of file vectorUtils.hpp.
References mx::astro::constants::sigma().
Referenced by mx::math::vectorSigmaMean().
vectorT::value_type mx::math::vectorSigmaMean | ( | const vectorT & | vec, |
const vectorT & | weights, | ||
typename vectorT::value_type | sigma, | ||
int & | maxPasses | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | vec | the vector (unaltered) |
[in] | weights | [optional] the weights (unaltered) |
[in] | sigma | the standard deviation threshold to apply. |
maxPasses | [in.out] [optional] the maximum number of sigma-clipping passes. Set to actual number of passes on return. |
Definition at line 459 of file vectorUtils.hpp.
References mx::astro::constants::sigma(), and mx::math::vectorSigmaMean().
vectorT::value_type mx::math::vectorSigmaMean | ( | const vectorT & | vec, |
const vectorT * | weights, | ||
typename vectorT::value_type | sigma, | ||
int & | maxPasses | ||
) |
Calculate the sigma-clipped mean of a vector.
Performas sigma-clipping relative to the median, removing any values with deviation from the median > sigma. Continues until either no values are removed, or maxPasses iterations. If maxPasses == 0, then it is ignored.
vectorT | the std::vector type of vec |
[in] | vec | the vector (unaltered) |
[in] | weights | [optional] the weights (unaltered) |
[in] | sigma | the standard deviation threshold to apply. |
maxPasses | [in.out] [optional] the maximum number of sigma-clipping passes. Set to actual number of passes on return. |
Definition at line 365 of file vectorUtils.hpp.
References mx::astro::constants::sigma(), mx::math::vectorMean(), mx::math::vectorMedian(), and mx::math::vectorVariance().
Referenced by mx::improc::eigenCube< dataT >::sigmaMean().
vectorT::value_type mx::math::vectorSigmaMean | ( | const vectorT & | vec, |
typename vectorT::value_type | sigma | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | vec | the vector (unaltered) |
[in] | sigma | the standard deviation threshold to apply. |
Definition at line 446 of file vectorUtils.hpp.
References mx::astro::constants::sigma(), and mx::math::vectorSigmaMean().
int mx::math::vectorSmoothMax | ( | std::vector< realT > & | smVec, |
std::vector< realT > & | vec, | ||
int | win | ||
) |
Smooth a vector using the max in a window specified by its full-width.
[out] | smVec | the smoothed version of the vector |
[in] | vec | the input vector, unaltered. |
[in] | win | the full-width of the smoothing window |
Definition at line 659 of file vectorUtils.hpp.
int mx::math::vectorSmoothMean | ( | realT * | smVec, |
realT * | vec, | ||
size_t | vecSize, | ||
int | win | ||
) |
Smooth a vector using the mean in a window specified by its full-width.
[out] | smVec | the smoothed version of the vector. At least as large as vec . |
[in] | vec | the input vector, unaltered. |
[in] | vecSize | the size of vec |
[in] | win | the full-width of the smoothing window. Should be even. 0 results in a slow memcpy. |
Definition at line 530 of file vectorUtils.hpp.
int mx::math::vectorSmoothMean | ( | std::vector< realT > & | smVec, |
std::vector< realT > & | vec, | ||
int | win | ||
) |
Smooth a vector using the mean in a window specified by its full-width.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[out] | smVec | the smoothed version of the vector. Will be resize()-ed. |
[in] | vec | the input vector, unaltered. |
[in] | win | the full-width of the smoothing window. Should be even. 0 results in a slow memcpy. |
Definition at line 562 of file vectorUtils.hpp.
References mx::math::vectorSmoothMean().
int mx::math::vectorSmoothMean | ( | std::vector< realT > & | smVec, |
std::vector< realT > & | vec, | ||
std::vector< int > & | wins, | ||
bool | norm = false |
||
) |
Smooth a vector using the mean in windows specified by their full-widths.
You supply a window width for each point. This is useful for, say, logarithmically growing bin sizes in a PSD.
[out] | smVec | the smoothed version of the vector |
[in] | vec | the input vector, unaltered. |
[in] | wins | the full-widths of the smoothing windows, same size as vec. |
[in] | norm | if true the output will normalized to have the same integral as the input. |
Definition at line 580 of file vectorUtils.hpp.
Referenced by mx::math::vectorSmoothMean().
int mx::math::vectorSmoothMedian | ( | std::vector< realT > & | smVec, |
std::vector< realT > & | vec, | ||
int | win | ||
) |
Smooth a vector using the median in a window specified by its full-width.
[out] | smVec | the smoothed version of the vector |
[in] | vec | the input vector, unaltered. |
[in] | win | the full-width of the smoothing window |
Definition at line 629 of file vectorUtils.hpp.
References mx::math::vectorMedianInPlace().
std::vector<size_t> mx::math::vectorSortOrder | ( | std::vector< memberT > const & | values | ) |
Return the indices of the vector in sorted order, without altering the vector itself.
Example:
memberT | is the member type of the vector. Must have < comparison defined. |
[in] | values | the vector to sort |
Definition at line 92 of file vectorUtils.hpp.
Referenced by mx::astro::rewritePhoenixSpectrum().
void mx::math::vectorSub | ( | valueT * | vec, |
size_t | sz, | ||
const constT & | c | ||
) |
Subtract a constant value from a vector.
vec | [in.out] the vector, each element will have the constant subtracted from it | |
[in] | sz | the size of the vector |
[in] | c | the constant to subtract from each element |
Definition at line 486 of file vectorUtils.hpp.
References mx::astro::constants::c().
void mx::math::vectorSub | ( | vecT & | vec, |
const constT & | c | ||
) |
Subtract a constant value from a vector.
vec | [in.out] the vector, each element will have the constant subtracted from it | |
[in] | c | the constant to subtract from each element |
Definition at line 496 of file vectorUtils.hpp.
References mx::astro::constants::c().
Referenced by mx::math::vectorMeanSub(), and mx::math::vectorMedianSub().
valueT mx::math::vectorSum | ( | const valueT * | vec, |
size_t | sz | ||
) |
Calculate the sum of a vector.
vectorT | the std::vector type of vec |
[in] | vec | the vector |
[in] | sz | the size of the vector |
Definition at line 112 of file vectorUtils.hpp.
vectorT::value_type mx::math::vectorSum | ( | const vectorT & | vec | ) |
Calculate the sum of a vector.
vectorT | the std::vector type of vec |
[in] | vec | the vector |
Definition at line 132 of file vectorUtils.hpp.
valueT mx::math::vectorVariance | ( | const valueT * | vec, |
size_t | sz | ||
) |
Calculate the variance of a vector.
vectorT | the std::vector type of vec |
[in] | vec | the vector |
[in] | sz | the size of the vector |
Definition at line 327 of file vectorUtils.hpp.
References mx::math::vectorMean(), and mx::math::vectorVariance().
valueT mx::math::vectorVariance | ( | const valueT * | vec, |
size_t | sz, | ||
valueT | mean | ||
) |
Calculate the variance of a vector relative to a supplied mean value.
valueT | the data type |
[in] | vec | the vector |
[in] | sz | the size of the vector |
[in] | mean | the mean value with which to calculate the variance |
Definition at line 282 of file vectorUtils.hpp.
Referenced by mx::improc::imCenterCircleSym< realT >::center(), mx::improc::sourceFinder< _realT >::operator()(), mx::sigproc::averagePeriodogram< realT >::operator()(), SCENARIO(), and mx::improc::stddevImage().
vectorT::value_type mx::math::vectorVariance | ( | const vectorT & | vec | ) |
Calculate the variance of a vector.
vectorT | the std::vector type of vec |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | vec | the vector |
Definition at line 346 of file vectorUtils.hpp.
References mx::math::vectorMean().
Referenced by mx::math::vectorSigmaMean(), and mx::math::vectorVariance().
vectorT::value_type mx::math::vectorVariance | ( | const vectorT & | vec, |
const typename vectorT::value_type & | mean | ||
) |
Calculate the variance of a vector relative to a supplied mean value.
vectorT | the std::vector type of vec |
[in] | vec | the vector |
[in] | mean | the mean value with which to calculate the variance |
Definition at line 305 of file vectorUtils.hpp.