javaslam.util
Class Flops

java.lang.Object
  |
  +--javaslam.util.Flops

public class Flops
extends Object

A class containing methods for counting floating point operations.


Field Summary
static boolean countFlops
          A flag that determines whether count(long) will increment the flop count.
protected static long flops
          A counter of the number of floating-point operations performed.
 
Constructor Summary
Flops()
           
 
Method Summary
static int add(int n, int m)
          Counts the number of floating point operations used to add two n-by-m matrices.
static int backSubst(int n, int k, int m)
          Counts the number of floating point operations used to solve for X via back substitution in the matrix equation AX = B where A is upper triangular.
static int chol(int n)
          Counts the number of floating point operations used to compute the Cholesky decomposition of an n-by-n symmetric positive definite matrix.
static long count()
          Returns the number of floating point operations performed by code in the tjtf package since the virtual machine was started.
static void count(long f)
          Increments the flop counter by f.
static int det(int n, boolean isSPD)
          Counts the number of floating point operations used to compute the determinant of an n-by-n matrix that is possibly symmetric positive definite.
static int exp()
          Counts the number of floating point operations used to compute the exponential of a number.
static int forwardSubst(int n, int k, int m)
          Counts the number of floating point operations used to solve for X via back substitution in the matrix equation AX = B where A is unit lower triangular.
static int inv(int n, boolean isSPD)
          Counts the number of floating point operations used to invert an n-by-n matrix that is possibly symmetric positive definite.
static int log()
          Counts the number of floating point operations used to compute the logarithm of a number.
static int lu(int n)
          Counts the number of floating point operations used to compute the LU decomposition of an n-by-n square matrix.
static int mult(int n, int k, int m)
          Counts the number of floating point operations used to compute the product of two matrices A and B.
static int rand()
          Counts the number of floating point operations used to compute a random double-precision floating point number between 0.0 and 1.0 using a simple linear-congruential formula xi + 1 = a xi + b (mod c).
static int randn()
          Counts the number of floating point operations used to compute a sample from the standard normal using the Box-Muller method.
static int randnorm(int n, int k)
          Counts the number of floating point operations used to compute n samples from a k-dimensional multivariate Gaussian distribution represented using a covariance matrix.
static void reset()
          A method that resets the flop count.
static int solve(int n, int k, int m, boolean isSPD)
          Counts the number of floating point operations used to solve for X in the matrix equation AX = B where A is possibly symmetric positive definite.
static int sqrt()
          Counts the number of floating point operations used to compute the square root of a number.
static int trace(int n)
          Counts the number of floating point operations used to compute the trace of a square matrix A.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

countFlops

public static boolean countFlops
A flag that determines whether count(long) will increment the flop count.


flops

protected static long flops
A counter of the number of floating-point operations performed.

Constructor Detail

Flops

public Flops()
Method Detail

count

public static long count()
Returns the number of floating point operations performed by code in the tjtf package since the virtual machine was started.


count

public static void count(long f)
Increments the flop counter by f.


reset

public static void reset()
A method that resets the flop count.


solve

public static int solve(int n,
                        int k,
                        int m,
                        boolean isSPD)
Counts the number of floating point operations used to solve for X in the matrix equation AX = B where A is possibly symmetric positive definite. This algorithm comes from the Numerical Recipes algorithm via the Lightspeed Matlab library of Tom Minka.

Parameters:
n - the number of rows in A
k - the number of columns in A (and also the number of rows in B)
m - the number of columns in B
isSPD - true if A is positive definite, enabling the Cholesky decomposition
Returns:
the exact number of floating point operations required to solve for X.

backSubst

public static int backSubst(int n,
                            int k,
                            int m)
Counts the number of floating point operations used to solve for X via back substitution in the matrix equation AX = B where A is upper triangular. This algorithm comes from the Numerical Recipes algorithm via the Lightspeed Matlab library of Tom Minka.

Parameters:
n - the number of rows in A
k - the number of columns in A (and also the number of rows in B)
m - the number of columns in B
Returns:
the exact number of floating point operations required to solve for X via back substitution.

forwardSubst

public static int forwardSubst(int n,
                               int k,
                               int m)
Counts the number of floating point operations used to solve for X via back substitution in the matrix equation AX = B where A is unit lower triangular. This algorithm comes from the Numerical Recipes algorithm via the Lightspeed Matlab library of Tom Minka.

Parameters:
n - the number of rows in A
k - the number of columns in A (and also the number of rows in B)
m - the number of columns in B
Returns:
the exact number of floating point operations required to solve for X via back substitution.

inv

public static int inv(int n,
                      boolean isSPD)
Counts the number of floating point operations used to invert an n-by-n matrix that is possibly symmetric positive definite. This algorithm comes from the Numerical Recipes algorithm via the Lightspeed Matlab library of Tom Minka.

Parameters:
n - the number of rows and columns of the square matrix
isSPD - true if the matrix is positive definite, enabling the Cholesky decomposition
Returns:
the exact number of floating point operations required to invert the matrix

chol

public static int chol(int n)
Counts the number of floating point operations used to compute the Cholesky decomposition of an n-by-n symmetric positive definite matrix. This formula comes from the Numerical Recipes algorithm via the Lightspeed Matlab library of Tom Minka.

Parameters:
n - the number of rows and columns of the square matrix
Returns:
the number of flops required to compute the Cholesky decomposition

lu

public static int lu(int n)
Counts the number of floating point operations used to compute the LU decomposition of an n-by-n square matrix. This formula comes from http://www.maths.uq.edu.au/~gac/math2200/mn_nla2.pdf.

Parameters:
n - the number of rows and columns of the square matrix
Returns:
the number of flops required to compute the Cholesky decomposition

sqrt

public static int sqrt()
Counts the number of floating point operations used to compute the square root of a number. This function returns 15 and is based on source code for sqrt() function at http://www.opencores.org/cvsweb.shtml/or1k/newlib/newlib/libm/mathfp/s_sqrt.c. This formula comes from the Lightspeed Matlab library of Tom Minka.


det

public static int det(int n,
                      boolean isSPD)
Counts the number of floating point operations used to compute the determinant of an n-by-n matrix that is possibly symmetric positive definite.

Parameters:
n - the number of rows and columns of the square matrix
isSPD - true if the matrix is positive definite, enabling the Cholesky decomposition This formula comes from the Lightspeed Matlab library of Tom Minka.

log

public static int log()
Counts the number of floating point operations used to compute the logarithm of a number. This function returns 20; this formula comes from the Lightspeed Matlab library of Tom Minka.


exp

public static int exp()
Counts the number of floating point operations used to compute the exponential of a number. This function returns 20; this formula comes from the Lightspeed Matlab library of Tom Minka.


rand

public static int rand()
Counts the number of floating point operations used to compute a random double-precision floating point number between 0.0 and 1.0 using a simple linear-congruential formula xi + 1 = a xi + b (mod c).


randn

public static int randn()
Counts the number of floating point operations used to compute a sample from the standard normal using the Box-Muller method.


randnorm

public static int randnorm(int n,
                           int k)
Counts the number of floating point operations used to compute n samples from a k-dimensional multivariate Gaussian distribution represented using a covariance matrix.

Parameters:
n - the number of samples
k - the dimension of the Gaussian distribution
Returns:
the number of floating-point operations required to sample n times from a k-dimensional multivariate Gaussian distribution represented using a covariance matrix.

mult

public static int mult(int n,
                       int k,
                       int m)
Counts the number of floating point operations used to compute the product of two matrices A and B. This formula comes from the Lightspeed Matlab library of Tom Minka.

Parameters:
n - the number of rows in A
k - the number of columns in A (and also the number of rows in B)
m - the number of columns in B
Returns:
the number of flops used to compute the product AB

trace

public static int trace(int n)
Counts the number of floating point operations used to compute the trace of a square matrix A.

Parameters:
n - the number of rows (and columns) in A
Returns:
the number of flops used to compute tr(A)

add

public static int add(int n,
                      int m)
Counts the number of floating point operations used to add two n-by-m matrices.

Parameters:
n - the number of rows in each matrix
m - the number of columns in each matrix
Returns:
the number of flops used to compute the sum A + B