20 #ifndef ESSENTIA_MATH_H
21 #define ESSENTIA_MATH_H
23 #ifndef _USE_MATH_DEFINES
24 #define _USE_MATH_DEFINES
41 #define M_2PI (2 * M_PI)
46 return (n & (n-1)) == 0;
49 template <
typename T> T
log2(T x) {
50 return log(x) / M_LN2;
55 if (n < 0)
return ilog10(-n);
88 template <
typename T> T
norm(
const std::vector<T>& array) {
95 for (
uint i=0; i<array.size(); i++) {
96 sum += array[i] * array[i];
105 template <
typename T> T
sumSquare(
const std::vector<T> array) {
107 for (
size_t i = 0; i < array.size(); ++i) {
108 sum += array[i] * array[i];
116 template <
typename T> T
sum(
const std::vector<T>& array,
int start,
int end) {
120 for (; i<end-8; i+=8) {
142 template <
typename T> T
mean(
const std::vector<T>& array,
int start,
int end) {
143 return sum(array, start, end) / (end - start);
149 template <
typename T> T
sum(
const std::vector<T>& array) {
150 if (array.empty())
return 0;
151 return sum(array, 0, array.size());
157 template <
typename T> T
mean(
const std::vector<T>& array) {
160 return mean(array, 0, array.size());
166 template <
typename T>
173 for (
int i = 0; i < (int)array.size(); i++) {
183 template <
typename T>
190 for (
int i = 0; i < (int)array.size(); i++) {
198 template <
typename T>
199 std::vector<T>
meanFrames(
const std::vector<std::vector<T> >& frames,
int beginIdx=0,
int endIdx=-1) {
200 if (frames.empty()) {
204 if (endIdx == -1) endIdx = (int)frames.size();
205 uint vsize = frames[0].size();
207 std::vector<T> result(vsize, (T)0.0);
208 typename std::vector<std::vector<T> >::const_iterator it = frames.begin() + beginIdx;
209 typename std::vector<std::vector<T> >::const_iterator end = frames.begin() + endIdx;
210 for (; it!=end; ++it) {
211 typename std::vector<T>::const_iterator itFrame = it->begin();
212 typename std::vector<T>::const_iterator endFrame = it->end();
213 typename std::vector<T>::iterator itResult = result.begin();
214 for (; itFrame != endFrame; ++itFrame, ++itResult) {
215 *itResult += *itFrame;
218 for (
uint j=0; j<vsize; j++) result[j] /= (endIdx - beginIdx);
224 template <
typename T>
225 std::vector<T>
medianFrames(
const std::vector<std::vector<T> >& frames,
int beginIdx=0,
int endIdx=-1) {
226 if (frames.empty()) {
230 if (endIdx == -1) endIdx = (int)frames.size();
232 uint vsize = frames[0].size();
233 uint fsize = endIdx - beginIdx;
235 std::vector<T> result(vsize, (T)0.0);
239 for (
uint i=0; i<vsize; ++i) {
240 typename std::vector<std::vector<T> >::const_iterator it = frames.begin() + beginIdx;
241 typename std::vector<std::vector<T> >::const_iterator end = frames.begin() + endIdx;
244 for (; it!=end; ++it) {
245 temp.push_back((*it)[i]);
247 std::sort(temp.begin(), temp.end());
250 if (fsize % 2 == 0.0) {
251 result[i] = (temp[
uint(fsize/2 - 1)] + temp[
uint(fsize/2)]) / 2;
255 result[i] = temp[
uint(fsize/2)];
263 template <
typename T>
265 if (frames.empty()) {
266 throw EssentiaException(
"trying to calculate variance of empty array of frames");
269 uint nframes = frames.size();
270 uint vsize = frames[0].size();
274 std::vector<T> result(vsize, (T)0.0);
276 for (
uint i=0; i<nframes; i++) {
277 for (
uint j=0; j<vsize; j++) {
278 diff = frames[i][j] - m[j];
279 result[j] += diff*diff;
282 for (
uint j=0; j<vsize; j++) result[j] /= nframes;
289 template <
typename T>
290 std::vector<T>
sumFrames(
const std::vector<std::vector<T> >& frames) {
291 if (frames.empty()) {
292 throw EssentiaException(
"sumFrames: trying to calculate sum of empty input frames");
294 size_t nframes = frames.size();
295 size_t vsize = frames[0].size();
296 std::vector<T> result(vsize, (T)0);
297 for (
size_t j=0; j<vsize; j++) {
298 for (
size_t i=0; i<nframes; i++) {
299 result[j] += frames[i][j];
306 template <
typename T>
308 if (frames.empty()) {
309 throw EssentiaException(
"trying to calculate skewness of empty array of frames");
312 uint nframes = frames.size();
313 uint vsize = frames[0].size();
317 std::vector<T> result(vsize, (T)0.0);
318 std::vector<T> m3(vsize, (T)0.0);
319 std::vector<T> m2(vsize, (T)0.0);
321 for (
uint i=0; i<nframes; i++) {
322 for (
uint j=0; j<vsize; j++) {
323 diff = frames[i][j] - m[j];
325 m3[j] += diff*diff*diff;
328 for (
uint j=0; j<vsize; j++) {
331 if (m2[j] == (T)0.) result[j] = (T)0.;
332 else result[j] = m3[j] / pow(m2[j], (T)1.5);
338 template <
typename T>
340 if (frames.empty()) {
341 throw EssentiaException(
"trying to calculate kurtosis of empty array of frames");
344 uint nframes = frames.size();
345 uint vsize = frames[0].size();
349 std::vector<T> result(vsize, (T)0.0);
350 std::vector<T> m2(vsize, (T)0.0);
351 std::vector<T> m4(vsize, (T)0.0);
353 for (
uint i=0; i<nframes; i++) {
354 for (
uint j=0; j<vsize; j++) {
355 diff = frames[i][j] - m[j];
357 m4[j] += diff*diff*diff*diff;
360 for (
uint j=0; j<vsize; j++) {
363 if (m2[j] == (T)0.) result[j] = (T)(-3.);
364 else result[j] = m4[j] / (m2[j]*m2[j]) - 3;
372 template <
typename T> T
median(
const std::vector<T>& array) {
377 std::vector<T> sorted_array = array;
378 std::sort(sorted_array.begin(), sorted_array.end());
380 uint size = sorted_array.size();
383 if (size % 2 == 0.0) {
384 return (sorted_array[
uint(size/2 - 1)] + sorted_array[
uint(size/2)]) / 2;
388 return sorted_array[
uint(size/2)];
393 template <
typename T>
395 for (
int i=0; i<(int)array.size(); i++) {
396 array[i] = fabs(array[i]);
401 template <
typename T> T
energy(
const std::vector<T>& array) {
405 return inner_product(array.begin(), array.end(), array.begin(), (T)0.0);
410 return energy(array) / array.size();
423 #define SILENCE_CUTOFF 1e-10
424 #define DB_SILENCE_CUTOFF -100
425 #define LOG_SILENCE_CUTOFF -23.025850929940457
428 template <
typename T>
bool isSilent(
const std::vector<T>& array) {
433 template <
typename T>
441 for (
int i=0; i<(int)array.size(); i++) {
449 template <
typename T>
457 for (
int i=0; i<(int)array.size(); i++) {
466 template <
typename T> T
variance(
const std::vector<T>& array,
const T
mean) {
472 for (
uint i=0; i<array.size(); i++) {
473 T temp = array[i] -
mean;
481 template <
typename T> T
skewness(
const std::vector<T>& array,
const T
mean) {
485 const int n = (int)array.size();
486 T m2 = (T)0.0, m3 = (T)0.0;
488 for (
int i=0; i<n; i++) {
489 T temp = array[i] -
mean;
491 m3 += temp * temp * temp;
498 if (m2 == (T)0.) result = (T)0.;
499 else result = m3 / pow(m2, (T)1.5);
505 template <
typename T> T
kurtosis(
const std::vector<T>& array,
const T
mean) {
509 const int n = (int)array.size();
510 T m2 = (T)0.0, m4 = (T)0.0;
512 for (
int i=0; i<n; i++) {
513 T temp = array[i] -
mean;
515 m4 += temp * temp * temp * temp;
522 if (m2 == (T)0.) result = (T)(-3.);
523 else result = m4 / (m2*m2) - 3;
530 template <
typename T> T
stddev(
const std::vector<T>& array,
const T
mean) {
538 template <
typename T> T
round(
const T value) {
539 return (T)std::floor(value + (T)0.5);
548 return value < silenceCutoff ? dbSilenceCutoff : (
Real)10.0 * log10(value);
552 return pow((
Real)10.0, value/(
Real)10.0);
560 return lin2db(power, silenceCutoff, dbSilenceCutoff);
572 return Real(2.0)*
lin2db(amplitude, silenceCutoff, dbSilenceCutoff);
576 return db2lin(0.5*amplitude);
588 return input < silenceCutoff ? logSilenceCutoff : log(input);
599 inline T asinh(
const T x)
604 using ::std::numeric_limits;
606 T
const one =
static_cast<T
>(1);
607 T
const two =
static_cast<T
>(2);
609 static T
const taylor_2_bound = sqrt(numeric_limits<T>::epsilon());
610 static T
const taylor_n_bound = sqrt(taylor_2_bound);
611 static T
const upper_taylor_2_bound = one/taylor_2_bound;
612 static T
const upper_taylor_n_bound = one/taylor_n_bound;
614 if (x >= +taylor_n_bound) {
615 if (x > upper_taylor_n_bound) {
616 if (x > upper_taylor_2_bound) {
618 return( log( x * two) );
622 return( log( x*two + (one/(x*two)) ) );
626 return( log( x + sqrt(x*x+one) ) );
629 else if (x <= -taylor_n_bound) {
636 if (abs(x) >= taylor_2_bound)
641 result -= x3/
static_cast<T
>(6);
657 Real b = ((26.81*f)/(1960 + f)) - 0.53;
659 if (b < 2) b += 0.15*(2-b);
660 if (b > 20.1) b += 0.22*(b - 20.1);
675 if (z < 2) z = (z - 0.3) / 0.85;
676 if (z > 20.1) z = (z - 4.422) / 1.22;
679 return 1960.0 * (z + 0.53) / (26.28 - z);
683 return 52548.0 / (z*z - 52.56 * z + 690.39);
688 return 700.0 * (exp(mel/1127.01048) - 1.0);
692 return 700.0 * (pow(10.0, mel/2595.0) - 1.0);
697 const Real minLogHz = 1000.0;
698 const Real linSlope = 3 / 200.;
699 const Real minLogMel = minLogHz * linSlope;
701 if (mel < minLogMel) {
703 return mel / linSlope;
707 const Real logStep = log(6.4) / 27.0;
708 return minLogHz * exp((mel - minLogMel) * logStep);
713 return 1127.01048 * log(hz/700.0 + 1.0);
717 return 2595.0 * log10(hz/700.0 + 1.0);
722 const Real minLogHz = 1000.0;
723 const Real linSlope = 3 / 200.;
727 return hz * linSlope;
731 const Real minLogMel = minLogHz * linSlope;
732 const Real logStep = log(6.4) / 27.0;
733 return minLogMel + log(hz/minLogHz) / logStep;
742 return 12 * std::log(hz/440)/std::log(2.) + 69;
745 inline int argmin(
const std::vector<Real>& input) {
748 return std::min_element(input.begin(), input.end()) - input.begin();
751 inline int argmax(
const std::vector<Real>& input) {
754 return std::max_element(input.begin(), input.end()) - input.begin();
759 template <
typename T>
void normalize(std::vector<T>& array) {
760 if (array.empty())
return;
762 T maxElement = *std::max_element(array.begin(), array.end());
764 if (maxElement != (T) 0.0) {
765 for (
uint i=0; i<array.size(); i++) {
766 array[i] /= maxElement;
773 if (array.empty())
return;
774 std::vector<T> absArray = array;
776 T maxElement = *std::max_element(absArray.begin(), absArray.end());
778 if (maxElement != (T) 0.0) {
779 for (
uint i=0; i<array.size(); i++) {
780 array[i] /= maxElement;
786 template <
typename T>
void normalizeAbs(std::vector<T>& array, T headroom) {
787 if (array.empty())
return;
788 std::vector<T> absArray = array;
790 T maxElement = *std::max_element(absArray.begin(), absArray.end());
792 if (maxElement != (T) 0.0) {
793 for (
uint i=0; i<array.size(); i++) {
794 array[i] /= (maxElement + headroom);
802 if (array.empty())
return;
805 T sumElements = (T) 0.;
806 for (
size_t i=0; i<array.size(); ++i) {
807 if (array[i] < 0)
return;
808 sumElements += array[i];
811 if (sumElements != (T) 0.0) {
812 for (
size_t i=0; i<array.size(); ++i) {
813 array[i] /= sumElements;
820 template <
typename T>
822 if (array.size() < 2) {
823 throw EssentiaException(
"trying to calculate approximate derivative of empty or single-element array");
826 std::vector<T> result(array.size()-1, (T)0.0);
827 for (
int i=0; i<(int)result.size(); i++) {
828 result[i] = array[i+1] - array[i];
833 template<
typename T,
typename U,
typename Comparator=std::greater<T> >
837 bool operator () (
const std::pair<T,U>& p1,
const std::pair<T,U>& p2)
const {
838 if (
_cmp(p1.first, p2.first))
return true;
839 if (
_cmp(p2.first, p1.first))
return false;
840 return _cmp(p1.second, p2.second);
846 template <
typename T,
typename U,
typename Comparator>
847 void sortpair(std::vector<T>& v1, std::vector<U>& v2) {
848 if (v1.size() != v2.size()) {
851 int size = v1.size();
852 std::vector<std::pair<T, U> > tmp(size);
853 for (
int i=0; i<size; i++)
854 tmp[i] = std::make_pair(v1[i], v2[i]);
856 for (
int i=0; i<size; i++) {
857 v1[i] = tmp[i].first;
858 v2[i] = tmp[i].second;
865 return std::fpclassify(x) == FP_SUBNORMAL;
875 template <
typename T> T
fmod(T a, T b) {
898 template <
typename T>
899 void hist(
const T* array,
uint n,
int* n_array, T* x_array,
uint n_bins) {
900 T miny = *std::min_element(array, array+n);
901 T maxy = *std::max_element(array, array+n);
904 for (
uint i=0; i<n_bins; i++) {
905 x_array[i] = (0.5 + i)*(maxy - miny)/n_bins + miny;
909 std::vector<T> cutoff(n_bins - 1);
910 for (
uint i=0; i<n_bins-1; i++) {
911 cutoff[i] = (x_array[i] + x_array[i+1]) / 2.0;
921 std::vector<T> dist(array, array+n);
922 std::sort(dist.begin(), dist.end());
923 uint current_cutoff_idx = 0;
924 T current_cutoff = cutoff[0];
925 for (
uint i=0; i<n_bins; i++) n_array[i] = 0;
927 for (
uint i=0; i<n; i++) {
928 while (dist[i] > current_cutoff) {
930 if (current_cutoff_idx == n_bins-2) {
931 n_array[n_bins-1] = n-i;
936 current_cutoff_idx++;
937 current_cutoff = cutoff[current_cutoff_idx];
939 n_array[current_cutoff_idx]++;
947 template <
typename T>
948 void bincount(
const std::vector<T>& input, std::vector<T>& output) {
950 output.resize( (
int) ( std::max<Real>( input[
argmax(input)], 0.) + 0.5 ) + 1);
952 for (
uint i=0; i< input.size(); i++) {
953 index = int(std::max<Real>(input[i],0) + 0.5);
954 if (index < output.size() ) {
965 template <
typename T>
966 std::vector<std::vector<T> >
transpose(
const std::vector<std::vector<T> >& m) {
967 if (m.empty())
return std::vector<std::vector<T> >();
969 int nrows = m.size();
970 int ncols = m[0].size();
971 for (
int i=1; i<nrows; i++) {
972 if ((
int)m[i].size() != ncols) {
973 std::ostringstream ss;
974 ss <<
"Trying to transpose a non rectangular matrix. Expecting dim2 = " << ncols
975 <<
" but got " << m[i].size() <<
". Cannot transpose!";
980 std::vector<std::vector<T> > result(ncols, std::vector<Real>(nrows));
981 for (
int i=0; i<nrows; i++) {
982 for (
int j=0; j<ncols; j++) {
983 result[j][i] = m[i][j];
990 template <
typename T>
994 int nrows = m.
dim1();
995 int ncols = m.
dim2();
998 for (
int i=0; i<nrows; i++) {
999 for (
int j=0; j<ncols; j++) {
1000 result[j][i] = m[i][j];
1067 template <
typename T>
1069 if (inputMatrix.empty())
1071 for (
size_t i=0; i<inputMatrix.size(); i++) {
1072 std::rotate(inputMatrix[i].begin(), inputMatrix[i].end() - oti, inputMatrix[i].end());
1081 template <
typename T>
1082 T
dotProduct(
const std::vector<T>& xArray,
const std::vector<T>& yArray) {
1083 if (xArray.empty() || yArray.empty())
1084 throw EssentiaException(
"dotProduct: trying to calculate the dotProduct of empty arrays!");
1085 return std::inner_product(xArray.begin(), xArray.end(), yArray.begin(), 0.0);
1095 throw EssentiaException(
"percentile: trying to calculate percentile of empty array");
1097 std::vector<T> sorted_array = array;
1099 std::sort(sorted_array.begin(), sorted_array.end());
1100 qpercentile /= 100.;
1103 int sortArraySize = sorted_array.size();
1104 if (sortArraySize > 1) {
1105 k = (sortArraySize - 1) * qpercentile;
1109 k = sortArraySize * qpercentile;
1112 Real d0 = sorted_array[int(std::floor(k))] * (std::ceil(k) - k);
1113 Real d1 = sorted_array[int(std::ceil(k))] * (k - std::floor(k));
1121 template <
typename T> T
covariance(
const std::vector<T>& x,
const T xMean,
const std::vector<T>& y,
const T yMean) {
1126 if (x.size() != y.size())
1131 for (
uint i=0; i<x.size(); i++) {
1132 cov += (x[i] - xMean) * (y[i] - yMean);
1135 return (T)(cov / (
Real)x.size());
1148 if (x.size() != y.size())
1156 T xStddev =
stddev(x, xMean);
1157 T yStddev =
stddev(y, yMean);
1160 if ((xStddev == (T)0.0) || (xStddev == (T)0.0) || (xStddev == (T)0.0))
return (T) 0.0;
1162 T corr = cov / (xStddev * yStddev);
1167 return std::max(std::min(corr, (T)1.0), (T)-1.0);
1177 template <
typename T>
1179 if (inputArray.empty())
1182 for (
size_t i=0; i<inputArray.size(); i++) {
1183 for (
size_t j=0; j<inputArray[i].size(); j++) {
1185 inputArray[i][j] = (inputArray[i][j] < 0) ? 0 : 1;
1197 template <
typename T>
1198 std::vector<std::vector<T> >
pairwiseDistance(
const std::vector<std::vector<T> >& m,
const std::vector<std::vector<T> >& n) {
1200 if (m.empty() || n.empty())
1203 size_t mSize = m.size();
1204 size_t nSize = n.size();
1205 std::vector<std::vector<T> > pdist(mSize, std::vector<T>(nSize));
1206 for (
size_t i=0; i<mSize; i++) {
1207 for (
size_t j=0; j<nSize; j++) {
1209 pdist[i][j] = sqrt(item);
1213 throw EssentiaException(
"pairwiseDistance: outputs an empty similarity matrix!");
1221 template <
typename T>
1223 std::array<Eigen::Index, TENSORRANK - 1>& squeezeShape,
1224 std::array<Eigen::Index, TENSORRANK>& summarizerShape,
1225 std::array<Eigen::Index, TENSORRANK>& broadcastShape) {
1233 squeezeShape[i] = j;
1239 summarizerShape = {1, 1, 1, 1};
1240 summarizerShape[axis] = tensor.dimension(axis);
1244 broadcastShape = tensor.dimensions();
1245 broadcastShape[axis] = 1;
1251 template <
typename T>
1259 template <
typename T>
1261 std::array<Eigen::Index,
TENSORRANK - 1> squeezeShape;
1262 std::array<Eigen::Index, TENSORRANK> summarizerShape, broadcastShape;
1265 Tensor1D means = tensor.mean(squeezeShape);
1273 template <
typename T>
1280 return sqrt(sos / tensor.size());
1286 template <
typename T>
1288 std::array<Eigen::Index,
TENSORRANK - 1> squeezeShape;
1289 std::array<Eigen::Index, TENSORRANK> summarizerShape, broadcastShape;
1294 Real normalization = tensor.size() / tensor.dimension(axis);
1301 Tensor1D sos = tmp.pow(2).sum(squeezeShape);
1304 Tensor1D stds = (sos / normalization).sqrt();
1312 template <
typename T>
1320 template <
typename T>
1322 std::array<Eigen::Index,
TENSORRANK - 1> squeezeShape;
1323 std::array<Eigen::Index, TENSORRANK> summarizerShape, broadcastShape;
1326 Tensor1D minima = tensor.minimum(squeezeShape);
1334 template <
typename T>
1342 template <
typename T>
1344 std::array<Eigen::Index,
TENSORRANK - 1> squeezeShape;
1345 std::array<Eigen::Index, TENSORRANK> summarizerShape, broadcastShape;
1348 Tensor1D maxima = tensor.maximum(squeezeShape);
1356 template <
typename T>
1361 return round(pow(10, decimal) * x) / pow(10, decimal);
Definition: tnt_array2d.h:38
int dim1() const
Definition: tnt_array2d.h:231
int dim2() const
Definition: tnt_array2d.h:234
Definition: essentiamath.h:834
bool operator()(const std::pair< T, U > &p1, const std::pair< T, U > &p2) const
Definition: essentiamath.h:837
Comparator _cmp
Definition: essentiamath.h:835
#define M_2PI
Definition: essentiamath.h:41
#define SILENCE_CUTOFF
Definition: essentiamath.h:423
#define DB_SILENCE_CUTOFF
Definition: essentiamath.h:424
#define LOG_SILENCE_CUTOFF
Definition: essentiamath.h:425
Definition: algorithm.h:28
Real hz2cents(Real hz)
Definition: essentiamath.h:741
Real lin2log(Real value)
Definition: essentiamath.h:583
void rotateChroma(std::vector< std::vector< T > > &inputMatrix, int oti)
Definition: essentiamath.h:1068
std::vector< T > kurtosisFrames(const std::vector< std::vector< T > > &frames)
Definition: essentiamath.h:339
void hist(const T *array, uint n, int *n_array, T *x_array, uint n_bins)
Definition: essentiamath.h:899
std::string equivalentKey(const std::string key)
Definition: essentiamath.h:1007
void sortpair(std::vector< T > &v1, std::vector< U > &v2)
Definition: essentiamath.h:847
T round(const T value)
Definition: essentiamath.h:538
Real db2amp(Real amplitude)
Definition: essentiamath.h:575
Eigen::TensorMap< Tensor< T >, 0 > TensorMap
Definition: types.h:390
Eigen::Tensor< Real, 1, Eigen::RowMajor > Tensor1D
Definition: types.h:400
std::vector< T > skewnessFrames(const std::vector< std::vector< T > > &frames)
Definition: essentiamath.h:307
Real hz2hz(Real hz)
Definition: essentiamath.h:737
void heavisideStepFunction(std::vector< std::vector< T > > &inputArray)
Definition: essentiamath.h:1178
T mean(const std::vector< T > &array, int start, int end)
Definition: essentiamath.h:142
std::vector< T > varianceFrames(const std::vector< std::vector< T > > &frames)
Definition: essentiamath.h:264
Real pow2db(Real power)
Definition: essentiamath.h:555
T pearsonCorrelationCoefficient(const std::vector< T > &x, const std::vector< T > &y)
Definition: essentiamath.h:1143
void tensorGeometricalInfo(const Tensor< T > &tensor, int &axis, std::array< Eigen::Index, 4 - 1 > &squeezeShape, std::array< Eigen::Index, 4 > &summarizerShape, std::array< Eigen::Index, 4 > &broadcastShape)
Definition: essentiamath.h:1222
T nextPowerTwo(T n)
Definition: essentiamath.h:64
T instantPower(const std::vector< T > &array)
Definition: essentiamath.h:409
TNT::Array2D< T > varianceMatrix(const std::vector< TNT::Array2D< T > > &array, const TNT::Array2D< T > &mean)
Definition: essentiamath.h:434
Real hz2melSlaney(Real hz)
Definition: essentiamath.h:721
T sum(const std::vector< T > &array, int start, int end)
Definition: essentiamath.h:116
std::vector< T > sumFrames(const std::vector< std::vector< T > > &frames)
Definition: essentiamath.h:290
void normalize(std::vector< T > &array)
Definition: essentiamath.h:759
T variance(const std::vector< T > &array, const T mean)
Definition: essentiamath.h:466
void rectify(std::vector< T > &array)
Definition: essentiamath.h:394
std::vector< T > derivative(const std::vector< T > &array)
Definition: essentiamath.h:821
T tensorMin(const Tensor< T > &tensor)
Definition: essentiamath.h:1313
T energy(const std::vector< T > &array)
Definition: essentiamath.h:401
T kurtosis(const std::vector< T > &array, const T mean)
Definition: essentiamath.h:505
T median(const std::vector< T > &array)
Definition: essentiamath.h:372
Real amp2db(Real amplitude)
Definition: essentiamath.h:567
Real linear(Real input)
Definition: essentiamath.h:579
std::vector< T > meanFrames(const std::vector< std::vector< T > > &frames, int beginIdx=0, int endIdx=-1)
Definition: essentiamath.h:199
int ilog10(T n)
Definition: essentiamath.h:54
Real lin2db(Real value)
Definition: essentiamath.h:543
Real hz2mel10(Real hz)
Definition: essentiamath.h:716
T princarg(T y)
Definition: essentiamath.h:881
T sumSquare(const std::vector< T > array)
Definition: essentiamath.h:105
std::vector< std::vector< T > > pairwiseDistance(const std::vector< std::vector< T > > &m, const std::vector< std::vector< T > > &n)
Definition: essentiamath.h:1198
TNT::Array2D< T > & matinit(TNT::Array2D< T > &A)
Definition: tnt2essentiautils.h:45
T stddev(const std::vector< T > &array, const T mean)
Definition: essentiamath.h:530
void normalizeAbs(std::vector< T > &array)
Definition: essentiamath.h:772
TNT::Array2D< T > meanMatrix(const std::vector< TNT::Array2D< T > * > &array)
Definition: essentiamath.h:167
Real db2lin(Real value)
Definition: essentiamath.h:551
std::vector< std::vector< T > > transpose(const std::vector< std::vector< T > > &m)
Definition: essentiamath.h:966
T norm(const std::vector< T > &array)
Definition: essentiamath.h:88
std::vector< T > medianFrames(const std::vector< std::vector< T > > &frames, int beginIdx=0, int endIdx=-1)
Definition: essentiamath.h:225
float Real
Definition: types.h:69
T roundToDecimal(T x, int decimal)
Definition: essentiamath.h:1357
Eigen::Tensor< Real, 0, Eigen::RowMajor > TensorScalar
Definition: types.h:395
Real bark2hz(Real z)
Definition: essentiamath.h:673
bool isPowerTwo(T n)
Definition: essentiamath.h:45
void normalizeSum(std::vector< T > &array)
Definition: essentiamath.h:801
T dotProduct(const std::vector< T > &xArray, const std::vector< T > &yArray)
Definition: essentiamath.h:1082
Eigen::Tensor< T, 4, Eigen::RowMajor > Tensor
Definition: types.h:384
bool isSilent(const std::vector< T > &array)
Definition: essentiamath.h:428
T skewness(const std::vector< T > &array, const T mean)
Definition: essentiamath.h:481
Real mel2hz(Real mel)
Definition: essentiamath.h:687
Real barkCriticalBandwidth(Real z)
Definition: essentiamath.h:682
Real mel2hzSlaney(Real mel)
Definition: essentiamath.h:696
void bincount(const std::vector< T > &input, std::vector< T > &output)
Definition: essentiamath.h:948
int argmax(const std::vector< Real > &input)
Definition: essentiamath.h:751
T fmod(T a, T b)
Definition: essentiamath.h:875
Real hz2bark(Real f)
Definition: essentiamath.h:656
Real db2pow(Real power)
Definition: essentiamath.h:563
bool isDenormal(const float &x)
Definition: essentiamath.h:864
T log2(T x)
Definition: essentiamath.h:49
T percentile(const std::vector< T > &array, Real qpercentile)
Definition: essentiamath.h:1093
int argmin(const std::vector< Real > &input)
Definition: essentiamath.h:745
T covariance(const std::vector< T > &x, const T xMean, const std::vector< T > &y, const T yMean)
Definition: essentiamath.h:1121
Real mel102hz(Real mel)
Definition: essentiamath.h:691
T tensorMax(const Tensor< T > &tensor)
Definition: essentiamath.h:1335
Real hz2mel(Real hz)
Definition: essentiamath.h:712
unsigned int uint
Definition: types.h:49
#define TENSORRANK
Definition: types.h:376