Michael Thomas Flanagan's Java Scientific Library

ThreeDimensionalSmooth Class:     Three Dimensional Smoothing

     

Last update: 16 March 2012
Main Page of Michael Thomas Flanagan's Java Scientific Library

This class contains methods for smoothing three dimensional data, v = f(x, y, z). A choice of smoothing method is offered:
The class also contains methods for: See CurveSmooth for the one dimensional equivalent of this class, i.e. for curve smoothing
See SurfaceSmooth for the two dimensional equivalent of this class, i.e. for surface smoothing

import directive: import flanagan.analysis.ThreeDimensionalSmooth;

SUMMARY OF METHODS

Constructors public ThreeDimensionalSmooth(double[] xData, double[] yData, double[] zData, double[][][] vData)
public ThreeDimensionalSmooth(double[][][] vData)
public ThreeDimensionalSmooth(float[] xData, float[] yData, float[] zData, float[][][] vData)
public ThreeDimensionalSmooth(float[][][] vData)
public ThreeDimensionalSmooth(long[] xData, long[] yData, long[] zData, long[][][] vData)
public ThreeDimensionalSmooth(long[][][] vData)
public ThreeDimensionalSmooth(int[] xData, int[] yData, int[] zData, int[][][] vData)
public ThreeDimensionalSmooth(int[][][] vData)
public ThreeDimensionalSmooth(BigDecimal[] xData, BigDecimal[] yData, BigDecimal[] zData, BigDecimal[][][] vData)
public ThreeDimensionalSmooth(BigDecimal[][][] vData)
public ThreeDimensionalSmooth(BigInteger[] xData, BigInteger[] yData, BigInteger[] zData, BigInteger[][][] vData)
public ThreeDimensionalSmooth(BigInteger[][][] vData)
Smoothing Savitzky-Golay Smoothed Curves public double[][][] savitzkyGolay(int sgFilterWidthx, int sgFilterWidthy, int sgFilterWidthz)
public double[][][] savitzkyGolay(int sgFilterWidth)
public double[][][] getSavitzkyGolaySmoothedValues()
Smoothed Derivatives public double[][][][] savitzkyGolay(int sgFilterWidthx, int sgFilterWidthy, int sgFilterWidthz, int p, int q, int r)
public double[][][] getSavitzDerivatives()
The Filter public double[][] getSGcoefficients()
public void setSGpolyDegree(int degree)
public int getSGpolyDegree()
public int[][] getSGPolyIndices()
public static double[][] savitzkyGolayFilter(int nBackwardx, int nForwardx, int nBackwardy, int nForwardy, int nBackwardz, int nForwardz, int degree)
public static int[][] filterIndices(int degree)
Moving Average Window public double[][][] movingAverage(int sgWindowWidthx, int sgWindowWidthy, int sgWindowWidthz)
public double[][][] movingAverage(int sgWindowWidth)
public double[][][] getMovingAverageValues()
public BigDecimal[][][] movingAverageAsBigDecimal(int sgWindowWidthx, int sgWindowWidthy, int sgWindowWidthz)
public BigDecimal[][][] movingAverageAsBigDecimal(int sgWindowWidth)
public BigDecimal[][][] getMovingAverageValuesAsBigDecimal()
Extent of smoothing public double extentMovingAverage()
public double extentSavitzlyGolay()
Interpolation Savitzky-Golay public double interpolateSavitzkyGolay(double xi, double yi, double zi)
Moving average public double interpolateMovingAverage(double xi, double yi, double zi)
Plot Savitzky-Golay x-direction section public double plotSavitzkyGolayX(double yValue, double zValue)
public double plotSavitzkyGolayX(int yIndex, dint zIndex)
y-direction section public double plotSavitzkyGolayY(double xValue, double zValue)
public double plotSavitzkyGolayY(int xIndex, int zIndex)
z-direction section public double plotSavitzkyGolayZ(double xValue, double yValue)
public double plotSavitzkyGolayZ(int xIndex, int yIndex)
Moving average x-direction section public double plotMovingAverageX(double yValue, int zValue)
public double plotMovingAverageX(int yIndex, int zIndex)
y-direction section public double plotMovingAverageY(double xValue, int zValue)
public double plotMovingAverageY(int xIndex, int zIndex)
z-direction section public double plotMovingAverageZ(double xValue, int yValue)
public double plotMovingAverageZ(int xIndex, int yIndex)




CONSTRUCTORS

public ThreeDimensionalSmooth(double[] xData, double[] yData, double[] zData, double[][][] vData)
public ThreeDimensionalSmooth(float[] xData, float[] yData, float[] zData, float[][][] vData)
public ThreeDimensionalSmooth(long[] xData, long[] yData, long[] zData, long[][][] vData)
public ThreeDimensionalSmooth(int[] xData, int[] yData, int[] zData)
public ThreeDimensionalSmooth(BigDecimal[] xData, BigDecimal[] yData, BigDecimal[] zData, BigDecimal[][][] vData)
public ThreeDimensionalSmooth(BigInteger[] xData, BigInteger[] yData, BigInteger[][] zData, BigInteger[][][] vData)
Usage:                      ThreeDimensionalSmooth tds = new ThreeDimensionalSmooth(xData, yData, zData, vData);
Creates an instance of ThreeDimensionalSmooth. The data is entered as arrays of the x, y and z values, arguments xData, yData and zData, for v = f(x, y, z). The data may be entered as type double, float, long, int, BigDecimal or BigInteger. All data, except types BigDecimal and BigInteger, are converted to type double before processing. BigInteger is converted to BigDecimal. Moving average window smoothing is performed in arbitrary precision arithmetic for BigDecimal and BigInteger entered data. Savitzky-Golay filtering is performed in double precision arithmetic for BigDecimal and BigInteger entered data. The data are ordered as ascending x and ascending y values before processing.
The 3D array v [argument vData] should be dimensioned as vData[n][m][l] where n is the number of z [zData] values, m is the number of y [yData] values and l is the number of x [xData] values.

public ThreeDimensionalSmooth(double[][][] vData)
public ThreeDimensionalSmooth(float[][][] vData)
public ThreeDimensionalSmooth(long[][][] vData)
public ThreeDimensionalSmooth(int[][][] vData)
public ThreeDimensionalSmooth(BigDecimal[][][] vData)
public ThreeDimensionalSmooth(BigInteger[][][] vData)
Usage:                      ThreeDimensionalSmooth tds = new ThreeDimensionalSmooth(vData);
Creates an instance of ThreeDimensionalSmooth. The data is entered as an array of v values, argument vData, for v = f(x, y,z). As no x, y or z values are entered the data is treated as data sampled at equal x, y and z value intervals. Values of 0, 1, 2 ... to l-1 are assigned to the l x-values. Values of 0, 1, 2 ... to m-1 are assigned to the m y-values. Values of 0, 1, 2 ... to n-1 are assigned to the n z-values. The data may be entered as type double, float, long, int, BigDecimal or BigInteger. All data, except types BigDecimal and BigInteger, are converted to type double before processing. BigInteger is converted to BigDecimal. Moving average window smoothing is performed in arbitrary precision arithmetic for BigDecimal and BigInteger entered data. Savitzky-Golay filtering is performed in double precision arithmetic for BigDecimal and BigInteger entered data.



SMOOTHING METHODS

SAVITZKY-GOLAY FILTER METHODS

Savitzky-Golay Smoothed Curves
public double[][][] savitzkyGolay(int sgFilterWidthx, int sgFilterWidthy, int sgFilterWidthz)
public double[][][] savitzkyGolay(int sgFilterWidth)
public double[][][] getsavitzkyGolaySmoothedValues()
Usage:                      smoothedData = tds.savitzkyGolay(sgFilterWidthx, sgFilterWidthy, sgFilterWidthz);
This method returns the smoothed v values, for the data entered via the constructor arguments, using a three dimensional Savitzky-Golay filter of width sgFilterWidthx points in the x dimension, of width sgFilterWidthy points in the y dimension and of width sgFilterWidthz points in the z dimension. The default value of the degree of the fitting polynomial is 4. This value may be reset using the setSGpolyDeg method.

Usage:                      smoothedData = tds.savitzkyGolay(sgFilterWidth);
This method returns the smoothed v values, for the data entered via the constructor arguments, using a three dimensional Savitzky-Golay filter of width sgFilterWidth points in the x dimension and of the same width, sgFilterWidth points, in both the y and z dimensions. The default value of the degree of the fitting polynomial is 4. This value may be reset using the setSGpolyDeg method.

Usage:                      smoothedData = tds.getSavitzkyGolaySmoothedValues();
This method returns the smoothed z values if the above Savitzky-Golay filter method has already been called.


Savitzky-Golay Smoothed Derivatives
public double[][][][] savitzkyGolay(int sgFilterWidthx, int sgFilterWidthy, int sgFilterWidthz, int p, int q, int r)
public double[][][] getSavitzkyGolayDerivatives()
Usage:                      smoothedDataPlusDeriv = tds.savitzkyGolay(sgFilterWidthx, sgFilterWidthy, sgFilterWidthz, p, q, r);
This method returns the smoothed v values and the smoothed derivatives , for the data entered via the constructor arguments, using a three dimensional Savitzky-Golay filter of width sgFilterWidthx points in the x dimension, of width sgFilterWidthy points in the y dimension and of width sgFilterWidthz points in the z dimension. The arguments p, q and r contains the values of the required orders of the derivative, p, q and r. The smoothed v values are returned, in the above usage, in smoothedDataPlusDeriv[0], the derivatives are returned in smoothedDataPlusDeriv[1].
The sum of p [p], q [q] and r [r] must be less than or equal to the degree of the fitting polynomial. The default value of this degree is 4. This value may be reset using the method setSGpolyDegree.

Usage:                      smoothedData = tds.getSavitzkyDerivatives();
This method returns the Savitzky-Golay smoothed derivatives . The Savitzky-Golay derivative method must already have been called as the last derivative method and the values of p, q and r will be that used in this last call.

The Savitzky-Golay Filter
public double[][] getSGcoefficients()
Usage:                      sgCoefficients = tds.getSGcoefficients();
This method returns the Savitzky-Golay filter coefficients, c, used in the smoothing

lw, mw and nw are the lengths of the filter in the x, y and z directions respectively, ll, ml and nl are the number of points preceeding the data point on which the filter is operating, vz,x,y, in the x, y and z directions respectively and lu, mu and nu are the number of points following the data point, zz,y,x,in the x, y and z directions respectively. If the filter is used as a smoothing filter sz,y,x is the smoothed value of the data point vz,y,x and the c values used are those stored in the zeroth row of the returned matrix sgCoefficients. Each row of sgCoefficients is the array of coefficients c[lw][mw][nw] arranged linearly. Each row of sgCoefficients corresponds to the indices of the fitting polynomial coefficients, e.g. for a polynomial of degree 4,

Each row, when applied to the data, gives the smoothed derivatives, where p, q and r are given by the three subscripts of the polynomial coefficients, e.g. the zeroth row, indices 0,0,0, gives the smoothed zeroth derivative, i.e. the smoothed data values; the second row, indices 0,0,1, gives the derivatives . The trio of indices associated with each row may be obtained by calling the method
getSGpolyIndices() and they correspond to the indices of the coefficients of the fitting polynomial (see above). The default value of the degree of the fitting polynomial is 4. This value may be reset using the setSGpolyDegree method.
The smoothing method, savitzkyGolay, uses a symmetrical filter, i.e. ll = lu, ml = mu and nl = nu.

public int[] getSGpolyIndices()
Usage:                      indicesPairs = tds.getSGpolyIndices();
This method returns the trios of indices of the fitting polynomial (see
above). The value in indices[i][0] is the first index of the ith coefficient of the polynomial and is also the power of z in the ith term. The value in indices[i][1] is the second index of the ith coefficient of the polynomial and is also the power of y in the ith term. The value in indices[i][2] is the third index of the ith coefficient of the polynomial and is also the power of x in the ith term. These returned trios are also ordered to match the rows in the returned c matrix (See savitzkyGolayFilter method above).

public void setSGpolyDegree(int degree)
public int getSGpolyDegree()
Usage:                      tds.setSGpolyDegree(degree);
This method resets the degree of the Savitzky-Golay fitting polynomial. The default value is 4 if this method is not called.

Usage:                      deg = tds.getSGpolyDegree();
This method returns the degree of the Savitzky-Golay fitting polynomial. The default value is 4.

Static methods for returning a Savitzky-Golay filter
public static double[][] savitzkyGolayFilter(int nBackwardx, int nForwardx, int nBackwardy, int nForwardy, int nBackwardz, int nForwardz, int polyDegree)
Usage:                      sgCoefficients = ThreeDimensionalSmooth.savitzkyGolayFilter(nBackwardx, nForwardx, nBackwardx, nForwardx, nBackwardz, nForwardz, polyDegree);
This method returns the coefficients, c, of a three dimensional Savitzky-Golay filter of x dimension length, lw [ = nBackWardx + nForWardx + 1], y dimension length, mw [= nBackWardy + nForWardy + 1], and z dimension length, nw [= nBackWardz + nForWardz + 1], with a fitting polynomial of degree, polyDegree. A description of the coefficients, c, their application and their ordering within the returned two dimensional array, sgCoefficients. may be found
above. The arguments nBackWardx [ll], nBackWardy[ml] and nBackWardz[nl] are the number of points preceeding the data point, upon which the filter is operating, in the x, y and z dimensions respectively and nForWardx [lu], nForWardy [mu] and nForWardz [nu] are the number of points following the data point in the x, y and z dimensions respectively.

public static int[][] filterIndices(int degree)
Usage:                      indicesPairs = ThreeDimensionalSmooth.filterIndices(deg);
This method returns the trios of indices of the fitting polynomialof degree deg. The value in indices[i][0] is the first index of the ith coefficient of the polynomial and is also the power of z in the ith term. The value in indices[i][1] is the second index of the ith coefficient of the polynomial and is also the power of y in the ith term. The value in indices[i][2] is the third index of the ith coefficient of the polynomial and is also the power of x in the ith term. An example of such a fitting polynomial and its coefficients is shown above. These returned trios are also ordered to match the rows in the returned c matrix (See savitzkyGolayFilter method above).



MOVING AVERAGE WINDOW SMOOTHING
public double[][][] movingAverage(int windowWidthx, int windowWidthy, int windowWidthz)
public double[][][] movingAverage(int windowWidth)
public BigDecimal[][][] movingAverageAsBigDecimal(int windowWidthx, int windowWidthy, int windowWidthz)
public BigDecimal[][][] movingAverageAsBigDecimal(int windowWidth)
public double[][][] getMovingAverageValues()
public BigDecimal[][][] getMovingAverageValuesAsBigDecimal()
Usage:                      smoothedData = tds.movingAverage(windowWidthx, windowWidthy, windowWidthz);
This method returns the smoothed v values, for the data entered via the constructor arguments, using a moving average cube of lw [argument windowWidthx] points in the x dimension, of mw [argument windowWidthy] points in the y dimension and of nw [argument windowWidthz] points in the z dimension:

sz,y,x is the smoothed value of the data point zz,y,x. The entered value for the number of points in the windows are adjusted to the next higher odd number if an even number has been entered. The values of ll, lu, ml, mu, nl, and nu are truncated appropriately if, when close to the data extremes, they fall below or above the first or last data point respectively. The smoothed data is returned as type double.

Usage:                      smoothedData = tds.movingAverage(windowWidth);
As immediately above for movingAverage(windowWidthx, windowWidthy, windowWidthz) with a smoothing cube of equal sides, i.e. windowWidthx = windowWidth, windowWidthy = windowWidth and windowWidthz = windowWidth.

Usage:                      smoothedData = tds.movingAverageAsBigDecimal(windowWidthx, windowWidthy, windowWidthz);
As above for movingAverage(windowWidthx, windowWidthy, windowWidthz) with the exception that the smoothed data is returned as type BigDecimal. If the data was entered as type BigDecimal or BigInteger the smoothing will have been performed in arbitrary arithmetic.

Usage:                      smoothedData = tds.movingAverageAsBigDecimal(windowWidthx);
As above for movingAverage(windowWidthx, windowWidthy, windowWidthz) with a smoothing cube of equal sides, i.e. windowWidthx = windowWidth, windowWidthy = windowWidth and windowWidthz = windowWidth, and with the exception that the smoothed data is returned as type BigDecimal. If the data was entered as type BigDecimal or BigInteger the smoothing will have been performed in arbitrary arithmetic.

Usage:                      smoothedData = tds.getMovingAverageValues();
This method returns the smoothed v values if the above moving average window method has already been called.

Usage:                      smoothedData = tds.getMovingAverageValuesAsBigDecimal();
This method returns the smoothed v values if the above moving average window method has already been called. The smoothed values are returned as type BigDecimal.



EXTENT OF SMOOTHING

public double extentSavitzkyGolay()
public double extentMovingAverage()
These methods return the value of the function
    
where vi,j,k is the original v value of the ith, jth, kth data point, si,j,k is its smoothed value, vmin is the minimum value of the vi,j,k, vmax is the maximum value of the zi,j,k and p is the number of x coordinates, q is the number of y coordinates and r is the number of z coordinates.

Usage:                      extent = tds.extentSavitzkyGolay();
In this method si,j,k is the Savitzky-Golay smoothed value.

Usage:                      extent = tds.extentMovingAverage();
In this method si,j,k is its moving average smoothed value.



INTERPOLATION

public double interpolateSavitzkyGolay(double xi, double yi, double zi)
public double interpolateMovingAverage(double xi, , double yi, double zi)
Usage:                      vi = tds.interpolateSavitzkyGolay(xi, yi, zi);
This method returns the interpolated value of v [vi] for the supplied x [argument xi], y [argument yi] and z [argument zi] values for the Savitzky-Golay smoothed data. The interpolation procedure uses the
TriCubicSpline class. A Savitzky-Golay smoothing method must have been called previously.

Usage:                      vi = tds.interpolateMovingAverage(xi, yi, zi);
This method returns the interpolated value of v [vi] for the supplied supplied x [argument xi], y [argument yi] and z [argument zi] values for the moving average smoothed data. The interpolation procedure uses the TriCubicSpline class. A moving average smoothing method must have been called previously.



PLOT

Savitzky-Golay
public double plotSavitzkyGolayX(double yValue, double zValue)
public double plotSavitzkyGolayX(int yIndex, double zIndex)
public double plotSavitzkyGolayY(double xValue, double zValue)
public double plotSavitzkyGolayY(int xIndex, double zIndex)
public double plotSavitzkyGolayZ(double xValue, double yValue)
public double plotSavitzkyGolayZ(int xIndex, double yIndex)
Usage:                      tds.plotSavitzkyGolayX(yValue, zValue);
This method displays a plot of both the original data and the Savitzky-Golay smoothed data for a section parallel to the x-axis at a value of y supplied as the argument yValue and a value of z supplied as the argument zValue. The values, yValue and zValue, must be one of the values supplied in the array yData and the array zData respectively. The arrays yData and zData are those entered via a
Constructor.

Usage:                      tds.plotSavitzkyGolayX(yIndex, zIndex);
This method displays a plot of both the original data and the Savitzky-Golay smoothed data for a section parallel to the x-axis at the value of y whose index in the array yData is the integer supplied as the argument yIndex and at the value of z whose index in the array zData is the integer supplied as the argument zIndex. NB indices start at 0. The arrays yData and zData are those entered via a Constructor.

Usage:                      tds.plotSavitzkyGolayY(xValue, zValue);
This method displays a plot of both the original data and the Savitzky-Golay smoothed data for a section parallel to the y-axis at a value of x supplied as the argument xValue and a value of z supplied as the argument zValue. The values, xValue and zValue, must be one of the values supplied in the array xData and the array zData respectively. The arrays xData and zData are those entered via a Constructor.

Usage:                      tds.plotSavitzkyGolayY(xIndex, zIndex);
This method displays a plot of both the original data and the Savitzky-Golay smoothed data for a section parallel to the y-axis at the value of x whose index in the array xData is the integer supplied as the argument xIndex and at the value of z whose index in the array zData is the integer supplied as the argument zIndex. NB indices start at 0. The arrays xData and zData are those entered via a Constructor.

Usage:                      tds.plotSavitzkyGolayZ(xValue, yValue);
This method displays a plot of both the original data and the Savitzky-Golay smoothed data for a section parallel to the z-axis at a value of x supplied as the argument xValue and a value of y supplied as the argument yValue. The values, xValue and yValue, must be one of the values supplied in the array xData and the array yData respectively. The arrays xData and yData are those entered via a Constructor.

Usage:                      tds.plotSavitzkyGolayZ(xIndex, yIndex);
This method displays a plot of both the original data and the Savitzky-Golay smoothed data for a section parallel to the z-axis at the value of x whose index in the array xData is the integer supplied as the argument xIndex and at the value of y whose index in the array yData is the integer supplied as the argument yIndex. NB indices start at 0. The arrays xData and yData are those entered via a Constructor.

Moving average
public double plotMovingAverageX(double yValue, double zValue)
public double plotMovingAverageX(int yIndex, double zIndex)
public double plotMovingAverageY(double xValue, double zValue)
public double plotMovingAverageY(int xIndex, double zIndex)
public double plotMovingAverageZ(double xValue, double yValue)
public double plotMovingAverageZ(int xIndex, double yIndex)
Usage:                      tds.plotMovingAverageX(yValue, zValue);
This method displays a plot of both the original data and the Moving Average smoothed data for a section parallel to the x-axis at a value of y supplied as the argument yValue and a value of z supplied as the argument zValue. The values, yValue and zValue, must be one of the values supplied in the array yData and the array zData respectively. The arrays yData and zData are those entered via a Constructor.

Usage:                      tds.plotMovingAverageX(yIndex, zIndex);
This method displays a plot of both the original data and the Moving Average smoothed data for a section parallel to the x-axis at the value of y whose index in the array yData is the integer supplied as the argument yIndex and at the value of z whose index in the array zData is the integer supplied as the argument zIndex. NB indices start at 0. The arrays yData and zData are those entered via a Constructor.

Usage:                      tds.plotMovingAverageY(xValue, zValue);
This method displays a plot of both the original data and the Moving Average smoothed data for a section parallel to the y-axis at a value of x supplied as the argument xValue and a value of z supplied as the argument zValue. The values, xValue and zValue, must be one of the values supplied in the array xData and the array zData respectively. The arrays xData and zData are those entered via a Constructor.

Usage:                      tds.plotMovingAverageY(xIndex, zIndex);
This method displays a plot of both the original data and the Moving Average smoothed data for a section parallel to the y-axis at the value of x whose index in the array xData is the integer supplied as the argument xIndex and at the value of z whose index in the array zData is the integer supplied as the argument zIndex. NB indices start at 0. The arrays xData and zData are those entered via a Constructor.

Usage:                      tds.plotMovingAverageZ(xValue, yValue);
This method displays a plot of both the original data and the Moving Average smoothed data for a section parallel to the z-axis at a value of x supplied as the argument xValue and a value of y supplied as the argument yValue. The values, xValue and yValue, must be one of the values supplied in the array xData and the array yData respectively. The arrays xData and yData are those entered via a Constructor.

Usage:                      tds.plotMovingAverageZ(xIndex, yIndex);
This method displays a plot of both the original data and the Moving Average smoothed data for a section parallel to the z-axis at the value of x whose index in the array xData is the integer supplied as the argument xIndex and at the value of y whose index in the array yData is the integer supplied as the argument yIndex. NB indices start at 0. The arrays xData and yData are those entered via a Constructor.



OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:


This page was prepared by Dr Michael Thomas Flanagan