bunwarpj
Class MathTools

java.lang.Object
  extended by bunwarpj.MathTools

public class MathTools
extends java.lang.Object

This class has the math methods to deal with b-splines and images.


Field Summary
private static double FLT_EPSILON
          float epsilon
private static int MAX_SVD_ITERATIONS
          maximum number of iteration for the Singular Value Decomposition
 
Constructor Summary
MathTools()
           
 
Method Summary
static double[][] antiSymmetricPadding(double[][] c, int extra)
           
static double[] antiSymmetricPadding(double[] c, int n, int extra)
           
static float[] antiSymmetricPadding(float[] c, int n, int extra)
           
static double Bspline01(double x)
          B-spline 01.
static double Bspline02(double x)
          B-spline 02.
static double Bspline03(double x)
          B-spline 03.
static double EuclideanNorm(double a, double b)
          Euclidean Norm.
static boolean invertMatrixSVD(int Ydim, int Xdim, double[][] B, double[][] iB)
          Invert a matrix by the Singular Value Decomposition method.
static double[] linearLeastSquares(double[][] A, double[] b)
          Gives the least-squares solution to (A * x = b) such that (A^T * A)^-1 * A^T * b = x is a vector of size (column), where A is a (line x column) matrix, and where b is a vector of size (line).
static double nchoosek(int n, int k)
          N choose K.
static void QRdecomposition(double[][] Q, double[][] R)
          Decomposes the (line x column) input matrix Q into an orthonormal output matrix Q of same size (line x column) and an upper-diagonal square matrix R of size (column x column), such that the matrix product (Q * R) gives the input matrix, and such that the matrix product (Q^T * Q) gives the identity.
static void showMatrix(int Ydim, int Xdim, double[][] A)
          Method to display the matrix in the command line.
static void singularValueBackSubstitution(double[][] U, double[] W, double[][] V, double[] B, double[] X)
          solve (U.W.Transpose(V)).X == B in terms of X {U, W, V} are given by SingularValueDecomposition by convention, set w[i,j]=0 to get (1/w[i,j])=0 the size of the input matrix U is (Lines x Columns) the size of the vector (1/W) of singular values is (Columns) the size of the untransposed orthogonal matrix V is (Columns x Columns) the size of the input vector B is (Lines) the size of the output vector X is (Columns)
static void singularValueDecomposition(double[][] U, double[] W, double[][] V)
          Singular Value Decomposition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLT_EPSILON

private static final double FLT_EPSILON
float epsilon


MAX_SVD_ITERATIONS

private static final int MAX_SVD_ITERATIONS
maximum number of iteration for the Singular Value Decomposition

See Also:
Constant Field Values
Constructor Detail

MathTools

public MathTools()
Method Detail

Bspline01

public static double Bspline01(double x)
B-spline 01.

Parameters:
x -

Bspline02

public static double Bspline02(double x)
B-spline 02.

Parameters:
x -

Bspline03

public static double Bspline03(double x)
B-spline 03.

Parameters:
x -

EuclideanNorm

public static double EuclideanNorm(double a,
                                   double b)
Euclidean Norm.

Parameters:
a -
b -

invertMatrixSVD

public static boolean invertMatrixSVD(int Ydim,
                                      int Xdim,
                                      double[][] B,
                                      double[][] iB)
Invert a matrix by the Singular Value Decomposition method.

Parameters:
Ydim - input, Y-dimension
Xdim - input, X-dimension
B - input, matrix to invert
iB - output, inverted matrix
Returns:
under-constrained flag

linearLeastSquares

public static double[] linearLeastSquares(double[][] A,
                                          double[] b)
Gives the least-squares solution to (A * x = b) such that (A^T * A)^-1 * A^T * b = x is a vector of size (column), where A is a (line x column) matrix, and where b is a vector of size (line). The result may differ from that obtained by a singular-value decomposition in the cases where the least-squares solution is not uniquely defined (SVD returns the solution of least norm, not QR).

Parameters:
A - An input matrix A[line][column] of size (line x column)
b - An input vector b[line] of size (line)
Returns:
An output vector x[column] of size (column)

nchoosek

public static double nchoosek(int n,
                              int k)
N choose K.

Parameters:
n -
k -

QRdecomposition

public static void QRdecomposition(double[][] Q,
                                   double[][] R)
Decomposes the (line x column) input matrix Q into an orthonormal output matrix Q of same size (line x column) and an upper-diagonal square matrix R of size (column x column), such that the matrix product (Q * R) gives the input matrix, and such that the matrix product (Q^T * Q) gives the identity.

Parameters:
Q - An in-place (line x column) matrix Q[line][column], which expects as input the matrix to decompose, and which returns as output an orthonormal matrix
R - An output (column x column) square matrix R[column][column]

showMatrix

public static void showMatrix(int Ydim,
                              int Xdim,
                              double[][] A)
Method to display the matrix in the command line.

Parameters:
Ydim - Y-dimension
Xdim - X-dimension
A - matrix to display

singularValueDecomposition

public static void singularValueDecomposition(double[][] U,
                                              double[] W,
                                              double[][] V)
Singular Value Decomposition.

Parameters:
U - input matrix
W - vector of singular values
V - untransposed orthogonal matrix

singularValueBackSubstitution

public static void singularValueBackSubstitution(double[][] U,
                                                 double[] W,
                                                 double[][] V,
                                                 double[] B,
                                                 double[] X)
solve (U.W.Transpose(V)).X == B in terms of X {U, W, V} are given by SingularValueDecomposition by convention, set w[i,j]=0 to get (1/w[i,j])=0 the size of the input matrix U is (Lines x Columns) the size of the vector (1/W) of singular values is (Columns) the size of the untransposed orthogonal matrix V is (Columns x Columns) the size of the input vector B is (Lines) the size of the output vector X is (Columns)

Parameters:
U - input matrix
W - vector of singular values
V - untransposed orthogonal matrix
B - input vector
X - returned solution

antiSymmetricPadding

public static double[][] antiSymmetricPadding(double[][] c,
                                              int extra)

antiSymmetricPadding

public static double[] antiSymmetricPadding(double[] c,
                                            int n,
                                            int extra)

antiSymmetricPadding

public static float[] antiSymmetricPadding(float[] c,
                                           int n,
                                           int extra)