public final class Floats extends Object
float
or float[]
.
Here you find a wealth of functions that operate on arrays, like sum(float[])
, abs(float[])
,
reverse(float[])
, but also things like pNorm(float[], double)
or
pDistance(float[], float[], double)
.Modifier and Type | Method and Description |
---|---|
static float[] |
abs(float[] array)
Changes all values to their absolute values.
|
static float[] |
add(float[] a,
float[] b)
Adds the corresponding elements of two arrays.
|
static float |
arithmeticMean(float[] array)
Computes the arithmetic mean of the array.
|
static float |
arithmeticMean(float[] array,
int offset,
int length)
Computes the arithmetic mean of a portion of an array.
|
static float[] |
autoCorrelation(float[] samples)
Computes the values of the auto-correlation function with a min delay of
0 and a max delay of
samples.length/2 . |
static float[] |
autoCorrelation(float[] samples,
int minDelay,
int maxDelay)
Computes the values of the auto-correlation function.
|
static float[] |
autoCorrelation(float[] samples,
int minDelay,
int maxDelay,
float magnitudeCompression)
Computes the values of the auto-correlation function.
|
static float[] |
autoCorrelationNaive(float[] samples,
int minDelay,
int maxDelay)
Naive implementation of the auto-correlation function.
|
static double |
cityBlockDistance(float[] a,
float[] b)
Computes the city block distance (aka Manhattan distance) between two points, represented as arrays.
|
static double |
cityBlockDistance(float[] a,
float[] b,
boolean ignoreNegativeDiffs)
Computes the city block distance (a.k.a.
|
static double |
cityBlockNorm(float[] data)
Computes the city block norm (also known as 1-norm or Manhattan norm) for the given data.
|
static float[] |
convolve(float[] f,
float[] g)
Fully convolves two vectors.
|
static float[] |
convolveSame(float[] f,
float[] g)
Convolves two vectors and returns the central part of the convolution, which is
as long as the first vector.
|
static float[] |
convolveValid(float[] f,
float[] g)
Convolves two vectors and returns only those parts of the convolution that are computed without
zero-padding.
|
static float |
correctedStandardDeviation(float... data)
Corrected standard deviation using
unbiasedVariance(float...) . |
static float |
correlation(float[] a,
float[] b)
Computes the Pearson correlation coefficient between two vectors.
|
static double |
cosineDistance(float[] a,
float[] b)
Computes the cosine distance between two vectors.
|
static double |
cosineDistance(float[] a,
float[] b,
int offset,
int length)
Computes the cosine distance between two vectors.
|
static double |
cosineSimilarity(float[] a,
float[] b)
Computes the cosine similarity between two vectors.
|
static double |
cosineSimilarity(float[] a,
float[] b,
int offset,
int length)
Computes the cosine similarity between two vectors.
|
static double |
cosineSimilarity(float[] a,
float[] b,
int offset,
int length,
double euclideanNormA,
double euclideanNormB)
Computes the cosine similarity between two vectors, taking advantage of already known norms.
|
static float[] |
deltas(float[] data,
int n)
Compute deltas for a point
t that takes ±n points around t
into account. |
static double |
dotProduct(float[] a,
float[] b)
Computes the dot product.
|
static double |
dotProduct(float[] a,
float[] b,
int offset,
int length)
Computes the dot product.
|
static double |
euclideanDistance(float[] a,
float[] b)
Computes the Euclidean distance between two points, represented as arrays.
|
static double |
euclideanDistance(float[] a,
float[] b,
boolean ignoreNegativeDiffs)
Computes the Euclidean distance between two points, represented as arrays.
|
static double |
euclideanNorm(float[] data)
Computes the Euclidean norm (root sum of the squared data points, also known as 2-norm) for the given data.
|
static double |
euclideanNorm(float[] data,
int offset,
int length)
Computes the Euclidean norm (root sum of the squared data points, also known as 2-norm) for the given data
taking only a part of the vector into account (defined by offset and length).
|
static float |
geometricMean(float[] array)
Computes the geometric mean of the array.
|
static float |
geometricMean(float[] array,
int offset,
int length)
Computes the geometric mean of a portion of an array.
|
static float[] |
interpolate(float[] data,
float shift,
int indicesPerOneShift)
Linearly interpolates a given array by shifting its contents by the amount
shift . |
static float |
log2(float n)
Base 2 logarithm.
|
static float |
max(float[] array)
Calculates the maximum value of a given array.
|
static float |
max(float[] array,
int offset,
int length)
Calculates the maximum value of a given array.
|
static int |
maxIndex(float... array)
Calculates the index of the max value of a given array.
|
static int |
maxIndex(float[] array,
int offset,
int length)
Calculates the index of the max value of a given array.
|
static int[] |
maxIndices(float[] array)
Calculates the indices of the max values of a given array in descending value order.
|
static int[] |
maxIndices(float[] array,
int offset,
int length)
Calculates the indices of the max values of a given array in descending value order.
|
static float |
meanAbsoluteDeviation(float centralPoint,
float[] array)
Mean absolute deviation around a central point.
|
static float |
meanAbsoluteDeviation(float centralPoint,
float[] array,
int offset,
int length)
Mean absolute deviation around a central point.
|
static float |
median(float... array)
Median of the provided data.
|
static float |
median(float[] array,
int offset,
int length)
Median of the provided data.
|
static float |
min(float[] array)
Calculates the min value of a given array.
|
static float |
min(float[] array,
int offset,
int length)
Calculates the min value of a given array.
|
static int |
minIndex(float... array)
Calculates the index of the min value of a given array.
|
static int |
minIndex(float[] array,
int offset,
int length)
Calculates the index of the min value of a given array.
|
static void |
multiply(float[] array,
float factor)
Multiplies the given array with the given factor.
|
static double |
pDistance(float[] a,
float[] b,
double p)
p-Distance, that is the norm of the difference of each
a,b pair.. |
static int[] |
peaks(float[] array,
int interval,
boolean strict)
Calculates all peaks in the given array.
|
static float |
percentageBelowAverage(float[] array)
Percentage of array items below average.
|
static float[] |
phases(float[] r,
float[] i)
Measures the angle/phase between the real and the imaginary part in radians.
|
static double |
pNorm(float[] data,
double p)
p-Norm.
|
static float[] |
reverse(float[] array)
Reverses the order of the elements in an array in place, that is the original array is modified.
|
static float |
rootMeanSquare(float[] floats)
Computes the Root Mean Square (RMS) of one frame of data.
|
static float |
skewness(float... array)
|
static float |
skewness(float[] array,
int offset,
int length)
|
static float[] |
square(float[] array)
Changes all values to their square values.
|
static float |
standardDeviation(float... data)
Uncorrected sample standard deviation.
|
static float[] |
subtract(float[] a,
float[] b)
Subtracts the corresponding elements of two arrays.
|
static float[] |
sum(float[]... arrays)
Sums the corresponding values of all arrays in the array.
|
static float |
sum(float[] array)
Computes the sum over all array elements.
|
static float[] |
sum(List<float[]> arrays)
Sums the corresponding values of all arrays in the list.
|
static void |
swap(float[] array,
int a,
int b)
Swaps two elements.
|
static Float |
toFloat(float f)
Convert a given float primitive to a Float object.
|
static float |
unbiasedVariance(float... array)
Unbiased sample variance of the provided data using
Bessel's correction.
|
static float |
unbiasedVariance(float[] array,
int offset,
int length)
Unbiased sample variance of the provided data using
Bessel's correction.
|
static float |
variance(float... array)
Biased sample variance of the provided data without
Bessel's correction.
|
static float |
variance(float[] array,
int offset,
int length)
Biased sample variance of the provided data without
Bessel's correction.
|
static float[] |
wrap(float[] floats,
int length)
Wraps a given array of data into a smaller (or larger) array by adding all values with
an index distance of
length . |
static float |
zeroCrossingRate(float[] floats)
Computes the zero crossing rate for the given array.
|
static float[] |
zeroPadAtEnd(float[] array)
Zero-pads the given array at the end so that it has a length that is a power of two.
|
static float[] |
zeroPadAtEnd(int minSize,
float[] array)
Zero-pads the given array at the end so that it has a length that is a power of two.
|
public static float log2(float n)
n
- npublic static float[] reverse(float[] array)
array
- array to reversepublic static void swap(float[] array, int a, int b)
array
- arraya
- index of element ab
- index of element bpublic static float[] zeroPadAtEnd(int minSize, float[] array)
Transform.transform(float[])
.minSize
- minimum size of resulting arrayarray
- arraypublic static float[] zeroPadAtEnd(float[] array)
Transform.transform(float[])
.array
- arraypublic static float percentageBelowAverage(float[] array)
array
- datapublic static float[] subtract(float[] a, float[] b)
a
- arrayb
- arraypublic static float[] add(float[] a, float[] b)
a
- arrayb
- arraypublic static float sum(float[] array)
array
- datapublic static float[] sum(List<float[]> arrays)
arrays
- list of float arrayspublic static float[] sum(float[]... arrays)
arrays
- array of float arrayspublic static float arithmeticMean(float[] array, int offset, int length)
array
- arrayoffset
- first index (incl)length
- number of array elements to considerpublic static float arithmeticMean(float[] array)
array
- arraypublic static float geometricMean(float[] array, int offset, int length)
array
- arrayoffset
- offsetlength
- lengthpublic static float geometricMean(float[] array)
array
- arraypublic static float[] abs(float[] array)
array
- array of floatsMath.abs(float)
valuespublic static float[] square(float[] array)
array
- array of floatspublic static float min(float[] array, int offset, int length)
array
- float arrayoffset
- offset into the arraylength
- lengthpublic static float min(float[] array)
array
- float arraypublic static float max(float[] array, int offset, int length)
array
- float arrayoffset
- offset into the arraylength
- lengthpublic static float max(float[] array)
array
- float arraypublic static int minIndex(float[] array, int offset, int length)
array
- float arrayoffset
- offset into the arraylength
- lengthpublic static int maxIndex(float[] array, int offset, int length)
array
- float arrayoffset
- offset into the arraylength
- lengthpublic static int[] maxIndices(float[] array)
array
- float arraypublic static int[] maxIndices(float[] array, int offset, int length)
array
- float arrayoffset
- offset into the arraylength
- lengthpublic static Float toFloat(float f)
f
- float primitivepublic static void multiply(float[] array, float factor)
array
- arrayfactor
- factorpublic static double dotProduct(float[] a, float[] b)
a
- array ab
- array bpublic static double dotProduct(float[] a, float[] b, int offset, int length)
a
- array ab
- array boffset
- offset into both arrayslength
- lengthpublic static int[] peaks(float[] array, int interval, boolean strict)
interval
values to
its left that are strictly less than their direct neighbors to the right,
and at least interval
values to its right that
are strictly less than their direct neighbors to the left.array
- arrayinterval
- number of values to the left and the right that the function has to be
increasing or decreasingstrict
- if true, the shoulders of the peak must be strictly monotonically increasing or decreasingpublic static int minIndex(float... array)
array
- float arraypublic static int maxIndex(float... array)
array
- float arraypublic static float variance(float... array)
array
- datapublic static float unbiasedVariance(float... array)
array
- datapublic static float median(float... array)
array
- datapublic static float median(float[] array, int offset, int length)
array
- dataoffset
- offsetlength
- lengthpublic static float meanAbsoluteDeviation(float centralPoint, float[] array, int offset, int length)
centralPoint
- central pointarray
- dataoffset
- offsetlength
- lengthpublic static float meanAbsoluteDeviation(float centralPoint, float[] array)
centralPoint
- central pointarray
- datapublic static float variance(float[] array, int offset, int length)
array
- dataoffset
- offsetlength
- length)
public static float unbiasedVariance(float[] array, int offset, int length)
array
- dataoffset
- offsetlength
- lengthpublic static float standardDeviation(float... data)
data
- datacorrectedStandardDeviation(float...)
public static float correctedStandardDeviation(float... data)
unbiasedVariance(float...)
.data
- datapublic static float skewness(float[] array, int offset, int length)
array
- dataoffset
- offsetlength
- lengthpublic static float skewness(float... array)
array
- datapublic static float[] deltas(float[] data, int n)
t
that takes ±n
points around t
into account. This is suitable for computing
Delta MFCCs.
The array is padded with the first and last value respectively.data
- datan
- size of surroundingpublic static double euclideanNorm(float[] data)
data
- datapublic static double euclideanNorm(float[] data, int offset, int length)
data
- dataoffset
- offset into the data vectorlength
- length of the vector elements to considerpublic static double cityBlockNorm(float[] data)
data
- datapublic static double pNorm(float[] data, double p)
data
- real datap
- ppublic static double pDistance(float[] a, float[] b, double p)
a,b
pair..a
- real datab
- real datap
- ppNorm(float[], double)
,
Lp spacepublic static double euclideanDistance(float[] a, float[] b)
a
- point ab
- point bpublic static double euclideanDistance(float[] a, float[] b, boolean ignoreNegativeDiffs)
a
- point ab
- point bignoreNegativeDiffs
- ignores negative differences, i.e. take only increases into account. If true, the distance is not symmetric.public static double cityBlockDistance(float[] a, float[] b)
a
- point ab
- point bpublic static double cityBlockDistance(float[] a, float[] b, boolean ignoreNegativeDiffs)
a
- point ab
- point bignoreNegativeDiffs
- ignores negative differences, i.e. take only increases into account. If true, the distance is not symmetric.public static double cosineSimilarity(float[] a, float[] b)
a
- vector ab
- vector bcosineDistance(float[], float[])
public static double cosineSimilarity(float[] a, float[] b, int offset, int length)
a
- vector ab
- vector boffset
- offset into both arrayslength
- length of the array elements to comparecosineDistance(float[], float[])
public static double cosineSimilarity(float[] a, float[] b, int offset, int length, double euclideanNormA, double euclideanNormB)
a
- vector ab
- vector boffset
- offset into both arrayslength
- length of the array elements to compareeuclideanNormA
- euclidean norm for vector a (taking the offset and length into account)euclideanNormB
- euclidean norm for vector b (taking the offset and length into account)cosineDistance(float[], float[])
public static double cosineDistance(float[] a, float[] b)
a
- vector ab
- vector bcosineSimilarity(float[], float[])
public static double cosineDistance(float[] a, float[] b, int offset, int length)
a
- vector ab
- vector boffset
- offset into both arrayslength
- length of the array elements to comparecosineSimilarity(float[], float[])
public static float correlation(float[] a, float[] b)
a
- vector ab
- vector bpublic static float rootMeanSquare(float[] floats)
floats
- floatspublic static float zeroCrossingRate(float[] floats)
floats
- floatspublic static float[] wrap(float[] floats, int length)
length
.floats
- input datalength
- length of the resulting arraypublic static float[] autoCorrelationNaive(float[] samples, int minDelay, int maxDelay)
samples
- samplesminDelay
- min delay in samplesmaxDelay
- max delay in samplesautoCorrelationFFT(float[],int,int,float)
,
autoCorrelation(float[], int, int)
public static float[] convolve(float[] f, float[] g)
w(k) = sumOverJ( f(j) * g(k+1-j) )
Note that this is a naive implementation, not using FFT.f
- vectorg
- vectorpublic static float[] convolveSame(float[] f, float[] g)
f
- vectorg
- vectorpublic static float[] convolveValid(float[] f, float[] g)
f
- vectorg
- vectorpublic static float[] autoCorrelation(float[] samples)
0
and a max delay of
samples.length/2
.samples
- samplesautoCorrelation(float[], int, int, float)
public static float[] autoCorrelation(float[] samples, int minDelay, int maxDelay)
samples
- samplesminDelay
- min delay in samplesmaxDelay
- max delay in samples - note that this usually only makes sense up to
a value of samples.length/2
autoCorrelation(float[], int, int, float)
public static float[] autoCorrelation(float[] samples, int minDelay, int maxDelay, float magnitudeCompression)
samples
- samplesminDelay
- min delay in samplesmaxDelay
- max delay in samples - note that this usually only makes sense up to
a value of samples.length/2
magnitudeCompression
- if not 2f, instead of using the regular power (i.e. abs^2
),
use abs^k
; in other words, calculate the auto-correlation
r
like this r = IDFT(|DFT(x)|^k)
(where k
is the magnitudeCompression)suggested magnitude compression value see T.
Tolonen and M. Karjalainen, "A computationally efficient multipitch analysis model," IEEE Trans. Speech Audio Process.,
vol. 8, no. 6, pp. 708-716, Nov. 2000.
,
autoCorrelation(float[], int, int)
public static float[] interpolate(float[] data, float shift, int indicesPerOneShift)
shift
.data
- data to interpolateshift
- normalized shift amount, i.e. a value in [-1, - 1]
indicesPerOneShift
- indicates how may indices one full shift (+1 or -1) is equal to.public static float[] phases(float[] r, float[] i)
r
- real valuesi
- imaginary valuesCopyright © 2011–2020 tagtraum industries incorporated. All rights reserved.