edu.jhmi.rad.medic.utilities
Class NumericsPublic

java.lang.Object
  extended by edu.jhmi.rad.medic.utilities.NumericsPublic

public class NumericsPublic
extends java.lang.Object

This class computes various basic numerical functions.

Includes min, max, gaussian random numbers, special functions, mathematical constants. This duplicates some of Java's Math functions where these have limited type support (e.g. double, but not float) or perform multiple casting operations (slow).

Version:
May 17, 2005
Author:
Pierre-Louis Bazin

Field Summary
static float INF
          mathematical constants
static float PI
          mathematical constants
static float ZERO
          mathematical constants
 
Constructor Summary
NumericsPublic()
           
 
Method Summary
static double abs(double a)
           
static float abs(float a)
           
static int abs(int a)
           
static int argmax(double a, double b, double c)
          gives the position of the highest value
static int argmax(float a, float b, float c)
          gives the position of the highest value
static void bestIndex(byte[] id, float[] bestval, float[] val, int num)
          find the indices of the num largest values in val (any sign)
static void bestIndex(byte[] id, float[] bestval, float[] val, int num, byte first)
          find the indices of the num largest values in val (>=0)
static void bestIndex(byte[] id, float[] val, int num)
          find the indices of the num largest values in val (>=0)
static byte bestIndex(float[] val)
          find the index of the largest values in val (>=0)
static byte[] bestIndex(float[] val, int num)
          find the indices of the num largest values in val (>=0)
static void bestIndex(short[] id, float[] bestval, float[] val, int num)
          find the indices of the num largest values in val (any sign)
static byte bin(boolean val)
          boolean to number value
static double bounded(double x, double a, double b)
           
static float bounded(float x, float a, float b)
           
static int bounded(int x, int a, int b)
           
static int ceil(double num)
           
static int ceil(float num)
           
static float determinant3D(float[][] m)
          Close-form 3D matrix determinant
static double[] eigenvalues3D(double[][] m)
          Close-form 3D matrix eigenvalues.
static float[] eigenvalues3D(float[][] m)
          Close-form 3D matrix eigenvalues.
static double[][] eigenvectors3D(double[][] m, double[] values)
          Simple geometric technique to get eigenvectors of 3D matrices.
static float[][] eigenvectors3D(float[][] m, float[] values)
          Simple geometric technique to get eigenvectors of 3D matrices.
static int floor(double num)
           
static int floor(float num)
           
static void invert3Dmatrix(float[][] m)
          Close-form 3D matrix inversion
static float invertMatrix(float[][] m, float[][] inverse, int nColumn)
          This method compute the inverse of a matrix
static void main(java.lang.String[] args)
          for testing purposes
static float mapped(float x, float a, float b)
          returns x in [a,b] linearly mapped to [0,1]
static double max(double a, double b)
           
static float max(float[] val)
           
static float max(float[] val, int first, int last)
           
static float max(float a, float b)
           
static float max(float a, float b, float c)
           
static int max(int a, int b)
           
static int max(int a, int b, int c)
           
static float maxmag(float a, float b)
           
static double min(double a, double b)
           
static float min(float a, float b)
           
static float min(float a, float b, float c)
           
static int min(int a, int b)
           
static long min(long a, long b)
           
static float minmag(float a, float b)
           
static float pow(float a, float b)
           
static double randomGaussian()
          Gaussian random numbers (from the Box-Muller method, as in NRC) mean 0, variance 1
static double randomT3(double sigma)
          Student T 3rd order random numbers mean 0, variance given note: the formula should be the inverse of the probability integral (wrong here!)
static int round(double num)
           
static int round(float num)
          rounding function (faster than regular Java)
static int sign(double a)
           
static int sign(float a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

public static final float ZERO
mathematical constants

See Also:
Constant Field Values

INF

public static final float INF
mathematical constants

See Also:
Constant Field Values

PI

public static final float PI
mathematical constants

See Also:
Constant Field Values
Constructor Detail

NumericsPublic

public NumericsPublic()
Method Detail

randomGaussian

public static final double randomGaussian()
Gaussian random numbers (from the Box-Muller method, as in NRC) mean 0, variance 1


randomT3

public static final double randomT3(double sigma)
Student T 3rd order random numbers mean 0, variance given note: the formula should be the inverse of the probability integral (wrong here!)


determinant3D

public static final float determinant3D(float[][] m)
Close-form 3D matrix determinant


invert3Dmatrix

public static final void invert3Dmatrix(float[][] m)
Close-form 3D matrix inversion


invertMatrix

public static final float invertMatrix(float[][] m,
                                       float[][] inverse,
                                       int nColumn)
This method compute the inverse of a matrix

Parameters:
m - : the given matrix which should be a square array of floats
inverse - : is the result of inversion
nColumn - : number of coulmn of squared aaray
Returns:
: determinent of the matrix

eigenvalues3D

public static final float[] eigenvalues3D(float[][] m)
Close-form 3D matrix eigenvalues.

This may not work well all the time with arbitrary matrices.


eigenvectors3D

public static final float[][] eigenvectors3D(float[][] m,
                                             float[] values)
Simple geometric technique to get eigenvectors of 3D matrices.

This may not work well all the time: sometimes you have a 2 or 3D sub-space with one eigenvalue. We assume here that the highest eigenvalues give the most reliable directions, and lesser eigenvectors are projected on orthogonal subspaces (seems wrong: to check). We also assume ordered, positive eigenvalues.


eigenvalues3D

public static final double[] eigenvalues3D(double[][] m)
Close-form 3D matrix eigenvalues.

This may not work well all the time with arbitrary matrices.


eigenvectors3D

public static final double[][] eigenvectors3D(double[][] m,
                                              double[] values)
Simple geometric technique to get eigenvectors of 3D matrices.

This may not work well all the time: sometimes you have a 2 or 3D sub-space with one eigenvalue. We assume here that the highest eigenvalues give the most reliable directions, and lesser eigenvectors are projected on orthogonal subspaces. We also assume ordered, positive eigenvalues.


round

public static final int round(float num)
rounding function (faster than regular Java)


floor

public static final int floor(float num)

ceil

public static final int ceil(float num)

round

public static final int round(double num)

floor

public static final int floor(double num)

ceil

public static final int ceil(double num)

min

public static final float min(float a,
                              float b)

min

public static final double min(double a,
                               double b)

min

public static final int min(int a,
                            int b)

min

public static final long min(long a,
                             long b)

min

public static final float min(float a,
                              float b,
                              float c)

max

public static final float max(float a,
                              float b)

max

public static final double max(double a,
                               double b)

max

public static final int max(int a,
                            int b)

max

public static final int max(int a,
                            int b,
                            int c)

max

public static final float max(float a,
                              float b,
                              float c)

max

public static final float max(float[] val)

max

public static final float max(float[] val,
                              int first,
                              int last)

bounded

public static final int bounded(int x,
                                int a,
                                int b)

bounded

public static final float bounded(float x,
                                  float a,
                                  float b)

bounded

public static final double bounded(double x,
                                   double a,
                                   double b)

minmag

public static final float minmag(float a,
                                 float b)

maxmag

public static final float maxmag(float a,
                                 float b)

mapped

public static final float mapped(float x,
                                 float a,
                                 float b)
returns x in [a,b] linearly mapped to [0,1]


abs

public static final float abs(float a)

abs

public static final double abs(double a)

abs

public static final int abs(int a)

sign

public static final int sign(float a)

sign

public static final int sign(double a)

pow

public static final float pow(float a,
                              float b)

bestIndex

public static final byte bestIndex(float[] val)
find the index of the largest values in val (>=0)


bestIndex

public static final byte[] bestIndex(float[] val,
                                     int num)
find the indices of the num largest values in val (>=0)


bestIndex

public static final void bestIndex(byte[] id,
                                   float[] val,
                                   int num)
find the indices of the num largest values in val (>=0)


bestIndex

public static final void bestIndex(byte[] id,
                                   float[] bestval,
                                   float[] val,
                                   int num)
find the indices of the num largest values in val (any sign)


bestIndex

public static final void bestIndex(short[] id,
                                   float[] bestval,
                                   float[] val,
                                   int num)
find the indices of the num largest values in val (any sign)


bestIndex

public static final void bestIndex(byte[] id,
                                   float[] bestval,
                                   float[] val,
                                   int num,
                                   byte first)
find the indices of the num largest values in val (>=0)


argmax

public static final int argmax(float a,
                               float b,
                               float c)
gives the position of the highest value


argmax

public static final int argmax(double a,
                               double b,
                               double c)
gives the position of the highest value


bin

public static final byte bin(boolean val)
boolean to number value


main

public static void main(java.lang.String[] args)
for testing purposes