marytts.util.math

## Class Polynomial

• ```public class Polynomial
extends Object```
Author:
marc
• ### Field Summary

Fields
Modifier and Type Field and Description
`double[]` `coeffs`
• ### Constructor Summary

Constructors
Constructor and Description
`Polynomial(double[] coeffs)`
Create a new polynomial with the given coefficients.
`Polynomial(int order)`
Create a new polynomial of the requested order with all coefficients set to 0.
• ### Method Summary

Methods
Modifier and Type Method and Description
`void` `copyCoeffs(Polynomial other)`
`static double[]` ```fitPolynomial(double[] data, int order)```
Fit a polynomial of the given order to the given data.
`static double[]` ```generatePolynomialValues(double[] coeffs, int numSamples, double a, double b)```
For a polynomial with the given coefficients, compute `numSamples` values, equally spaced in the interval [a, b[.
`double[]` ```generatePolynomialValues(int numSamples, double a, double b)```
For a polynomial with the given coefficients, compute `numSamples` values, equally spaced in the interval [a, b[.
`int` `getOrder()`
`double` `getValueAt(double x)`
For a polynomial with the given coefficients, compute the value at the given position.
`static double` ```getValueAt(double[] coeffs, double x)```
For a polynomial with the given coefficients, compute the value at the given position.
`static double[]` `mean(double[][] p)`
Compute the mean polynomial from the given polynomials, by building a polynomial of the averaged coefficients.
`static float[]` `mean(float[][] p)`
Compute the mean polynomial from the given polynomials, by building a polynomial of the averaged coefficients.
`static Polynomial` `mean(Polynomial[] p)`
Compute the mean polynomial from the given polynomials, by building a polynomial of the averaged coefficients.
`static double` ```polynomialDistance(double[] coeffs1, double[] coeffs2)```
Compute the integrated distance between two polynomials of same order.
`static double` ```polynomialDistance(float[] coeffs1, float[] coeffs2)```
Compute the integrated distance between two polynomials of same order.
`double` `polynomialDistance(Polynomial other)`
Compute the integrated distance between two polynomials of same order.
`static double` ```polynomialPearsonProductMomentCorr(double[] coeffs1, double[] coeffs2)```
Compute one minus the Pearson product moment correlation between two polynomials of same order.
`static double` ```polynomialSquaredDistance(double[] coeffs1, double[] coeffs2)```
Compute the integral of the squared difference between two polynomials of same order.
`static double` ```polynomialSquaredDistance(float[] coeffs1, float[] coeffs2)```
Compute the integral of the squared difference between two polynomials of same order.
`double` `polynomialSquaredDistance(Polynomial other)`
Compute the integral of the squared difference between two polynomials of same order.
`static double` ```variance(double[][] p, double[] mean)```
For the given collection of polynomials, for which a mean polynomial has already been computed using `mean(double[][])`, compute a variance as follows.
`static double` ```variance(float[][] p, float[] mean)```
For the given collection of polynomials, for which a mean polynomial has already been computed using `mean(float[][])`, compute a variance as follows.
`static double` ```variance(Polynomial[] p, Polynomial mean)```
For the given collection of polynomials, for which a mean polynomial has already been computed using `mean(Polynomial[])`, compute a variance as follows.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### coeffs

`public final double[] coeffs`
• ### Constructor Detail

• #### Polynomial

`public Polynomial(int order)`
Create a new polynomial of the requested order with all coefficients set to 0.
Parameters:
`order` - the polynomial order.
• #### Polynomial

`public Polynomial(double[] coeffs)`
Create a new polynomial with the given coefficients.
Parameters:
`coeffs` - the polynomial coefficients. The code assumes that the polynomial is `a_order t^order + a_(order-1) t^(order-1) + ... + a_1 t + a_0`, and will interpret coeffs as `a_order, a_(order-1), ..., a_1, a_0`, where `order` is `coeffs.length-1`.
• ### Method Detail

• #### getOrder

`public int getOrder()`
• #### copyCoeffs

`public void copyCoeffs(Polynomial other)`
• #### generatePolynomialValues

```public double[] generatePolynomialValues(int numSamples,
double a,
double b)```
For a polynomial with the given coefficients, compute `numSamples` values, equally spaced in the interval [a, b[.
Parameters:
`numSamples` - num samples
`a` - lower bound (inclusive)
`b` - upper bound (exclusive)
Returns:
the predicted samples.
Throws:
`NullPointerException` - if coeffs is null
`IllegalArgumentException` - if coeffs has length 0
`IllegalArgumentException` - if numSamples is ≤ 0
`IllegalArgumentException` - if a is not less than b.
• #### getValueAt

`public double getValueAt(double x)`
For a polynomial with the given coefficients, compute the value at the given position.
Parameters:
`x` - the position where to compute the value
Returns:
the predicted value
Throws:
`NullPointerException` - if coeffs is null
`IllegalArgumentException` - if coeffs has length 0
• #### polynomialDistance

`public double polynomialDistance(Polynomial other)`
Compute the integrated distance between two polynomials of same order. More precisely, this will return the absolute value of the integral from 0 to 1 of the difference between the two functions.
Parameters:
`other` - polynomial with the same order as this polynomial.
Returns:
polynomialDistance(self.coeffs, other.coeffs)
• #### polynomialSquaredDistance

`public double polynomialSquaredDistance(Polynomial other)`
Compute the integral of the squared difference between two polynomials of same order. More precisely, this will return the the integral from 0 to 1 of the square of the difference between the two functions.

This implements the algebraic solution proposed by Maxima from the following command: `expand(integrate((sum(a[i]*x**i, i, 0, order))**2, x, 0, 1));`, with order varied from 0 to 4. Increasing order by 1 adds (order+1) summands.

Parameters:
`other` - polynomial with the same order as this polynomial.
Returns:
polynomialSquaredDistance(this.coeffs, other.coeffs)
• #### fitPolynomial

```public static double[] fitPolynomial(double[] data,
int order)```
Fit a polynomial of the given order to the given data.
Parameters:
`data` - the data points, assumed to be in the interval [0, 1[
`order` - the order of the polynomial. Must be non-negative.
Returns:
the polynomial coefficients, highest power first. In other words, if the polynomial is `a_order t^order + a_(order-1) t^(order-1) + ... + a_1 t + a_0`, then the array returned contains `a_order, a_(order-1), ..., a_1, a_0`. throws NullPointerException if data is null throws IllegalArgumentException if data.length < order or if order < 0.
• #### generatePolynomialValues

```public static double[] generatePolynomialValues(double[] coeffs,
int numSamples,
double a,
double b)```
For a polynomial with the given coefficients, compute `numSamples` values, equally spaced in the interval [a, b[.
Parameters:
`coeffs` - the polynomial coefficients. The code assumes that the polynomial is `a_order t^order + a_(order-1) t^(order-1) + ... + a_1 t + a_0`, and will interpret coeffs as `a_order, a_(order-1), ..., a_1, a_0`, where `order` is `coeffs.length-1`.
`numSamples` - num samples
`a` - lower bound (inclusive)
`b` - upper bound (exclusive)
Returns:
the predicted samples.
Throws:
`NullPointerException` - if coeffs is null
`IllegalArgumentException` - if coeffs has length 0
`IllegalArgumentException` - if numSamples is ≤ 0
`IllegalArgumentException` - if a is not less than b.
• #### getValueAt

```public static double getValueAt(double[] coeffs,
double x)```
For a polynomial with the given coefficients, compute the value at the given position.
Parameters:
`coeffs` - the polynomial coefficients. The code assumes that the polynomial is `a_order t^order + a_(order-1) t^(order-1) + ... + a_1 t + a_0`, and will interpret coeffs as `a_order, a_(order-1), ..., a_1, a_0`, where `order` is `coeffs.length-1`.
`x` - the position where to compute the value
Returns:
the predicted value
Throws:
`NullPointerException` - if coeffs is null
`IllegalArgumentException` - if coeffs has length 0
• #### mean

`public static Polynomial mean(Polynomial[] p)`
Compute the mean polynomial from the given polynomials, by building a polynomial of the averaged coefficients.
Parameters:
`p` - the polynomials from which to compute the mean. they must all have the same order
Returns:
the mean polynomial, of the same order.
• #### mean

`public static double[] mean(double[][] p)`
Compute the mean polynomial from the given polynomials, by building a polynomial of the averaged coefficients.
Parameters:
`p` - the polynomials from which to compute the mean. they must all have the same order
Returns:
the mean polynomial, of the same order.
• #### mean

`public static float[] mean(float[][] p)`
Compute the mean polynomial from the given polynomials, by building a polynomial of the averaged coefficients.
Parameters:
`p` - the polynomials from which to compute the mean. they must all have the same order
Returns:
the mean polynomial, of the same order.
• #### variance

```public static double variance(Polynomial[] p,
Polynomial mean)```
For the given collection of polynomials, for which a mean polynomial has already been computed using `mean(Polynomial[])`, compute a variance as follows.

` V = 1/(p-1) * sum i from 0 to p-1 of integral from 0 to 1 of (p[i]-mean)^2`; in other words, the sum of the squared distances (@see{#polynomialSquaredDistance()}) between each polynomial in p and the mean, divided by (p-1).

Parameters:
`p` - p
`mean` - mean
Returns:
the variance, a single non-negative double value.
• #### variance

```public static double variance(double[][] p,
double[] mean)```
For the given collection of polynomials, for which a mean polynomial has already been computed using `mean(double[][])`, compute a variance as follows.

` V = 1/(p-1) * sum i from 0 to p-1 of integral from 0 to 1 of (p[i]-mean)^2`; in other words, the sum of the squared distances (@see{#polynomialSquaredDistance()}) between each polynomial in p and the mean, divided by (p-1).

Parameters:
`p` - p
`mean` - mean
Returns:
the variance, a single non-negative double value.
• #### variance

```public static double variance(float[][] p,
float[] mean)```
For the given collection of polynomials, for which a mean polynomial has already been computed using `mean(float[][])`, compute a variance as follows.

` V = 1/(p-1) * sum i from 0 to p-1 of integral from 0 to 1 of (p[i]-mean)^2`; in other words, the sum of the squared distances (@see{#polynomialSquaredDistance()}) between each polynomial in p and the mean, divided by (p-1).

Parameters:
`p` - p
`mean` - mean
Returns:
the variance, a single non-negative double value.
• #### polynomialDistance

```public static double polynomialDistance(double[] coeffs1,
double[] coeffs2)```
Compute the integrated distance between two polynomials of same order. More precisely, this will return the absolute value of the integral from 0 to 1 of the difference between the two functions.
Parameters:
`coeffs1` - polynomial coefficients, [a_order, a_(order-1), ..., a_1, a_0]
`coeffs2` - polynomial coefficients, [a_order, a_(order-1), ..., a_1, a_0]
Returns:
abs(dist)
• #### polynomialDistance

```public static double polynomialDistance(float[] coeffs1,
float[] coeffs2)```
Compute the integrated distance between two polynomials of same order. More precisely, this will return the absolute value of the integral from 0 to 1 of the difference between the two functions.
Parameters:
`coeffs1` - polynomial coefficients, [a_order, a_(order-1), ..., a_1, a_0]
`coeffs2` - polynomial coefficients, [a_order, a_(order-1), ..., a_1, a_0]
Returns:
abs(dist)
• #### polynomialSquaredDistance

```public static double polynomialSquaredDistance(double[] coeffs1,
double[] coeffs2)```
Compute the integral of the squared difference between two polynomials of same order. More precisely, this will return the the integral from 0 to 1 of the square of the difference between the two functions.

This implements the algebraic solution proposed by Maxima from the following command: `expand(integrate((sum(a[i]*x**i, i, 0, order))**2, x, 0, 1));`, with order varied from 0 to 4. Increasing order by 1 adds (order+1) summands.

Parameters:
`coeffs1` - polynomial coefficients, [a_order, a_(order-1), ..., a_1, a_0]
`coeffs2` - polynomial coefficients, [a_order, a_(order-1), ..., a_1, a_0]
Returns:
integrateSquared(order, a)
• #### polynomialSquaredDistance

```public static double polynomialSquaredDistance(float[] coeffs1,
float[] coeffs2)```
Compute the integral of the squared difference between two polynomials of same order. More precisely, this will return the the integral from 0 to 1 of the square of the difference between the two functions.

This implements the algebraic solution proposed by Maxima from the following command: `expand(integrate((sum(a[i]*x**i, i, 0, order))**2, x, 0, 1));`, with order varied from 0 to 4. Increasing order by 1 adds (order+1) summands.

Parameters:
`coeffs1` - polynomial coefficients, [a_order, a_(order-1), ..., a_1, a_0]
`coeffs2` - polynomial coefficients, [a_order, a_(order-1), ..., a_1, a_0]
Returns:
integrateSquared(order, a)
• #### polynomialPearsonProductMomentCorr

```public static double polynomialPearsonProductMomentCorr(double[] coeffs1,
double[] coeffs2)```
Compute one minus the Pearson product moment correlation between two polynomials of same order.

Equation: `D = 1 - corr(F1 * F2)`

Purpose: the distance should be less for contours that have a similar shape, so differences in pitch height or pitch range should not be included in the distance measure.
Parameters:
`coeffs1` - polynomial coefficients that are not null
`coeffs2` - polynomial coefficients that are not null coeffs1, coeffs2 are expected to be coefficients of same order polynomials
Returns:
double distance between two polynomial coefficients
Throws:
`NullPointerException` - if received polynomial coeffs null
`IllegalArgumentException` - if the length of coeffs are not equal

Copyright © 2000–2018 DFKI GmbH. All rights reserved.