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)
42 #define ALL_NOTES "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"
47 return (n & (n-1)) == 0;
50 template <
typename T> T
log2(T x) {
51 return log(x) / M_LN2;
56 if (n < 0)
return ilog10(-n);
89 template <
typename T> T
norm(
const std::vector<T>& array) {
96 for (
uint i=0; i<array.size(); i++) {
97 sum += array[i] * array[i];
106 template <
typename T> T
sumSquare(
const std::vector<T> array) {
108 for (
size_t i = 0; i < array.size(); ++i) {
109 sum += array[i] * array[i];
117 template <
typename T> T
sum(
const std::vector<T>& array,
int start,
int end) {
121 for (; i<end-8; i+=8) {
143 template <
typename T> T
mean(
const std::vector<T>& array,
int start,
int end) {
144 return sum(array, start, end) / (end - start);
150 template <
typename T> T
sum(
const std::vector<T>& array) {
151 if (array.empty())
return 0;
152 return sum(array, 0, array.size());
158 template <
typename T> T
mean(
const std::vector<T>& array) {
161 return mean(array, 0, array.size());
167 template <
typename T>
174 for (
int i = 0; i < (int)array.size(); i++) {
184 template <
typename T>
191 for (
int i = 0; i < (int)array.size(); i++) {
199 template <
typename T>
200 std::vector<T>
meanFrames(
const std::vector<std::vector<T> >& frames,
int beginIdx=0,
int endIdx=-1) {
201 if (frames.empty()) {
205 if (endIdx == -1) endIdx = (int)frames.size();
206 uint vsize = frames[0].size();
208 std::vector<T> result(vsize, (T)0.0);
209 typename std::vector<std::vector<T> >::const_iterator it = frames.begin() + beginIdx;
210 typename std::vector<std::vector<T> >::const_iterator end = frames.begin() + endIdx;
211 for (; it!=end; ++it) {
212 typename std::vector<T>::const_iterator itFrame = it->begin();
213 typename std::vector<T>::const_iterator endFrame = it->end();
214 typename std::vector<T>::iterator itResult = result.begin();
215 for (; itFrame != endFrame; ++itFrame, ++itResult) {
216 *itResult += *itFrame;
219 for (
uint j=0; j<vsize; j++) result[j] /= (endIdx - beginIdx);
225 template <
typename T>
226 std::vector<T>
medianFrames(
const std::vector<std::vector<T> >& frames,
int beginIdx=0,
int endIdx=-1) {
227 if (frames.empty()) {
231 if (endIdx == -1) endIdx = (int)frames.size();
233 uint vsize = frames[0].size();
234 uint fsize = endIdx - beginIdx;
236 std::vector<T> result(vsize, (T)0.0);
240 for (
uint i=0; i<vsize; ++i) {
241 typename std::vector<std::vector<T> >::const_iterator it = frames.begin() + beginIdx;
242 typename std::vector<std::vector<T> >::const_iterator end = frames.begin() + endIdx;
245 for (; it!=end; ++it) {
246 temp.push_back((*it)[i]);
248 std::sort(temp.begin(), temp.end());
251 if (fsize % 2 == 0.0) {
252 result[i] = (temp[
uint(fsize/2 - 1)] + temp[
uint(fsize/2)]) / 2;
256 result[i] = temp[
uint(fsize/2)];
264 template <
typename T>
266 if (frames.empty()) {
267 throw EssentiaException(
"trying to calculate variance of empty array of frames");
270 uint nframes = frames.size();
271 uint vsize = frames[0].size();
275 std::vector<T> result(vsize, (T)0.0);
277 for (
uint i=0; i<nframes; i++) {
278 for (
uint j=0; j<vsize; j++) {
279 diff = frames[i][j] - m[j];
280 result[j] += diff*diff;
283 for (
uint j=0; j<vsize; j++) result[j] /= nframes;
290 template <
typename T>
291 std::vector<T>
sumFrames(
const std::vector<std::vector<T> >& frames) {
292 if (frames.empty()) {
293 throw EssentiaException(
"sumFrames: trying to calculate sum of empty input frames");
295 size_t nframes = frames.size();
296 size_t vsize = frames[0].size();
297 std::vector<T> result(vsize, (T)0);
298 for (
size_t j=0; j<vsize; j++) {
299 for (
size_t i=0; i<nframes; i++) {
300 result[j] += frames[i][j];
307 template <
typename T>
309 if (frames.empty()) {
310 throw EssentiaException(
"trying to calculate skewness of empty array of frames");
313 uint nframes = frames.size();
314 uint vsize = frames[0].size();
318 std::vector<T> result(vsize, (T)0.0);
319 std::vector<T> m3(vsize, (T)0.0);
320 std::vector<T> m2(vsize, (T)0.0);
322 for (
uint i=0; i<nframes; i++) {
323 for (
uint j=0; j<vsize; j++) {
324 diff = frames[i][j] - m[j];
326 m3[j] += diff*diff*diff;
329 for (
uint j=0; j<vsize; j++) {
332 if (m2[j] == (T)0.) result[j] = (T)0.;
333 else result[j] = m3[j] / pow(m2[j], (T)1.5);
339 template <
typename T>
341 if (frames.empty()) {
342 throw EssentiaException(
"trying to calculate kurtosis of empty array of frames");
345 uint nframes = frames.size();
346 uint vsize = frames[0].size();
350 std::vector<T> result(vsize, (T)0.0);
351 std::vector<T> m2(vsize, (T)0.0);
352 std::vector<T> m4(vsize, (T)0.0);
354 for (
uint i=0; i<nframes; i++) {
355 for (
uint j=0; j<vsize; j++) {
356 diff = frames[i][j] - m[j];
358 m4[j] += diff*diff*diff*diff;
361 for (
uint j=0; j<vsize; j++) {
364 if (m2[j] == (T)0.) result[j] = (T)(-3.);
365 else result[j] = m4[j] / (m2[j]*m2[j]) - 3;
373 template <
typename T> T
median(
const std::vector<T>& array) {
378 std::vector<T> sorted_array = array;
379 std::sort(sorted_array.begin(), sorted_array.end());
381 uint size = sorted_array.size();
384 if (size % 2 == 0.0) {
385 return (sorted_array[
uint(size/2 - 1)] + sorted_array[
uint(size/2)]) / 2;
389 return sorted_array[
uint(size/2)];
394 template <
typename T>
396 for (
int i=0; i<(int)array.size(); i++) {
397 array[i] = fabs(array[i]);
402 template <
typename T> T
energy(
const std::vector<T>& array) {
406 return inner_product(array.begin(), array.end(), array.begin(), (T)0.0);
411 return energy(array) / array.size();
424 #define SILENCE_CUTOFF 1e-10
425 #define DB_SILENCE_CUTOFF -100
426 #define LOG_SILENCE_CUTOFF -23.025850929940457
429 template <
typename T>
bool isSilent(
const std::vector<T>& array) {
434 template <
typename T>
442 for (
int i=0; i<(int)array.size(); i++) {
450 template <
typename T>
458 for (
int i=0; i<(int)array.size(); i++) {
467 template <
typename T> T
variance(
const std::vector<T>& array,
const T
mean) {
473 for (
uint i=0; i<array.size(); i++) {
474 T temp = array[i] -
mean;
482 template <
typename T> T
skewness(
const std::vector<T>& array,
const T
mean) {
486 const int n = (int)array.size();
487 T m2 = (T)0.0, m3 = (T)0.0;
489 for (
int i=0; i<n; i++) {
490 T temp = array[i] -
mean;
492 m3 += temp * temp * temp;
499 if (m2 == (T)0.) result = (T)0.;
500 else result = m3 / pow(m2, (T)1.5);
506 template <
typename T> T
kurtosis(
const std::vector<T>& array,
const T
mean) {
510 const int n = (int)array.size();
511 T m2 = (T)0.0, m4 = (T)0.0;
513 for (
int i=0; i<n; i++) {
514 T temp = array[i] -
mean;
516 m4 += temp * temp * temp * temp;
523 if (m2 == (T)0.) result = (T)(-3.);
524 else result = m4 / (m2*m2) - 3;
531 template <
typename T> T
stddev(
const std::vector<T>& array,
const T
mean) {
539 template <
typename T> T
round(
const T value) {
540 return (T)std::floor(value + (T)0.5);
549 return value < silenceCutoff ? dbSilenceCutoff : (
Real)10.0 * log10(value);
553 return pow((
Real)10.0, value/(
Real)10.0);
561 return lin2db(power, silenceCutoff, dbSilenceCutoff);
573 return Real(2.0)*
lin2db(amplitude, silenceCutoff, dbSilenceCutoff);
577 return db2lin(0.5*amplitude);
589 return input < silenceCutoff ? logSilenceCutoff : log(input);
600 inline T asinh(
const T x)
605 using ::std::numeric_limits;
607 T
const one =
static_cast<T
>(1);
608 T
const two =
static_cast<T
>(2);
610 static T
const taylor_2_bound = sqrt(numeric_limits<T>::epsilon());
611 static T
const taylor_n_bound = sqrt(taylor_2_bound);
612 static T
const upper_taylor_2_bound = one/taylor_2_bound;
613 static T
const upper_taylor_n_bound = one/taylor_n_bound;
615 if (x >= +taylor_n_bound) {
616 if (x > upper_taylor_n_bound) {
617 if (x > upper_taylor_2_bound) {
619 return( log( x * two) );
623 return( log( x*two + (one/(x*two)) ) );
627 return( log( x + sqrt(x*x+one) ) );
630 else if (x <= -taylor_n_bound) {
637 if (abs(x) >= taylor_2_bound)
642 result -= x3/
static_cast<T
>(6);
658 Real b = ((26.81*f)/(1960 + f)) - 0.53;
660 if (b < 2) b += 0.15*(2-b);
661 if (b > 20.1) b += 0.22*(b - 20.1);
676 if (z < 2) z = (z - 0.3) / 0.85;
677 if (z > 20.1) z = (z - 4.422) / 1.22;
680 return 1960.0 * (z + 0.53) / (26.28 - z);
684 return 52548.0 / (z*z - 52.56 * z + 690.39);
689 return 700.0 * (exp(mel/1127.01048) - 1.0);
693 return 700.0 * (pow(10.0, mel/2595.0) - 1.0);
698 const Real minLogHz = 1000.0;
699 const Real linSlope = 3 / 200.;
700 const Real minLogMel = minLogHz * linSlope;
702 if (mel < minLogMel) {
704 return mel / linSlope;
708 const Real logStep = log(6.4) / 27.0;
709 return minLogHz * exp((mel - minLogMel) * logStep);
714 return 1127.01048 * log(hz/700.0 + 1.0);
718 return 2595.0 * log10(hz/700.0 + 1.0);
723 const Real minLogHz = 1000.0;
724 const Real linSlope = 3 / 200.;
728 return hz * linSlope;
732 const Real minLogMel = minLogHz * linSlope;
733 const Real logStep = log(6.4) / 27.0;
734 return minLogMel + log(hz/minLogHz) / logStep;
743 return referenceFrequency * powf(2.0, cents / 1200.0);
747 return 1200 *
log2(hz / referenceFrequency);
751 return 69 + (int)
round(
log2(hz / tuningFrequency) * 12);
755 return tuningFrequency * powf(2, (midiNoteNumber - 69) / 12.0);
759 return note.substr(0, note.size()-1);
763 char octaveChar = note.back();
764 return octaveChar -
'0';
770 int nNotes = *(&NOTES + 1) - NOTES;
772 int diffCIdx = nNotes - CIdx;
773 int noteIdx = midiNoteNumber - 69;
774 int idx = abs(noteIdx) % nNotes;
775 int octave = (CIdx + 1) + floor((noteIdx + diffCIdx) / nNotes);
777 idx = abs(idx - nNotes) % nNotes;
779 std::string closest_note = NOTES[idx] + std::to_string(octave);
788 int nNotes = *(&NOTES + 1) - NOTES;
792 int noteIdx = floor((octave - (CIdx + 1)) * nNotes);
794 for (
int i = 0; i < nNotes; i++) {
795 if (NOTES[i] == root) {
803 int midiNote = noteIdx + 69 + idx;
808 int midiNoteNumber =
hz2midi(hz, tuningFrequency);
814 return midi2hz(midiNoteNumber, tuningFrequency);
819 if (decibels > hearingThreshold) {
820 velocity = (int)((hearingThreshold - decibels) * 127 / hearingThreshold);
826 return -(hearingThreshold * velocity / 127 -hearingThreshold);
829 inline int argmin(
const std::vector<Real>& input) {
832 return std::min_element(input.begin(), input.end()) - input.begin();
835 inline int argmax(
const std::vector<Real>& input) {
838 return std::max_element(input.begin(), input.end()) - input.begin();
843 template <
typename T>
void normalize(std::vector<T>& array) {
844 if (array.empty())
return;
846 T maxElement = *std::max_element(array.begin(), array.end());
848 if (maxElement != (T) 0.0) {
849 for (
uint i=0; i<array.size(); i++) {
850 array[i] /= maxElement;
857 if (array.empty())
return;
858 std::vector<T> absArray = array;
860 T maxElement = *std::max_element(absArray.begin(), absArray.end());
862 if (maxElement != (T) 0.0) {
863 for (
uint i=0; i<array.size(); i++) {
864 array[i] /= maxElement;
870 template <
typename T>
void normalizeAbs(std::vector<T>& array, T headroom) {
871 if (array.empty())
return;
872 std::vector<T> absArray = array;
874 T maxElement = *std::max_element(absArray.begin(), absArray.end());
876 if (maxElement != (T) 0.0) {
877 for (
uint i=0; i<array.size(); i++) {
878 array[i] /= (maxElement + headroom);
886 if (array.empty())
return;
889 T sumElements = (T) 0.;
890 for (
size_t i=0; i<array.size(); ++i) {
891 if (array[i] < 0)
return;
892 sumElements += array[i];
895 if (sumElements != (T) 0.0) {
896 for (
size_t i=0; i<array.size(); ++i) {
897 array[i] /= sumElements;
904 template <
typename T>
906 if (array.size() < 2) {
907 throw EssentiaException(
"trying to calculate approximate derivative of empty or single-element array");
910 std::vector<T> result(array.size()-1, (T)0.0);
911 for (
int i=0; i<(int)result.size(); i++) {
912 result[i] = array[i+1] - array[i];
917 template<
typename T,
typename U,
typename Comparator=std::greater<T> >
921 bool operator () (
const std::pair<T,U>& p1,
const std::pair<T,U>& p2)
const {
922 if (
_cmp(p1.first, p2.first))
return true;
923 if (
_cmp(p2.first, p1.first))
return false;
924 return _cmp(p1.second, p2.second);
930 template <
typename T,
typename U,
typename Comparator>
931 void sortpair(std::vector<T>& v1, std::vector<U>& v2) {
932 if (v1.size() != v2.size()) {
935 int size = v1.size();
936 std::vector<std::pair<T, U> > tmp(size);
937 for (
int i=0; i<size; i++)
938 tmp[i] = std::make_pair(v1[i], v2[i]);
940 for (
int i=0; i<size; i++) {
941 v1[i] = tmp[i].first;
942 v2[i] = tmp[i].second;
949 return std::fpclassify(x) == FP_SUBNORMAL;
959 template <
typename T> T
fmod(T a, T b) {
982 template <
typename T>
983 void hist(
const T* array,
uint n,
int* n_array, T* x_array,
uint n_bins) {
984 T miny = *std::min_element(array, array+n);
985 T maxy = *std::max_element(array, array+n);
988 for (
uint i=0; i<n_bins; i++) {
989 x_array[i] = (0.5 + i)*(maxy - miny)/n_bins + miny;
993 std::vector<T> cutoff(n_bins - 1);
994 for (
uint i=0; i<n_bins-1; i++) {
995 cutoff[i] = (x_array[i] + x_array[i+1]) / 2.0;
1005 std::vector<T> dist(array, array+n);
1006 std::sort(dist.begin(), dist.end());
1007 uint current_cutoff_idx = 0;
1008 T current_cutoff = cutoff[0];
1009 for (
uint i=0; i<n_bins; i++) n_array[i] = 0;
1011 for (
uint i=0; i<n; i++) {
1012 while (dist[i] > current_cutoff) {
1014 if (current_cutoff_idx == n_bins-2) {
1015 n_array[n_bins-1] = n-i;
1017 n_array[n_bins-2]--;
1020 current_cutoff_idx++;
1021 current_cutoff = cutoff[current_cutoff_idx];
1023 n_array[current_cutoff_idx]++;
1031 template <
typename T>
1032 void bincount(
const std::vector<T>& input, std::vector<T>& output) {
1034 output.resize( (
int) ( std::max<Real>( input[
argmax(input)], 0.) + 0.5 ) + 1);
1036 for (
uint i=0; i< input.size(); i++) {
1037 index = int(std::max<Real>(input[i],0) + 0.5);
1038 if (index < output.size() ) {
1039 output[index] += 1.;
1049 template <
typename T>
1050 std::vector<std::vector<T> >
transpose(
const std::vector<std::vector<T> >& m) {
1051 if (m.empty())
return std::vector<std::vector<T> >();
1053 int nrows = m.size();
1054 int ncols = m[0].size();
1055 for (
int i=1; i<nrows; i++) {
1056 if ((
int)m[i].size() != ncols) {
1057 std::ostringstream ss;
1058 ss <<
"Trying to transpose a non rectangular matrix. Expecting dim2 = " << ncols
1059 <<
" but got " << m[i].size() <<
". Cannot transpose!";
1064 std::vector<std::vector<T> > result(ncols, std::vector<Real>(nrows));
1065 for (
int i=0; i<nrows; i++) {
1066 for (
int j=0; j<ncols; j++) {
1067 result[j][i] = m[i][j];
1074 template <
typename T>
1078 int nrows = m.
dim1();
1079 int ncols = m.
dim2();
1082 for (
int i=0; i<nrows; i++) {
1083 for (
int j=0; j<ncols; j++) {
1084 result[j][i] = m[i][j];
1151 template <
typename T>
1153 if (inputMatrix.empty())
1155 for (
size_t i=0; i<inputMatrix.size(); i++) {
1156 std::rotate(inputMatrix[i].begin(), inputMatrix[i].end() - oti, inputMatrix[i].end());
1165 template <
typename T>
1166 T
dotProduct(
const std::vector<T>& xArray,
const std::vector<T>& yArray) {
1167 if (xArray.empty() || yArray.empty())
1168 throw EssentiaException(
"dotProduct: trying to calculate the dotProduct of empty arrays!");
1169 return std::inner_product(xArray.begin(), xArray.end(), yArray.begin(), 0.0);
1179 throw EssentiaException(
"percentile: trying to calculate percentile of empty array");
1181 std::vector<T> sorted_array = array;
1183 std::sort(sorted_array.begin(), sorted_array.end());
1184 qpercentile /= 100.;
1187 int sortArraySize = sorted_array.size();
1188 if (sortArraySize > 1) {
1189 k = (sortArraySize - 1) * qpercentile;
1193 k = sortArraySize * qpercentile;
1196 Real d0 = sorted_array[int(std::floor(k))] * (std::ceil(k) - k);
1197 Real d1 = sorted_array[int(std::ceil(k))] * (k - std::floor(k));
1205 template <
typename T> T
covariance(
const std::vector<T>& x,
const T xMean,
const std::vector<T>& y,
const T yMean) {
1210 if (x.size() != y.size())
1215 for (
uint i=0; i<x.size(); i++) {
1216 cov += (x[i] - xMean) * (y[i] - yMean);
1219 return (T)(cov / (
Real)x.size());
1232 if (x.size() != y.size())
1240 T xStddev =
stddev(x, xMean);
1241 T yStddev =
stddev(y, yMean);
1244 if ((xStddev == (T)0.0) || (xStddev == (T)0.0) || (xStddev == (T)0.0))
return (T) 0.0;
1246 T corr = cov / (xStddev * yStddev);
1251 return std::max(std::min(corr, (T)1.0), (T)-1.0);
1261 template <
typename T>
1263 if (inputArray.empty())
1266 for (
size_t i=0; i<inputArray.size(); i++) {
1267 for (
size_t j=0; j<inputArray[i].size(); j++) {
1269 inputArray[i][j] = (inputArray[i][j] < 0) ? 0 : 1;
1281 template <
typename T>
1282 std::vector<std::vector<T> >
pairwiseDistance(
const std::vector<std::vector<T> >& m,
const std::vector<std::vector<T> >& n) {
1284 if (m.empty() || n.empty())
1287 size_t mSize = m.size();
1288 size_t nSize = n.size();
1289 std::vector<std::vector<T> > pdist(mSize, std::vector<T>(nSize));
1290 for (
size_t i=0; i<mSize; i++) {
1291 for (
size_t j=0; j<nSize; j++) {
1293 pdist[i][j] = sqrt(item);
1297 throw EssentiaException(
"pairwiseDistance: outputs an empty similarity matrix!");
1305 template <
typename T>
1307 std::array<Eigen::Index, TENSORRANK - 1>& squeezeShape,
1308 std::array<Eigen::Index, TENSORRANK>& summarizerShape,
1309 std::array<Eigen::Index, TENSORRANK>& broadcastShape) {
1317 squeezeShape[i] = j;
1323 summarizerShape = {1, 1, 1, 1};
1324 summarizerShape[axis] = tensor.dimension(axis);
1328 broadcastShape = tensor.dimensions();
1329 broadcastShape[axis] = 1;
1335 template <
typename T>
1343 template <
typename T>
1345 std::array<Eigen::Index,
TENSORRANK - 1> squeezeShape;
1346 std::array<Eigen::Index, TENSORRANK> summarizerShape, broadcastShape;
1349 Tensor1D means = tensor.mean(squeezeShape);
1357 template <
typename T>
1364 return sqrt(sos / tensor.size());
1370 template <
typename T>
1372 std::array<Eigen::Index,
TENSORRANK - 1> squeezeShape;
1373 std::array<Eigen::Index, TENSORRANK> summarizerShape, broadcastShape;
1378 Real normalization = tensor.size() / tensor.dimension(axis);
1385 Tensor1D sos = tmp.pow(2).sum(squeezeShape);
1388 Tensor1D stds = (sos / normalization).sqrt();
1396 template <
typename T>
1404 template <
typename T>
1406 std::array<Eigen::Index,
TENSORRANK - 1> squeezeShape;
1407 std::array<Eigen::Index, TENSORRANK> summarizerShape, broadcastShape;
1410 Tensor1D minima = tensor.minimum(squeezeShape);
1418 template <
typename T>
1426 template <
typename T>
1428 std::array<Eigen::Index,
TENSORRANK - 1> squeezeShape;
1429 std::array<Eigen::Index, TENSORRANK> summarizerShape, broadcastShape;
1432 Tensor1D maxima = tensor.maximum(squeezeShape);
1440 template <
typename T>
1445 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:918
bool operator()(const std::pair< T, U > &p1, const std::pair< T, U > &p2) const
Definition: essentiamath.h:921
Comparator _cmp
Definition: essentiamath.h:919
#define M_2PI
Definition: essentiamath.h:41
#define SILENCE_CUTOFF
Definition: essentiamath.h:424
#define ALL_NOTES
Definition: essentiamath.h:42
#define DB_SILENCE_CUTOFF
Definition: essentiamath.h:425
#define LOG_SILENCE_CUTOFF
Definition: essentiamath.h:426
Definition: algorithm.h:28
Real lin2log(Real value)
Definition: essentiamath.h:584
void rotateChroma(std::vector< std::vector< T > > &inputMatrix, int oti)
Definition: essentiamath.h:1152
std::vector< T > kurtosisFrames(const std::vector< std::vector< T > > &frames)
Definition: essentiamath.h:340
void hist(const T *array, uint n, int *n_array, T *x_array, uint n_bins)
Definition: essentiamath.h:983
std::string equivalentKey(const std::string key)
Definition: essentiamath.h:1091
void sortpair(std::vector< T > &v1, std::vector< U > &v2)
Definition: essentiamath.h:931
T round(const T value)
Definition: essentiamath.h:539
int hz2midi(Real hz, Real tuningFrequency)
Definition: essentiamath.h:750
std::string hz2note(Real hz, Real tuningFrequency)
Definition: essentiamath.h:807
Real db2amp(Real amplitude)
Definition: essentiamath.h:576
Eigen::TensorMap< Tensor< T >, 0 > TensorMap
Definition: types.h:390
Eigen::Tensor< Real, 1, Eigen::RowMajor > Tensor1D
Definition: types.h:400
int db2velocity(Real decibels, Real hearingThreshold)
Definition: essentiamath.h:817
std::vector< T > skewnessFrames(const std::vector< std::vector< T > > &frames)
Definition: essentiamath.h:308
Real hz2hz(Real hz)
Definition: essentiamath.h:738
void heavisideStepFunction(std::vector< std::vector< T > > &inputArray)
Definition: essentiamath.h:1262
T mean(const std::vector< T > &array, int start, int end)
Definition: essentiamath.h:143
std::vector< T > varianceFrames(const std::vector< std::vector< T > > &frames)
Definition: essentiamath.h:265
Real pow2db(Real power)
Definition: essentiamath.h:556
T pearsonCorrelationCoefficient(const std::vector< T > &x, const std::vector< T > &y)
Definition: essentiamath.h:1227
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:1306
T nextPowerTwo(T n)
Definition: essentiamath.h:65
T instantPower(const std::vector< T > &array)
Definition: essentiamath.h:410
TNT::Array2D< T > varianceMatrix(const std::vector< TNT::Array2D< T > > &array, const TNT::Array2D< T > &mean)
Definition: essentiamath.h:435
Real hz2melSlaney(Real hz)
Definition: essentiamath.h:722
T sum(const std::vector< T > &array, int start, int end)
Definition: essentiamath.h:117
std::vector< T > sumFrames(const std::vector< std::vector< T > > &frames)
Definition: essentiamath.h:291
std::string midi2note(int midiNoteNumber)
Definition: essentiamath.h:767
void normalize(std::vector< T > &array)
Definition: essentiamath.h:843
T variance(const std::vector< T > &array, const T mean)
Definition: essentiamath.h:467
void rectify(std::vector< T > &array)
Definition: essentiamath.h:395
std::vector< T > derivative(const std::vector< T > &array)
Definition: essentiamath.h:905
T tensorMin(const Tensor< T > &tensor)
Definition: essentiamath.h:1397
T energy(const std::vector< T > &array)
Definition: essentiamath.h:402
Real midi2hz(int midiNoteNumber, Real tuningFrequency)
Definition: essentiamath.h:754
Real velocity2db(int velocity, Real hearingThreshold)
Definition: essentiamath.h:825
T kurtosis(const std::vector< T > &array, const T mean)
Definition: essentiamath.h:506
T median(const std::vector< T > &array)
Definition: essentiamath.h:373
Real amp2db(Real amplitude)
Definition: essentiamath.h:568
Real linear(Real input)
Definition: essentiamath.h:580
std::vector< T > meanFrames(const std::vector< std::vector< T > > &frames, int beginIdx=0, int endIdx=-1)
Definition: essentiamath.h:200
int ilog10(T n)
Definition: essentiamath.h:55
Real hz2cents(Real hz, Real referenceFrequency)
Definition: essentiamath.h:746
Real lin2db(Real value)
Definition: essentiamath.h:544
Real hz2mel10(Real hz)
Definition: essentiamath.h:717
T princarg(T y)
Definition: essentiamath.h:965
T sumSquare(const std::vector< T > array)
Definition: essentiamath.h:106
std::vector< std::vector< T > > pairwiseDistance(const std::vector< std::vector< T > > &m, const std::vector< std::vector< T > > &n)
Definition: essentiamath.h:1282
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:531
void normalizeAbs(std::vector< T > &array)
Definition: essentiamath.h:856
TNT::Array2D< T > meanMatrix(const std::vector< TNT::Array2D< T > * > &array)
Definition: essentiamath.h:168
Real db2lin(Real value)
Definition: essentiamath.h:552
std::vector< std::vector< T > > transpose(const std::vector< std::vector< T > > &m)
Definition: essentiamath.h:1050
Real cents2hz(Real cents, Real referenceFrequency)
Definition: essentiamath.h:742
T norm(const std::vector< T > &array)
Definition: essentiamath.h:89
int note2hz(std::string note, Real tuningFrequency)
Definition: essentiamath.h:812
std::vector< T > medianFrames(const std::vector< std::vector< T > > &frames, int beginIdx=0, int endIdx=-1)
Definition: essentiamath.h:226
float Real
Definition: types.h:69
T roundToDecimal(T x, int decimal)
Definition: essentiamath.h:1441
Eigen::Tensor< Real, 0, Eigen::RowMajor > TensorScalar
Definition: types.h:395
Real bark2hz(Real z)
Definition: essentiamath.h:674
bool isPowerTwo(T n)
Definition: essentiamath.h:46
void normalizeSum(std::vector< T > &array)
Definition: essentiamath.h:885
T dotProduct(const std::vector< T > &xArray, const std::vector< T > &yArray)
Definition: essentiamath.h:1166
Eigen::Tensor< T, 4, Eigen::RowMajor > Tensor
Definition: types.h:384
bool isSilent(const std::vector< T > &array)
Definition: essentiamath.h:429
T skewness(const std::vector< T > &array, const T mean)
Definition: essentiamath.h:482
Real mel2hz(Real mel)
Definition: essentiamath.h:688
Real barkCriticalBandwidth(Real z)
Definition: essentiamath.h:683
Real mel2hzSlaney(Real mel)
Definition: essentiamath.h:697
void bincount(const std::vector< T > &input, std::vector< T > &output)
Definition: essentiamath.h:1032
int argmax(const std::vector< Real > &input)
Definition: essentiamath.h:835
T fmod(T a, T b)
Definition: essentiamath.h:959
int note2octave(std::string note)
Definition: essentiamath.h:762
Real hz2bark(Real f)
Definition: essentiamath.h:657
Real db2pow(Real power)
Definition: essentiamath.h:564
bool isDenormal(const float &x)
Definition: essentiamath.h:948
std::string note2root(std::string note)
Definition: essentiamath.h:758
int note2midi(std::string note)
Definition: essentiamath.h:783
T log2(T x)
Definition: essentiamath.h:50
T percentile(const std::vector< T > &array, Real qpercentile)
Definition: essentiamath.h:1177
int argmin(const std::vector< Real > &input)
Definition: essentiamath.h:829
T covariance(const std::vector< T > &x, const T xMean, const std::vector< T > &y, const T yMean)
Definition: essentiamath.h:1205
Real mel102hz(Real mel)
Definition: essentiamath.h:692
T tensorMax(const Tensor< T > &tensor)
Definition: essentiamath.h:1419
Real hz2mel(Real hz)
Definition: essentiamath.h:713
unsigned int uint
Definition: types.h:49
#define TENSORRANK
Definition: types.h:376