MathUtils { public static double[] interpolateNonZeroValues(double[] contour) { for (int i = 0; i < contour.length; i++) { if (contour[i] == 0) { int index = findNextIndexNonZero(contour, i); if (index == -1) { for (int j = (i == 0 ? 1 : i); j < contour.length; j++) { contour[j] = contour[j - 1]; } break; } else { for (int j = i; j < index; j++) { if (i == 0) { contour[j] = contour[index]; } else { contour[j] = contour[j - 1] + ((contour[index] - contour[i - 1]) / (index - i + 1)); } } i = index - 1; } } } return contour; }  static boolean isPowerOfTwo(int N); static int closestPowerOfTwoAbove(int N); static int findNextValleyLocation(double[] data, int startIndex); static int findNextPeakLocation(double[] data, int startIndex); static int findGlobalPeakLocation(double[] data); static int findGlobalPeakLocation(float[] data); static int findGlobalValleyLocation(double[] data); static int findGlobalValleyLocation(float[] data); static double sum(double[] data); static float sum(float[] data); static int sum(int[] data); static double sumSquared(double[] data); static double sumSquared(double[] data, double term); static double sumSquared(double[] data, int startInd, int endInd); static double sumSquared(double[] data, int startInd, int endInd, double term); static double max(double[] data); static int max(int[] data); static double absMax(double[] data); static double absMax(double[] data, int off, int len); static double min(double[] data); static int min(int[] data); static double mean(double[] data); static double mean(double[] data, int startIndex, int endIndex); static double mean(double[] data, int[] inds); static float mean(float[] data, int startIndex, int endIndex); static float mean(float[] data); static float mean(float[] data, int[] inds); static double mean(double[] data, int opt); static double standardDeviation(double[] data); static double standardDeviation(double[] data, double meanVal); static double standardDeviation(double[] data, double meanVal, int startIndex, int endIndex); static double standardDeviation(double[] data, int opt); static double variance(double[] data, int opt); static double variance(double[] data); static float variance(float[] data); static double variance(double[] data, double meanVal); static float variance(float[] data, float meanVal); static float variance(float[] data, float meanVal, int startIndex, int endIndex); static double variance(double[] data, double meanVal, int startIndex, int endIndex); static double[] variance(double[][] x, double[] meanVector); static double[] variance(double[][] x, double[] meanVector, boolean isAlongRows); static double[] mean(double[][] x); static double[] mean(double[][] x, boolean isAlongRows); static double[] mean(double[][] x, boolean isAlongRows, int[] indicesOfX); static double[][] covariance(double[][] x); static double[][] covariance(double[][] x, double[] meanVector); static double[][] covariance(double[][] x, boolean isAlongRows); static double[][] covariance(double[][] x, double[] meanVector, boolean isAlongRows); static double[][] covariance(double[][] x, double[] meanVector, boolean isAlongRows, int[] indicesOfX); static double correlation(double[] x, double[] y); static double[] diagonal(double[][] x); static double[][] toDiagonalMatrix(double[] x); static double[][] transpoze(double[] x); static double[][] transpoze(double[][] x); static ComplexNumber[][] transpoze(ComplexNumber[][] x); static ComplexNumber[][] hermitianTranspoze(ComplexNumber[][] x); static ComplexNumber[][] diagonalComplexMatrix(double[] diag); static double[][] diagonalMatrix(double[] diag); static ComplexNumber ampPhase2ComplexNumber(double amp, double phaseInRadians); static ComplexNumber[] polar2complex(double[] amps, float[] phasesInRadian); static ComplexNumber[] polar2complex(double[] amps, double[] phasesInRadian); static double[] add(double[] x, double[] y); static double[] add(double[] a, double b); static double[] subtract(double[] a, double[] b); static double[] subtract(double[] a, double b); static double[] multiply(double[] a, double[] b); static float[] multiply(float[] a, float[] b); static double[] multiply(double[] a, double b); static float[] multiply(float[] a, float b); static double[] invert(double[] a); static float[] invert(float[] a); static ComplexNumber[] multiplyComplex(ComplexNumber[] a, double b); static ComplexNumber complexConjugate(ComplexNumber x); static ComplexNumber complexConjugate(double xReal, double xImag); static ComplexNumber addComplex(ComplexNumber x1, ComplexNumber x2); static ComplexNumber addComplex(ComplexNumber x, double yReal, double yImag); static ComplexNumber addComplex(double yReal, double yImag, ComplexNumber x); static ComplexNumber addComplex(double xReal, double xImag, double yReal, double yImag); static ComplexNumber subtractComplex(ComplexNumber x1, ComplexNumber x2); static ComplexNumber subtractComplex(ComplexNumber x, double yReal, double yImag); static ComplexNumber subtractComplex(double yReal, double yImag, ComplexNumber x); static ComplexNumber subtractComplex(double xReal, double xImag, double yReal, double yImag); static ComplexNumber multiplyComplex(ComplexNumber x1, ComplexNumber x2); static ComplexNumber multiplyComplex(ComplexNumber x, double yReal, double yImag); static ComplexNumber multiplyComplex(double yReal, double yImag, ComplexNumber x); static ComplexNumber multiplyComplex(double xReal, double xImag, double yReal, double yImag); static ComplexNumber multiply(double x1, ComplexNumber x2); static ComplexNumber divideComplex(ComplexNumber x, double yReal, double yImag); static ComplexNumber divideComplex(double yReal, double yImag, ComplexNumber x); static ComplexNumber divideComplex(ComplexNumber x1, ComplexNumber x2); static ComplexNumber divideComplex(double xReal, double xImag, double yReal, double yImag); static ComplexNumber divide(ComplexNumber x1, double x2); static ComplexNumber divide(double x1, ComplexNumber x2); static double magnitudeComplexSquared(ComplexNumber x); static double magnitudeComplexSquared(double xReal, double xImag); static double magnitudeComplex(ComplexNumber x); static double[] magnitudeComplex(ComplexNumber[] xs); static double[] magnitudeComplex(ComplexArray x); static double magnitudeComplex(double xReal, double xImag); static double phaseInRadians(ComplexNumber x); static float phaseInRadiansFloat(ComplexNumber x); static double phaseInRadians(double xReal, double xImag); static double[] phaseInRadians(ComplexNumber[] xs); static float[] phaseInRadiansFloat(ComplexNumber[] xs); static double[] phaseInRadians(ComplexArray x); static ComplexNumber complexNumber(double r, double theta); static double[] divide(double[] a, double[] b); static double[] divide(double[] a, double b); static double[][] add(double[][] x, double[][] y); static double[][] subtract(double[][] x, double[][] y); static double[][] multiply(double a, double[][] x); static double[][] divide(double[][] x, double a); static double[] matrixProduct(double[][] x, double[] y); static double[] matrixProduct(double[][] x, float[] y); static ComplexNumber[] matrixProduct(ComplexNumber[][] x, ComplexNumber[] y); static ComplexNumber[] matrixProduct(ComplexNumber[][] x, double[] y); static double[][] matrixProduct(double[] x, double[][] y); static ComplexNumber[][] matrixProduct(ComplexNumber[] x, ComplexNumber[][] y); static double[][] matrixProduct(double[][] x, double[][] y); static ComplexNumber[][] matrixProduct(ComplexNumber[][] x, ComplexNumber[][] y); static double[][] vectorProduct(double[] x, boolean isColumnVectorX, double[] y, boolean isColumnVectorY); static double dotProduct(double[] x, double[] y); static double[][] dotProduct(double[][] x, double[][] y); static double dbSPL(double energy); static double[] dbSPL(double[] energies); static double db(double energy); static double amp2db(double amp); static double amp2neper(double amp); static double[] db(double[] energies); static double[] abs(ComplexArray c); static double[] abs(ComplexNumber[] x); static double[] abs(ComplexArray c, int startInd, int endInd); static double[] amp2db(double[] amps); static double[] amp2neper(double[] amps); static double[] dft2ampdb(ComplexArray c); static double[] dft2ampdb(ComplexArray c, int startInd, int endInd); static double db2linear(double dbEnergy); static double[] db2linear(double[] dbEnergies); static double[] linear2db(double[] linears); static float db2amp(float dbAmplitude); static double db2amp(double dbAmplitude); static float[] db2amp(float[] dbAmplitudes); static double[] db2amp(double[] dbAmplitudes); static float radian2degrees(float rad); static double radian2degrees(double rad); static float degrees2radian(float deg); static double degrees2radian(double deg); static double sumSquaredError(double[] a, double[] b); static double log10(double x); static double[] log(double[] a); static double[] log(double[] a, double minimumValue, double fixedValue); static double[] log10(double[] a); static double exp10(double x); static double[] exp(double[] a); static double[] exp10(double[] a); static float[] add(float[] a, float[] b); static float[] add(float[] a, float b); static float[] subtract(float[] a, float[] b); static float[] subtract(float[] a, float b); static double euclidianLength(float[] a); static double euclidianLength(double[] a); static void toPolarCoordinates(double[] x, double[] y); static void toCartesianCoordinates(double[] r, double[] phi); static double angleToDefaultAngle(double angle); static void angleToDefaultAngle(double[] angle); static double[] levinson(double[] r, int m); static ComplexNumber[] levinson(ComplexNumber[] r, ComplexNumber[] c); static float[] interpolate(float[] x, int newLength); static double[] interpolate(double[] x, int newLength); static ComplexNumber[] interpolate(ComplexNumber[] x, int newLength); static double[] interpolate(int[] xInds, double[] xVals, int[] xInds2); static double interpolatedSample(double xStart, double xVal, double xEnd, double yStart, double yEnd); static int getMax(int[] x); static int getMinIndex(int[] x); static int getMinIndex(int[] x, int startInd); static int getMinIndex(int[] x, int startInd, int endInd); static int getMaxIndex(int[] x); static int getMaxIndex(int[] x, int startInd); static int getMaxIndex(int[] x, int startInd, int endInd); static int getExtremaIndex(int[] x, boolean isMax); static int getExtremaIndex(int[] x, boolean isMax, int startInd); static int getExtremaIndex(int[] x, boolean isMax, int startInd, int endInd); static int getMinIndex(float[] x); static int getMinIndex(float[] x, int startInd); static int getMinIndex(float[] x, int startInd, int endInd); static int getMaxIndex(float[] x); static int getMaxIndex(float[] x, int startInd); static int getMaxIndex(float[] x, int startInd, int endInd); static int getExtremaIndex(float[] x, boolean isMax); static int getExtremaIndex(float[] x, boolean isMax, int startInd); static int getExtremaIndex(float[] x, boolean isMax, int startInd, int endInd); static int getMinIndex(double[] x); static int getMinIndex(double[] x, int startInd); static int getMinIndex(double[] x, int startInd, int endInd); static int getMaxIndex(double[] x); static int getMaxIndex(double[] x, int[] inds); static int getMaxIndex(double[] x, int startInd); static int getMaxIndex(double[] x, int startInd, int endInd); static int getExtremaIndex(double[] x, boolean isMax); static int getExtremaIndex(double[] x, boolean isMax, int startInd); static int getExtremaIndex(double[] x, boolean isMax, int startInd, int endInd); static double getMax(double[] x); static float getMax(float[] x); static int getMin(int[] x); static double getMin(double[] x); static float getMin(float[] x); static double getAbsMax(double[] x); static double getAbsMax(double[] x, int startInd, int endInd); static int getAbsMaxInd(double[] x, int startInd, int endInd); static double[] filledArray(double val, int len); static float[] filledArray(float val, int len); static int[] filledArray(int val, int len); static double[] zeros(int len); static double[] ones(int len); static int[] zerosInt(int len); static int[] onesInt(int len); static float[] zerosFloat(int len); static float[] onesFloat(int len); static int[] find(int[] x, int comparator, int val); static int[] findAnd(int[] x, int comparator1, int val1, int comparator2, int val2); static int[] findOr(int[] x, int comparator1, int val1, int comparator2, int val2); static int[] findAnd(double[] x, int comparator1, double val1, int comparator2, double val2); static int[] findOr(double[] x, int comparator1, double val1, int comparator2, double val2); static double[] findValues(double[] x, int comparator, double val); static int[] find(double[] x, int comparator, double val); static double[] interpolate_linear(int[] x, double[] y, int[] xi); static int CheckLimits(int val, int minVal, int maxVal); static double CheckLimits(double val, double minVal, double maxVal); static float CheckLimits(float val, float minVal, float maxVal); static int[] getExtrema(double[] x, int numLeftN, int numRightN, boolean isMaxima); static int[] getExtrema(double[] x, int numLeftN, int numRightN, boolean isMaxima, int startInd); static int[] getExtrema(double[] x, int numLeftN, int numRightN, boolean isMaxima, int startInd, int endInd); static int[] getExtrema(double[] x, int numLeftN, int numRightN, boolean isMaxima, int startInd, int endInd, double th); static int[] getExtrema(double[] x, int[] numLeftNs, int[] numRightNs, boolean isMaxima); static int[] getExtrema(double[] x, int[] numLeftNs, int[] numRightNs, boolean isMaxima, int startInd); static int[] getExtrema(double[] x, int[] numLeftNs, int[] numRightNs, boolean isMaxima, int startInd, int endInd); static int[] getExtrema(double[] x, int[] numLeftNs, int[] numRightNs, boolean isMaxima, int startInd, int endInd,
			double th); static double[] getRandoms(int len); static double[] getRandoms(int len, double minVal, double maxVal); static int findClosest(float[] x, float val); static int findClosest(int[] x, int val); static float unwrap(float phaseInRadians, float prevPhaseInRadians); static float unwrapToRange(float phaseInDegrees, float lowestDegree); static double db2neper(double db); static double[] db2neper(double[] dbs); static double neper2db(double neper); static double[] neper2db(double[] nepers); static double neper2linear(double neper); static double[] neper2linear(double[] nepers); static float[] sinc(float[] x, float N); static float sinc(float x, float N); static double sinc(double x, double N); static float[] sinc(float[] x); static double[] sinc(double[] x); static float sinc(float x); static double sinc(double x); static double getSortedValue(double[] x, double percentSmallerThan); static int[][] factorialDesign(int[] totalItemsInNodes); static float linearMap(float x, float xStart, float xEnd, float yStart, float yEnd); static double linearMap(double x, double xStart, double xEnd, double yStart, double yEnd); static int linearMap(int x, int xStart, int xEnd, int yStart, int yEnd); static int[] quickSort(int[] x); static int[] quickSort(double[] x); static int[] quickSort(float[] x); static int[] quickSort(double[] x, int startIndex, int endIndex); static int[] quickSort(float[] x, int startIndex, int endIndex); static void quickSort(double[] x, int[] y); static void quickSort(float[] x, int[] y); static void quickSort(double[] x, int[] y, int startIndex, int endIndex); static void quickSort(float[] x, int[] y, int startIndex, int endIndex); static double[] sortAs(double[] x, int[] sortedIndices); static float[] sortAs(float[] x, int[] sortedIndices); static double[] normalizeZscore(double[] x); static double[] normalizeToSumUpTo(double[] x, double sumUp); static double[] normalizeToSumUpTo(double[] x, int len, double sumUp); static double[] normalizeToRange(double[] x, int len, double minVal, double maxVal); static double[] normalizeToAbsMax(double[] x, double absMax); static void adjustMean(double[] x, double newMean); static void adjustVariance(double[] x, double newVariance); static void adjustMeanVariance(double[] x, double newMean, double newVariance); static void adjustVariance(double[] x, double newVariance, double currentMean); static void adjustMeanStandardDeviation(double[] x, double newMean, double newStandardDeviation); static void adjustStandardDeviation(double[] x, double newStandardDeviation); static void adjustStandardDeviation(double[] x, double newStandardDeviation, double currentMean); static void adjustMeanStandardDeviation(double[] x, double currentMean, double newMean, double newStandardDeviation); static void adjustRange(double[] x, double minVal, double maxVal); static boolean clipRange(double[] x, double minVal, double maxVal); static double median(double[] x); static double median(double[] xin, int firstIndex, int lastIndex); static double absMean(double[] x); static double[] getVarianceRows(double[][] x); static double[] getVarianceCols(double[][] x); static double getGaussianPdfValueConstantTerm(int featureDimension, double detCovarianceMatrix); static double getGaussianPdfValueConstantTermLog(int featureDimension, double detCovarianceMatrix); static double getGaussianPdfValue(double[] x, double[] meanVector, double[] covarianceMatrix); static double getGaussianPdfValue(double[] x, double[] meanVector, double[] covarianceMatrix, double constantTerm); static double getGaussianPdfValueLog(double[] x, double[] meanVector, double[] covarianceMatrix, double constantTermLog); static double getGaussianPdfValue(double[] x, double[] meanVector, double detCovarianceMatrix,
			double[][] inverseCovarianceMatrix); static double getGaussianPdfValue(double[] x, double[] meanVector, double[][] inverseCovarianceMatrix,
			double constantTerm); static double determinant(double[] diagonal); static double determinant(double[][] matrix); static double[] random(int numSamples); static double[] random(int numSamples, double minVal, double maxVal); static double[] inverse(double[] x); static ComplexNumber[] inverse(ComplexNumber[] x); static double[][] inverse(double[][] matrix); static ComplexNumber[][] inverse(ComplexNumber[][] matrix); static void inverseInPlace(double[][] matrix); static void inverseInPlace(ComplexNumber[][] matrix); static void luDecompose(double[][] a, int n, int[] indx, double[] d); static void luDecompose(ComplexNumber[][] a, int n, int[] indx, ComplexNumber[] d); static void luSubstitute(double[][] a, int[] indx, double b[]); static void luSubstitute(ComplexNumber[][] a, int[] indx, ComplexNumber b[]); static double logAdd(double x, double y); static int getLargestIndexSmallerThan(double[] x, double val); static int[] randomSort(int[] x); static double[][] randomSort(double[][] x); static int[] addIndex(int[] X, int x); static int[] removeIndex(int[] X, int x); static double[] modifySize(double[] x, int newLen); static double getConfidenceInterval95(double standardDeviation); static double getConfidenceInterval99(double standardDeviation); static double[] autocorr(double[] x, int P); static boolean isAnyNaN(double[] x); static boolean isAnyInfinity(double[] x); static boolean allZeros(double[] x); static double[] doubleRange2ByteRange(double[] x); static double[] doubleRange2ByteRange(double[] x, double doubleMin, double doubleMax); static double[] byteRange2DoubleRange(double[] x); static double[] byteRange2DoubleRange(double[] x, double doubleMin, double doubleMax); static float[] floatRange2ByteRange(float[] x); static float[] floatRange2ByteRange(float[] x, float floatMin, float floatMax); static float[] byteRange2FloatRange(float[] x); static float[] byteRange2FloatRange(float[] x, float floatMin, float floatMax); static double trimToRange(double untrimmedValue, double min, double max); static double[] interpolateNonZeroValues(double[] contour); static int findNextIndexNonZero(double[] contour, int current); static double[] arrayResize(double[] source, int targetSize); static double[] diff(double[] a); static void main(String[] args); static String[] toStringLines(ComplexNumber[] x); static String[] toStringLines(ComplexArray x); static String toString(ComplexNumber[][] array); static final double TINY_PROBABILITY; static final double TINY_PROBABILITY_LOG; static final double TINY; static final double TINY_LOG; static final double TWOPI; static final int EQUALS; static final int GREATER_THAN; static final int GREATER_THAN_OR_EQUALS; static final int LESS_THAN; static final int LESS_THAN_OR_EQUALS; static final int NOT_EQUALS; }
@Test public void testInterpolateNonZeroValues() { double[] contour = new double[] { 1, 0, 3 }; double[] expected = new double[] { 1, 2, 3 }; double[] actual = MathUtils.interpolateNonZeroValues(contour); Assert.assertArrayEquals(expected, actual, 0d); }